Basic Usage
Signature
Type Safety
The@Agent decorator validates at compile time that:
- The decorated class extends
AgentContext - When
inputSchemais provided, theexecute()parameter matches the schema type - When
outputSchemais provided, theexecute()return type is compatible - Invalid metadata options (e.g., typos in
concurrency) produce specific compile-time errors
Agents can use the default
execute() from AgentContext (which runs the LLM agent loop) without overriding it. The type checker allows this pattern.Configuration Options
Required Properties
Optional Properties
LLM Configuration
Thellm property accepts one of two configuration shapes:
Built-in provider shorthand (AgentLlmBuiltinConfig):
AgentLlmAdapterConfig):
LLM Providers
OpenAI
Anthropic (Claude)
The Warning: Never embed long-lived API keys in client-side bundles shipped to end users.
When using Browser LLM adapters (
process.env examples above are Node.js-specific. Decorator and config arguments
are evaluated synchronously, so async token retrieval must happen before agent
creation. In browser environments, use the function-based agent() API:OpenAIAdapter / AnthropicAdapter), prefer a backend
proxy or short-lived tokens to avoid exposing persistent credentials.OpenAI Responses API
Direct Adapter Instance
Agent Loop
By default, agents run an automatic loop:- Send input to LLM with available tools
- If LLM requests tool call, execute tool and return result
- Repeat until LLM returns final response
- Parse and return output
Custom Execution
Overrideexecute() for custom behavior:
Function-Based Alternative
Context Methods
LLM Completion
Tool Execution
Notifications
Elicitation
Agent Visibility
Agents can invoke other agents:Full Example
Related
AgentContext
Context class details
AgentRegistry
Agent registry API
Agent Errors
Agent-related errors
@Tool
Define tools