Skip to main content
Multi-agent systems enable specialized agents to work together on complex tasks. Each agent focuses on a specific domain and coordinates through orchestration patterns.

Multi-Agent System Design Patterns

There are many ways to design multi‑agent systems, but we commonly see two broadly applicable patterns:
  • Manager (agents as tools): A central manager/orchestrator invokes specialized sub‑agents as tools and retains control of the conversation.
  • Handoffs: Peer agents hand off control to a specialized agent that takes over the conversation. This is decentralized.
This guide focuses on the Manager pattern (agents as tools), which is the most common and straightforward approach.

Installation

npm install @llamaindex/workflow @llamaindex/openai llamaindex zod

Manager Pattern (Agents as Tools)

In the Manager pattern, a central orchestrator invokes specialized agents as tools. The orchestrator retains control throughout the conversation and decides when to call each specialized agent.

Creating Specialized Agents

Each specialized agent focuses on a specific task:
import { agent } from '@llamaindex/workflow';
import { OpenAI } from '@llamaindex/openai';
import { createMemory } from 'llamaindex';

const llm = new OpenAI({
  model: process.env.OPENAI_MODEL || 'gpt-4o-mini',
  apiKey: process.env.OPENAI_API_KEY,
  baseURL: process.env.OPENAI_BASE_URL
});

const translatorAgent = agent({
  llm,
  name: 'TranslatorAgent',
  description: 'Translate fetched content to target language while preserving structure',
  systemPrompt: `You are TranslatorAgent. Translate the provided content. 
Preserve headings, lists, tables, code blocks, quotes, and links. 
If already in target language, return unchanged. Output markdown only.`
});

const summarizerAgent = agent({
  llm,
  name: 'SummarizerAgent',
  description: 'Extract entities and facts; produce structured content and mind-map',
  systemPrompt: 'You are SummarizerAgent. From the translated article, extract key entities and facts with citations, build a topical outline.',
  memory: createMemory({ tokenLimit: 100 * 1024 })
});

Creating the Orchestrator

The orchestrator coordinates the workflow by delegating to specialized agents. It wraps specialized agents as tools:
import { tool } from 'llamaindex';
import { z } from 'zod';

const orchestrator = agent({
  llm,
  name: 'Orchestrator',
  description: 'Coordinate: crawl -> translate -> summarize -> evaluate',
  systemPrompt: `You are the orchestrator. Understand user intent and use the right tools. 
You will be given a URL. You should read the content, generate a detailed report. 
The report should be in the same language as the user query with clear structure.`,
  tools: [
    tool({
      name: 'translate',
      description: 'Translate content while preserving structure',
      parameters: z.object({
        content: z.string(),
        targetLanguage: z.string()
      }),
      execute: async ({ content, targetLanguage }) => {
        const result = await translatorAgent.run(
          `Translate the following content to ${targetLanguage}. Preserve all formatting:\n\n${content}`
        );
        return result.data.result;
      }
    }),
    tool({
      name: 'summarize',
      description: 'Extract entities and facts, produce structured content and mind-map',
      parameters: z.object({
        content: z.string()
      }),
      execute: async ({ content }) => {
        const result = await summarizerAgent.run(
          `Extract key entities and facts from:\n\n${content}`
        );
        return result.data.result;
      }
    })
  ]
});

Best Practices

  1. Clear Boundaries: Each agent should have a specific, focused responsibility
  2. Efficient Communication: Minimize overhead between agents using appropriate patterns
  3. Structured State: Use typed state classes when agents need to share data
TODO: Framework-specific best practices coming soon.

Next Steps