+# OpenAI Agent Orchestration
+
+Design and implement multi-agent systems that coordinate specialized AI agents to solve complex tasks through handoffs, tool routing, and shared state.
+
+## When to use
+
+- Building a system where one LLM call is insufficient (e.g. research → plan → execute → review)
+- Splitting work across specialized agents (code agent, search agent, reviewer agent)
+- Implementing human-in-the-loop workflows with approval gates
+- Creating pipelines where upstream agent output feeds downstream agent input
+- Need deterministic routing between agents based on task classification
+
+## When NOT to use
+
+- A single system prompt with tools can handle the entire workflow
+- The task is a simple one-shot completion (summarize, translate, classify)
+- You only need function calling without inter-agent communication
+- Latency constraints prohibit multi-turn agent loops (< 2s budget)
+- The "agents" are really just prompt variants — use a single agent with conditional instructions instead
+
+## Core concepts
+
+### Agent types
+
+| Type | Role | Example |
+|------|------|---------|
+| Router | Classifies and dispatches to specialists | Triage agent for support tickets |
+| Specialist | Handles a narrow domain with focused tools | SQL agent, code-review agent |
+| Orchestrator | Manages multi-step pipelines and state | Project planner that sequences sub-agents |
+| Guardrail | Validates outputs before they reach the user | Safety classifier, PII redactor |
+
+### Handoff protocol
+
+Handoffs transfer control from one agent to another. The handoff carries:
+- **target agent** — which specialist to invoke
+- **context** — accumulated conversation state
+- **instructions** — what the target should focus on
+- **metadata** — routing reason, priority, constraints
+
+```typescript
+// OpenAI Agents SDK handoff definition
+import { Agent, handoff } from "@openai/agents";
+
+const researchAgent = new Agent({
+ name: "research_agent",
+ instructions: "You find and summarize relevant information.",
+ tools: [webSearch, docRetrieval],
+});
+
+const codeAgent = new Agent({
+ name: "code_agent",
+ instructions: "You write and review code based on research findings.",
+ tools: [fileWrite, linter, testRunner],
+});
+
+const triageAgent = new Agent({
+ name: "triage_agent",
+ instructions: \`Classify the user request:
+- If it needs research → hand off to research_agent
+- If it needs code → hand off to code_agent
+- If unclear → ask a clarifying question\`,
+ handoffs: [handoff(researchAgent), handoff(codeAgent)],
+});
+```
+
+### State management patterns
+
+```
+┌─────────────┐ context ┌─────────────────┐
+│ Router │ ──────────────> │ Specialist A │
+│ Agent │ │ (research) │
+└──────┬───── ┘ └────────┬─────────┘
+ │ │ result
+ │ ┌─────────────────────────────┘
+ ▼ ▼
+┌─────────────┐ context ┌─────────────────┐
+│ Orchestrator │ ──────────────> │ Specialist B │
+│ (merge) │ │ (code) │
+└──────┬──────┘ └────────┬─────────┘
+ │ │ result