Supervisor / Worker
createSupervisor() creates a supervisor agent that delegates tasks to a pool of specialized worker agents. The supervisor reasons about what work to delegate, calls workers via a synthetic tool, and synthesizes results.
Creating a supervisor
import { createAgent, createSupervisor, OpenAIProvider } from "@synkro/agents";
const provider = new OpenAIProvider({ apiKey: process.env.OPENAI_API_KEY! });
const weatherAgent = createAgent({ name: "weather-assistant", description: "Looks up weather information for any location", systemPrompt: "You are a weather assistant. Use the provided tools to look up weather.", provider, model: { model: "gpt-4o-mini" }, tools: [getWeatherTool],});
const mathAgent = createAgent({ name: "math-assistant", description: "Evaluates mathematical expressions and solves equations", systemPrompt: "You are a math assistant. Use the provided tools to calculate.", provider, model: { model: "gpt-4o-mini" }, tools: [calculateTool],});
const supervisor = createSupervisor({ name: "research-supervisor", systemPrompt: "Break down requests and delegate to the right specialist.", provider, model: { model: "gpt-4o" }, workers: [weatherAgent, mathAgent], maxRounds: 6,});
const result = await supervisor.run( "What is the weather in Tokyo and what is 42 * 17?");console.log(result.output);SupervisorConfig
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
name | string | Yes | — | Supervisor agent name. |
systemPrompt | string | Yes | — | Base system prompt — enhanced automatically with worker descriptions. |
provider | ModelProvider | Yes | — | LLM provider instance. |
model | ModelOptions | Yes | — | Model configuration. |
workers | Agent[] | Yes | — | Worker agents available for delegation. |
maxRounds | number | No | 5 | Maximum delegation rounds before stopping. |
How it works
- The supervisor is itself an
Agentinstance returned bycreateSupervisor(). - A synthetic
delegate_to_workertool is injected, with worker names exposed as an enum. - The system prompt is enhanced with a list of available workers and their descriptions.
- The supervisor reasons, delegates tasks to workers via the tool, observes results, and repeats until done.
maxRoundsmaps tomaxIterationson the underlying agent — it controls how many reason/delegate cycles are allowed.
Using as a Synkro handler
Since the supervisor is a standard Agent, it supports asHandler() for Synkro integration:
synkro.on("complex-request", supervisor.asHandler());This gives you distributed locking, retries, and dead letter queues for free.