Back to CourseLesson 7 of 12

Agent Orchestration

Complex tasks often exceed what a single agent can handle effectively. Agent orchestration lets you coordinate multiple specialized agents, each focused on a specific domain, to solve problems that require diverse expertise.

Why Multi-Agent Systems?

Single agents struggle when tasks require too many tools, different expertise domains, or parallel workflows. Multi-agent systems solve this by:

  • Keeping each agent focused with a small, relevant tool set
  • Allowing different models for different tasks (cheap models for simple tasks, powerful models for complex reasoning)
  • Running independent sub-tasks in parallel
  • Improving reliability through specialization

The Supervisor Pattern

The most common orchestration pattern uses a supervisor agent that delegates work to specialized worker agents. CoFounder provides the createOrchestrator helper:

import { createAgent, createOrchestrator } from '@waymakerai/aicofounder-core';

const researchAgent = createAgent({
  name: 'researcher',
  model: 'gpt-4o',
  systemPrompt: 'You are a research specialist. Find and verify facts.',
  tools: [webSearchTool, fetchPageTool],
});

const analysisAgent = createAgent({
  name: 'analyst',
  model: 'gpt-4o',
  systemPrompt: 'You are a data analyst. Analyze data and produce insights.',
  tools: [calculatorTool, chartTool, databaseTool],
});

const writerAgent = createAgent({
  name: 'writer',
  model: 'claude-sonnet-4-20250514',
  systemPrompt: 'You are a technical writer. Produce clear, well-structured reports.',
  tools: [],
});

const orchestrator = createOrchestrator({
  name: 'report-generator',
  model: 'gpt-4o',
  agents: [researchAgent, analysisAgent, writerAgent],
  strategy: 'supervisor',
  systemPrompt: `You coordinate a team of specialists to produce research reports.
Delegate research tasks to the researcher, analysis to the analyst,
and final writing to the writer.`,
});

const result = await orchestrator.run('Create a market analysis report for the EV industry in 2025.');

Agent Delegation

Under the hood, each sub-agent is exposed to the supervisor as a tool. The supervisor calls the agent by name and passes it a task description. CoFounder handles routing the message, running the sub-agent, and returning its output:

// The orchestrator automatically creates tools like this for each agent:
{
  name: 'delegate_to_researcher',
  description: 'Delegate a research task to the researcher agent.',
  parameters: {
    type: 'object',
    properties: {
      task: { type: 'string', description: 'The research task to perform' },
      context: { type: 'string', description: 'Additional context or constraints' },
    },
    required: ['task'],
  },
  execute: async ({ task, context }) => {
    return await researchAgent.run(task, { context });
  },
}

Parallel Agent Execution

When sub-tasks are independent, run agents in parallel to reduce total execution time:

const orchestrator = createOrchestrator({
  name: 'parallel-orchestrator',
  model: 'gpt-4o',
  agents: [researchAgent, analysisAgent, writerAgent],
  strategy: 'supervisor',
  execution: {
    allowParallel: true,
    maxConcurrentAgents: 3,
  },
});

// The supervisor can now delegate to researcher AND analyst simultaneously
// The writer waits until both produce results

Agent Communication

Agents can share context through a shared memory space. This lets downstream agents access results from upstream agents without the supervisor needing to relay everything:

  • Shared context -- A key-value store that all agents in the orchestration can read and write to.
  • Message passing -- Agents can send structured messages to specific other agents.
  • Result aggregation -- The orchestrator collects all agent outputs and can pass aggregated results to a final agent.

Keep communication structured and minimal. Each agent should receive only the context it needs to do its job, not the full output of every other agent.