Decorators Reference
Agent Forge uses TypeScript decorators to provide a clean, declarative way to configure agents, tools, and framework features. This section provides comprehensive documentation for all available decorators.
Categories
Core Decorators
Essential decorators for basic Agent Forge functionality:
- @agent - Configure agent properties and behavior
- @llmProvider - Set LLM provider and configuration
- @forge - Create AgentForge instances with automatic setup
Tool Decorators
Decorators for integrating tools with agents:
A2A Decorators
Agent-to-Agent protocol decorators for distributed systems:
- @a2aClient - Create remote agent clients
- @a2aServer - Expose agents as A2A servers
RAG Decorators
Retrieval-Augmented Generation integration:
- @RAGChromaDb - Add document retrieval capabilities
Utility Decorators
Performance and development utilities:
- @Visualizer - Generate team run timelines
- @RateLimiter - Apply rate limiting to LLM calls
Plugin Decorators
Plugin system integration:
- @plugin - Register plugins with decorated classes
Usage Patterns
Basic Agent Setup
@llmProvider("openai", { apiKey: process.env.OPENAI_API_KEY })
@agent({
name: "MyAgent",
role: "Assistant",
description: "A helpful assistant",
objective: "Help users with their tasks",
model: "gpt-4",
temperature: 0.7
})
class MyAgent extends Agent {}
Team with Tools and Visualization
@tool(WebSearchTool)
@Visualizer()
@RateLimiter({ rateLimitPerSecond: 2 })
@llmProvider("openai", { apiKey: process.env.OPENAI_API_KEY })
@forge()
class MyTeam {
static forge: AgentForge;
static async run() {
// Team implementation
}
}
Distributed Agent Network
// Server
@a2aServer({ port: 3001 })
@llmProvider("openai", { apiKey: process.env.OPENAI_API_KEY })
@agent({ name: "ServerAgent", ... })
class ServerAgent extends Agent {}
// Client
@a2aClient({ serverUrl: "http://localhost:3001/a2a" })
class RemoteAgent extends Agent {}
TypeScript Configuration
Agent Forge decorators require proper TypeScript configuration:
{
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"target": "ES2020",
"strict": true
}
}
Decorator Order
When using multiple decorators, order matters:
- @plugin - Register plugins first
- @Visualizer - Enable visualization features
- @RateLimiter - Apply rate limiting
- @tool/@MCP - Add tools
- @RAGChromaDb - Add RAG capabilities
- @a2aServer/@a2aClient - A2A protocol setup
- @llmProvider - Set LLM provider (required for most decorators)
- @agent - Configure agent (for Agent classes)
- @forge - Create AgentForge instance (last)
Error Handling
Common decorator-related errors and solutions:
- "LLM provider must be set" - Add
@llmProvider
before other decorators - "Can only be applied to classes extending Agent" - Ensure your class extends the Agent base class
- "Decorator order" - Follow the recommended decorator order above
- "experimentalDecorators not enabled" - Update your TypeScript configuration
Best Practices
- Consistent Ordering - Always follow the same decorator order across your project
- Environment Variables - Use environment variables for API keys and configuration
- Type Safety - Leverage TypeScript's type checking with proper configurations
- Error Boundaries - Implement proper error handling around decorated classes
- Testing - Test decorated classes with proper mock implementations