Synchronous
The simplest way to run an agent. Blocks until the full response is ready.Asynchronous
Usearun() in async contexts such as web servers or async pipelines:
Streaming (Sync)
Stream events in real time. Each event represents a step in the agent’s execution:Streaming (Async)
Run Parameters
All four methods accept the same parameters:The user’s message or instruction to the agent.
Existing conversation history. The instruction is appended as the latest user message.
Session identifier for grouping related runs together.
Unique identifier for this run. Auto-generated if not provided.
User identifier for memory scoping. When set, memory recall and storage are scoped to this user.
Images to include with the user message.
Videos to include with the user message.
Audio files to include with the user message.
Files to include with the user message. When readers are enabled, file content is automatically extracted and injected into the prompt.
Pydantic model for structured output from the final response.
The RunOutput Object
Every non-streaming run returns aRunOutput with the full results:
Stream Event Types
Streaming runs yieldRunOutputEvent objects. Key event types:
| Event | Description |
|---|---|
RunStarted | Agent execution has begun |
RunContent | A chunk of the agent’s text response |
RunContentCompleted | Full content generation is done |
ToolCallStarted | A tool call is about to execute |
ToolCallCompleted | A tool call finished successfully |
ToolCallError | A tool call failed |
ReasoningStep | A reasoning step from a thinking model |
KnowledgeRetrievalStarted | Knowledge retrieval began |
KnowledgeRetrievalCompleted | Knowledge retrieval finished |
MemoryRecallStarted | Memory recall began |
MemoryRecallCompleted | Memory recall finished |
MemoryUpdateStarted | Memory storage began |
MemoryUpdateCompleted | Memory storage finished |
FileReadStarted | File reading began |
FileReadCompleted | File reading finished |
RunCompleted | The entire run is finished (includes final RunOutput) |
RunError | The run failed with an error |
Deploying with serve()
Useagent.serve() to start the full agent runtime — messaging interfaces, HTTP endpoints, webhooks, and cron jobs in a single call:
Interface instances (Telegram, Discord, Signal) to run concurrently.
HTTP server bind address.
HTTP server port.
Force HTTP server on/off. Auto-detects from registered webhooks when
None.Enable hot-reload dev mode.
agent.serve() is a blocking sync call. Use agent.aserve() for async contexts.
When webhooks or cron triggers are registered via @agent.on(...), they run alongside interfaces automatically. Set agent.auth to protect HTTP endpoints with API key or JWT authentication.
See Agent Runtime for full details on webhooks, cron, event triggers, lifecycle hooks, and the HTTP server.