Overview
TheAgentor class is the main entry point for building AI agents. It provides a simple interface to create agents with tools, serve them as APIs, and run them with various configurations.
Constructor
Parameters
The name of the agent. Used in API endpoints and agent identification.
System prompt that defines the agent’s behavior and personality. This guides how the agent responds to user queries.
The LLM model to use. Supports any model from LiteLLM (e.g.,
"gpt-4o", "gemini/gemini-pro", "anthropic/claude-4").
For non-OpenAI models, use the format "provider/model-name" and provide an api_key.List of tools available to the agent. Can be:
FunctionToolobjects created with@function_tool- String names from the tool registry (e.g.,
"gmail","get_weather") MCPServerStreamableHttpinstances for MCP serversBaseToolsubclasses with capabilities
Optional Pydantic model or schema to structure the agent’s output.
Enable debug mode for additional logging and diagnostics.
API key for the LLM provider. Falls back to
OPENAI_API_KEY environment variable if not provided.Advanced model configuration including temperature, top_p, max_tokens, etc. See ModelSettings for details.
List of skill file paths to inject into the agent’s system prompt.
Enable LLM tracing and monitoring via Celesto. Requires
CELESTO_API_KEY environment variable.Methods
run
Run the agent synchronously with a single prompt.input(str): The user’s input prompt
arun
Run the agent asynchronously with support for batch processing and fallback models.input: A single prompt string, list of prompts for batch processing, or list of message dictionarieslimit_concurrency(int): Maximum concurrent tasks for batch prompts (default: 10)max_turns(int): Maximum agent turns before stopping (default: 20)fallback_models(List[str]): Optional fallback models to try on rate limit or API errors
chat
Interactive chat interface with optional streaming support.input(str): User messagestream(bool): Enable streaming responses (default: False)serialize(bool): Serialize output to JSON (default: True)
stream_chat
Stream agent responses in real-time.serve
Serve the agent as an HTTP API with A2A protocol support.host: Server host address (default: “0.0.0.0”)port(int): Server port (default: 8000)log_level: Logging level (default: “info”)access_log(bool): Enable access logging (default: True)
from_md
Create an Agentor instance from a markdown file with YAML frontmatter.md_path: Path to markdown file- Other parameters override markdown frontmatter settings
think
Make the agent “think” through a problem using chain-of-thought reasoning.query(str): The problem or question to analyze
Usage Examples
Basic Agent
Agent with Custom Model
Agent with Tools
Agent with Model Settings
Serving an Agent
Related
- LLM - Lightweight LLM client
- ModelSettings - Configure model parameters
- Tools - Create custom tools
