Skip to main content

Basic Usage

Signature

Type Safety

The @Agent decorator validates at compile time that:
  • The decorated class extends AgentContext
  • When inputSchema is provided, the execute() parameter matches the schema type
  • When outputSchema is provided, the execute() 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

The llm property accepts one of two configuration shapes: Built-in provider shorthand (AgentLlmBuiltinConfig):
Direct adapter instance (AgentLlmAdapterConfig):

LLM Providers

OpenAI

Anthropic (Claude)

The 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:
Warning: Never embed long-lived API keys in client-side bundles shipped to end users. When using Browser LLM adapters (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:
  1. Send input to LLM with available tools
  2. If LLM requests tool call, execute tool and return result
  3. Repeat until LLM returns final response
  4. Parse and return output

Custom Execution

Override execute() for custom behavior:

Function-Based Alternative

Context Methods

LLM Completion

Tool Execution

Notifications

Elicitation

Agent Visibility

Agents can invoke other agents:

Full Example

AgentContext

Context class details

AgentRegistry

Agent registry API

Agent Errors

Agent-related errors

@Tool

Define tools