Basic Agent
Define an agent with the@agent decorator and call serve() to start a server.
POST /v1/agents/hello/invoke.
The @agent Decorator
Agent name. Defaults to the function name.
Agent description. Defaults to the first paragraph of the function’s docstring.
One of:
prompt, chat, task, thread, workflow. When set, the agent uses predefined input/output schemas for that type.Tags for filtering and organization.
Additional metadata as key-value pairs.
Agent Types
Every agent has a type that determines its input/output contract. Choose the type that matches your use case.Prompt Agent (default)
Single prompt in, string out. Best for one-shot text generation tasks.Chat Agent
Multi-turn conversations with message history.Task Agent
Structured input and output for data processing tasks.Thread Agent
Full message history management — returns the entire conversation thread.Workflow Agent
Multi-step workflows with pause/resume support and human-in-the-loop actions.Context Parameter
Add an optionalcontext parameter to any agent to receive execution context such as caller identity and metadata.
Streaming
Use async generators to stream responses. Yield strings to emittext_delta events.
StreamEvent objects:
When an agent function is an async generator (uses
yield), the runtime automatically treats it as a streaming agent. Clients must pass stream=True to receive the events.Schema from Type Hints
When not using a predefined type, input and output schemas are automatically derived from the function signature.| Python Type | JSON Schema |
|---|---|
str | string |
int | integer |
float | number |
bool | boolean |
list | array |
dict | object |
Pydantic models for nested input
Use Pydantic models for nested object parameters. The runtime extracts a full JSON Schema from the model so callers see the structure, but it does not auto-validate at request time — the handler receives a plaindict. Call model_validate inside the handler when you want a typed instance.
Multiple Agents
Serve any number of agents from a single process. Each agent gets its ownPOST /agents/{name}/invoke endpoint.
serve() Function
Theserve() function starts a FastAPI server that exposes your agents and tools.
List of agents to serve.
List of tools to serve via MCP protocol.
Port number. Defaults to the
PORT environment variable or 8080.Host to bind. Defaults to the
HOST environment variable or "0.0.0.0".At least one agent or tool must be provided. Calling
serve() with no agents and no tools will raise an error.Next steps
Creating Tools
Define MCP tools alongside your agents.
Deploying
Ship your
serve() to production.Configuration & Secrets
Pass API keys and config to your handlers.
Frameworks
Wrap OpenAI, Anthropic, LangChain, or Google AI agents.