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:str
required
The user’s message or instruction to the agent.
List[Message]
Existing conversation history. The instruction is appended as the latest user message.
str
Session identifier for grouping related runs together.
str
Unique identifier for this run. Auto-generated if not provided.
str
User identifier for memory scoping. When set, memory recall and storage are scoped to this user.
List[Image]
Images to include with the user message.
List[Video]
Videos to include with the user message.
List[Audio]
Audio files to include with the user message.
List[File]
Files to include with the user message. When readers are enabled, file content is automatically extracted and injected into the prompt.
Type[BaseModel]
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:
Deploying with serve()
Useagent.serve() to start the full agent runtime — messaging interfaces, HTTP endpoints, webhooks, and cron jobs in a single call:
BaseInterface
Interface instances (Telegram, Discord) to run concurrently.
str
default:"0.0.0.0"
HTTP server bind address.
int
default:"8000"
HTTP server port.
bool
default:"None"
Force HTTP server on/off. Auto-detects from registered webhooks when
None.bool
default:"false"
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.