Skip to main content

ManagerAgent Class

The ManagerAgent class handles task coordination and worker delegation.

Constructor

Creates a new manager agent instance. Parameters:
  • config: Manager configuration object

Properties

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

Methods

executeTask(task, workers)

Execute a task by coordinating with worker agents. Parameters:
  • task: Task object with title, description, and priority
  • workers: Map of worker name to WorkerAgent instance
Returns: Promise<TaskResult> - Task execution result

ManagerConfig Interface

Configuration object for manager agents.

Properties

  • name: Human-readable name for the manager
  • description: Optional description of the manager’s role
  • provider: LLM provider configuration
  • systemPrompt: System prompt defining the manager’s behavior
  • tools: Array of tool definitions (typically worker agents)

Task Execution Flow

The manager follows this execution pattern:
  1. Receive Task: Manager gets a task from the user
  2. Analyze Requirements: Use LLM to understand task requirements
  3. Select Worker: Determine which worker agent(s) to call
  4. Generate Tool Call: Create function call to worker agent
  5. Execute Worker: Call the selected worker agent
  6. Process Result: Receive and process worker response
  7. Synthesize Output: Generate final response for user

Tool Integration

Managers integrate workers as tools:

Error Handling

Manager agents include built-in error handling:
  • Provider Errors: Automatic retry with backoff
  • Worker Failures: Graceful degradation with error messages
  • Invalid Parameters: Validation through Zod schemas
  • Network Issues: Timeout and retry logic

Usage Examples

Basic Manager Setup

Task Execution

Advanced Configuration

Best Practices

System Prompt Design

Tool Definition

Error Handling