Skip to main content

WorkerAgent Class

The WorkerAgent class represents specialized AI agents that perform specific types of work.

Constructor

Creates a new worker agent instance. Parameters:
  • config: Worker configuration object

Properties

  • config: The worker configuration object
  • provider: Internal LLM provider instance (private)

Methods

execute(params)

Execute a task with the given parameters. Parameters:
  • params: Task parameters as key-value pairs
Returns: Promise<TaskResult> - Task execution result

getToolSchema()

Get the tool schema for this worker (used by managers). Returns: Record<string, any> - JSON schema object

WorkerConfig Interface

Configuration object for worker agents.

Properties

  • name: Unique identifier for the worker
  • description: Optional description of the worker’s specialty
  • provider: LLM provider configuration
  • systemPrompt: System prompt defining the worker’s behavior and expertise
  • tools: Array of tool definitions available to this worker

Task Execution

Workers execute tasks through their execute() method:

Tool Integration

Workers can use tools to extend their capabilities:

Tool Schema Generation

The getToolSchema() method generates a schema for manager integration:

Error Handling

Worker agents include built-in error handling:
  • Provider Errors: Automatic retry with backoff
  • Tool Failures: Graceful error reporting
  • Invalid Parameters: Zod schema validation
  • Network Issues: Timeout and retry logic

Usage Examples

Basic Worker Setup

Task Execution

Specialized Workers

Advanced Configuration

Best Practices

System Prompt Design

Tool Definition

Error Handling

Performance Optimization