Overview
TheAgentor class is the main entry point for building AI agents. It wires a model, some tools, and the loop that drives them, then lets you run the agent, stream it, resume it, or serve it as an API.
Constructor
Parameters
str
required
The name of the agent. Used in API endpoints, A2A agent cards, and traces.
str
default:"None"
System prompt that defines the agent’s behavior. Sent as the first message of every run.
str | Model
default:"gpt-5-nano"
The model to use. A bare name such as
"gpt-4o-mini" goes to OpenAI. A provider/model string such as "gemini/gemini-2.5-flash" is routed through LiteLLM. With base_url set, the string is passed to that provider untouched. See Model providers.List[Callable | Tool | str | BaseTool | MCPServer]
default:"None"
What the agent can call. Any mix of:
type[BaseModel]
default:"None"
A Pydantic model describing the shape you want back.
result.final_output becomes an instance of it. See Structured output.bool
default:"False"
Accepted for backwards compatibility. It currently has no effect — use Python’s
logging to see engine activity.str
default:"None"
API key for the provider. Falls back to the
OPENAI_API_KEY environment variable.ModelSettings
default:"None"
Generation parameters: temperature,
max_tokens, top_p, and more. See ModelSettings.bool
default:"False"
Turn on Celesto tracing for this agent. Requires
CELESTO_API_KEY, and raises if it is missing. Tracing is off by default; setting CELESTO_API_KEY alone does not enable it. See Tracing.int
default:"20"
How many model calls a run may make before giving up. A run that hits the limit ends with
status="max_turns" instead of raising.int
default:"2"
How many times any one tool may raise before Agentor stops offering it to the model. Applies per tool, per run — so a run with two tools has a budget of
max_tool_failures for each. Set higher for tools that are legitimately flaky, or lower to fail fast.Store
default:"None"
Where to save the run’s events, so an interrupted run can be resumed. Use
FileStore or MemoryStore from agentor.engine.store. See Durable runs.str
default:"None"
An OpenAI-compatible endpoint to talk to instead of OpenAI — OpenRouter, Groq, Together, vLLM, Ollama, and others. See Model providers.
CelestoTracer
default:"None"
A tracer built with
setup_celesto_tracing. Passing one turns tracing on for the agent — you do not also need enable_tracing=True. See Tracing.str
default:"None"
Optional group id attached to every trace this agent exports. Traces sharing an id are grouped together in the Celesto dashboard, so use it to correlate the runs that make up one user session, one job, or one request. See Tracing.
Dict[str, Any]
default:"None"
Optional dictionary of key-value pairs attached to every trace this agent exports. Useful for tagging environment, tenant, or experiment so the dashboard can filter by it.
Literal["native"]
default:"None"
Vestigial.
"native" is accepted and does nothing; any other value raises. There is one engine and it is the default.Methods
run
Run the agent synchronously.input(str): the prompttracing(bool | None): override tracing for this call.Nonekeeps the agent’s configuration,Falsesends nothing for this run,Truetraces it even when the agent has tracing off (requiresCELESTO_API_KEY). See Tracing.
RunResult.
run() cannot be called from inside a running event loop. Use await agent.arun(...) there.arun
Run the agent asynchronously, with batching and model fallbacks.input: one prompt, a list of prompts to run concurrently, or a list of message dicts to continue a conversationlimit_concurrency(int): maximum concurrent runs wheninputis a list of prompts (default: 10)max_turns(int): turn budget for this call. Defaults to the agent’smax_turnsfallback_models(List[str]): models to try if the primary one is rate limited or errors. Configured temperature and token limits carry acrosstracing(bool | None): override tracing for this call.Nonekeeps the agent’s configuration,Falsesends nothing,Truetraces it even when the agent has tracing off. Wheninputis a batch, the flag applies to every prompt
resume
Continue a run that was saved by a store.run_id(str): the id fromresult.run_id
RunResult covering the whole run, including the part that ran before the interruption.
ValueError if the agent has no store, and KeyError if the store has no run with that id.
fork
Copy a persisted run to a new id and continue it there — even a run that already finished, whichresume() refuses to re-execute. See Durable runs.
run_id(str): the run to branch frominput(str | list[dict] | None): a prompt or message list to continue the fork with right away.Nonejust copies the run under a new id — an unfinished parent is completed, a finished one comes back as a snapshot with no model callfork_id(str): choose the new run’s id yourself. Defaults to a generated onemax_turns(int): turn budget for this call, same asrun(). Applies to the fork’s continuation onlytracing(bool | None): override tracing for this call, same semantics asrun(). Applies to the fork’s continuation only
RunResult for the new run — result.run_id is never the parent’s.
ValueError if the agent has no store, if fork_id is already in use, or if input is an empty list. Raises KeyError if the store has no run with that run_id.
The fork keeps the parent’s entire trace — every generation with its reasoning, when the model returned any, every tool call and result — and then lives its own life. Nothing appended to the fork touches the parent, and vice versa.
chat
Run the agent, optionally returning a stream.input(str): user messagestream(bool): return an async iterator instead of aRunResultserialize(bool): when streaming, yield JSON strings (default) orAgentOutputobjectstracing(bool | None): override tracing for this call, same semantics asrun
RunResult, or an async iterator when stream=True.
stream_chat
Stream the agent’s progress as it works.input(str): user messageserialize(bool): yield JSON strings (default) orAgentOutputobjectstracing(bool | None): override tracing for this call, same semantics asrun
serve
Serve the agent as an HTTP API with A2A protocol support.from_md
Create an agent from a markdown file with YAML frontmatter.weather_agent.md
Tool names in the frontmatter must exist in the registry. Unknown names are skipped with a warning, so an agent can end up with fewer tools than the file lists.
think
Run the agent through a chain-of-thought prompt.RunResult
Every run returns aRunResult:
str | BaseModel | None
The answer. A parsed model instance when
output_type is set, None if the run did not finish.'completed' | 'max_turns' | 'failed'
How the run ended.
str | None
Why it did not complete.
None on success.str | None
Set when the agent has a store. Pass it to
resume() or fork().Usage
input_tokens, output_tokens, and total_tokens for the run.list[dict]
The conversation as the model saw it. Feed it back into
arun() to continue.list[Event]
Every step of the run, in order.
list[Event]
Just the tool calls, with the arguments the model chose.
str(result) returns final_output, so print(result) prints the answer.
Usage Examples
Basic agent
Agent with a different provider
Agent with tools
Agent with model settings
Serving an agent
Related
- Model providers — reach any OpenAI-compatible endpoint
- Structured output — return typed objects
- Durable runs — save and resume runs
- LLM — lightweight LLM client
- ModelSettings — configure generation parameters
- Tools — create custom tools
