← Back to Tutorials

6. Advanced Orchestration

Multi-Agent Workflows

Complex applications often require multiple specialized agents working together. The MAF orchestrator manages handoffs, context sharing, and sequencing.

import { Orchestrator, Agent } from "@microsoft/agents";

const triageAgent = new Agent({ name: "Triage", instructions: "Route to the right specialist." });
const billingAgent = new Agent({ name: "Billing", instructions: "Handle billing inquiries." });
const supportAgent = new Agent({ name: "Support", instructions: "Provide technical support." });

const orchestrator = new Orchestrator({
  agents: [triageAgent, billingAgent, supportAgent],
  defaultAgent: triageAgent,
});

// Agent can hand off
await orchestrator.handoff(triageAgent, billingAgent, { context: { userId: "123" } });

Orchestration Patterns

PatternDescriptionUse Case
RouterSingle entry agent delegates to specialistsCustomer support
PipelineAgents process sequentiallyDocument processing pipeline
DebateMultiple agents discuss, then synthesizeDecision support
Round RobinAlternate between agentsMulti-perspective analysis

Context Passing

When handing off between agents, context (memory, conversation history, state) should be explicitly passed.

await orchestrator.handoff(fromAgent, toAgent, {
  context: {
    conversationId: convId,
    userProfile: await memory.get("user_profile"),
    sessionState: { currentTask: "troubleshooting" },
  }
});

Orchestration Lab

  1. Create three agents: Greeter, InfoCollector, and Farewell
  2. Configure a router orchestrator
  3. Greeter hands off to InfoCollector after introduction
  4. InfoCollector hands off to Farewell after gathering info
  5. Test the full flow end-to-end
✏️ Exercise: Build a multi-agent pipeline for customer support: a Triage agent that identifies the issue type, then routes to Billing, Technical Support, or Account Management. Each specialist must pass conversation context and return to the Triage agent after resolution.