orchestrating-multi-agent-systems
Execute orchestrate multi-agent systems with handoffs, routing, and workflows across AI providers. Use when building complex AI systems requiring agent collaboration, task delegation, or workflow coordination. Trigger with phrases like "create multi-agent system", "orchestrate agents", or "coordinate agent workflows".
What this skill does
# Orchestrating Multi-Agent Systems
## Overview
Design and implement multi-agent systems using AI SDK v5 with structured handoffs, intelligent routing, and coordinated workflows across AI providers. This skill covers agent role definition, tool scoping, inter-agent delegation via handoff rules, and workflow orchestration patterns including coordinator-worker and supervisor topologies.
## Prerequisites
- Node.js 18+ and TypeScript 5.0+ runtime
- AI SDK v5 (`npm install ai @ai-sdk/openai @ai-sdk/anthropic @ai-sdk/google`)
- API keys for target providers set in environment variables (`OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, `GOOGLE_GENERATIVE_AI_API_KEY`)
- Zod for input/output schema validation (`npm install zod`)
- Familiarity with agent-based architecture patterns (coordinator, pipeline, broadcast)
## Instructions
1. Initialize a TypeScript project with `tsconfig.json` targeting ES2022 and moduleResolution `bundler`
2. Install AI SDK v5 core and provider packages for each model backend required
3. Define agent roles by creating separate modules per agent, each with a system prompt, model binding, and scoped tool set
4. Implement tool functions using `ai.tool()` with Zod input/output schemas for type-safe execution
5. Configure handoff rules using `ai.handoff()` to delegate tasks between agents with clear trigger conditions and context passing
6. Build routing logic that classifies incoming requests by topic or intent and dispatches to the appropriate specialist agent
7. Wire agents into a workflow using sequential, parallel, or conditional orchestration patterns
8. Add state management to persist context across multi-step workflows using a shared context object or external store
9. Implement circuit breakers and timeout guards to prevent workflow deadlocks
10. Test each agent in isolation, then validate end-to-end handoff chains with representative inputs
See `${CLAUDE_SKILL_DIR}/references/implementation.md` for the detailed implementation guide.
## Output
- TypeScript agent modules with AI SDK v5 provider bindings and system prompts
- Tool definitions with Zod-validated input/output schemas
- Handoff configuration mapping agent-to-agent delegation triggers
- Workflow orchestration files defining sequential, parallel, and conditional execution paths
- Routing classifier that maps user intents to specialist agents
- Integration test suite covering handoff chains and fallback paths
## Error Handling
| Error | Cause | Solution |
|-------|-------|----------|
| Provider configuration invalid | Missing or malformed API key in environment | Verify `process.env.*_API_KEY` values; check provider SDK version compatibility |
| Circular handoff detected | Agent A hands off to B which hands back to A | Implement handoff depth counter; set `maxHandoffDepth` and add a fallback terminal agent |
| Task routed to no agent | Routing classifier returned no match for input | Add a default catch-all route; improve classifier training data or keyword coverage |
| Tool access violation | Agent invoked a tool outside its scoped permission set | Review `tools` array per agent; ensure tool names match registered definitions exactly |
| Workflow timeout | Multi-step workflow exceeded deadline without completion | Set per-step timeouts with `AbortController`; add workflow-level deadline and partial-result handling |
See `${CLAUDE_SKILL_DIR}/references/errors.md` for the full error reference.
## Examples
**Scenario 1: Customer Support Triage** -- A coordinator agent classifies incoming tickets as billing, technical, or general. Billing queries hand off to a specialist agent with access to Stripe tools. Technical queries route to a code-analysis agent with filesystem read tools. Resolution rate target: 85% automated within 3 handoff steps.
**Scenario 2: Research Pipeline** -- A sequential workflow chains a web-search agent, a summarization agent, and a report-writer agent. Each agent produces structured JSON output consumed by the next. The pipeline processes 50 research queries per batch with a p95 latency under 30 seconds per query.
**Scenario 3: Code Review Multi-Agent** -- A supervisor agent distributes pull request diffs to specialized reviewers (security, performance, style). Each reviewer returns findings with severity scores. The supervisor aggregates results into a unified review with prioritized action items.
See `${CLAUDE_SKILL_DIR}/references/examples.md` for additional examples.
## Resources
- [AI SDK v5 Documentation](https://sdk.vercel.ai/docs) -- agent creation, tool definitions, handoffs
- [Zod Schema Library](https://zod.dev) -- input/output validation for tools and flows
- Provider integration guides: OpenAI, Anthropic, Google Gemini
- Coordinator-worker and supervisor orchestration pattern references
- OpenTelemetry tracing for multi-agent observability
Related in AI Agents
skill-development
IncludedComprehensive meta-skill for creating, managing, validating, auditing, and distributing Claude Code skills and slash commands (unified in v2.1.3+). Provides skill templates, creation workflows, validation patterns, audit checklists, naming conventions, YAML frontmatter guidance, progressive disclosure examples, and best practices lookup. Use when creating new skills, validating existing skills, auditing skill quality, understanding skill architecture, needing skill templates, learning about YAML frontmatter requirements, progressive disclosure patterns, tool restrictions (allowed-tools), skill composition, skill naming conventions, troubleshooting skill activation issues, creating custom slash commands, configuring command frontmatter, using command arguments ($ARGUMENTS, $1, $2), bash execution in commands, file references in commands, command namespacing, plugin commands, MCP slash commands, Skill tool configuration, or deciding between skills vs slash commands. Delegates to docs-management skill for official documentation.
reprompter
IncludedTransform messy prompts into well-structured, effective prompts — single or multi-agent. Use when: "reprompt", "reprompt this", "clean up this prompt", "structure my prompt", rough text needing XML tags and best practices, "reprompter teams", "repromptception", "run with quality", "smart run", "smart agents", multi-agent tasks, audits, parallel work, anything going to agent teams. Don't use when: simple Q&A, pure chat, immediate execution-only tasks. See "Don't Use When" section for details. Outputs: Structured XML/Markdown prompt, quality score (before/after), optional team brief + per-agent sub-prompts, agent team output files. Success criteria: Single mode quality score ≥ 7/10; Repromptception per-agent prompt quality score 8+/10; all required sections present, actionable and specific.
adaptive-compaction
IncludedAdaptive add-on policy and recovery layer that decides WHEN to compact, prune, snapshot, or fork -- replacing fixed-percent auto-compaction across Claude Code, Codex, and MCP-capable hosts. Trigger on auto-compact timing or damage: "when should I compact", "is it safe to compact now or start a fresh session", "auto-compact fires too early/mid-task", "switching to an unrelated task but the window still has space", "context rot", "answers get worse the longer the session runs", "the agent forgot the plan or my decisions after it summarized", "add a layer on top that manages context without changing the agent", raising autoCompactWindow to give the policy room, or installing/tuning a cross-tool compaction policy or PreCompact hook -- even when "compaction" is never said but the problem is context-window pressure or post-summarization memory loss. Do NOT use to summarize a conversation, build RAG, write a summarization prompt (decides WHEN not HOW), or answer max-context-length trivia.
agent-skill-creator
IncludedCreate cross-platform agent skills from workflow descriptions. Activates when users ask to create an agent, automate a repetitive workflow, create a custom skill, or need advanced agent creation. Triggers on phrases like create agent for, automate workflow, create skill for, every day I have to, daily I need to, turn process into agent, need to automate, create a cross-platform skill, validate this skill, export this skill, migrate this skill. Supports single skills, multi-agent suites, transcript processing, template-based creation, interactive configuration, cross-platform export, and spec validation.
llm-wiki
IncludedUse when building or maintaining a persistent personal knowledge base (second brain) in Obsidian where an LLM incrementally ingests sources, updates entity/concept pages, maintains cross-references, and keeps a synthesis current. Triggers include "second brain", "Obsidian wiki", "personal knowledge management", "ingest this paper/article/book", "build a research wiki", "compound knowledge", "Memex", or whenever the user wants knowledge to accumulate across sessions instead of being re-derived by RAG on every query.
skill-master
IncludedAgent Skills authoring, evaluation, and optimization. Create, edit, validate, benchmark, and improve skills following the agentskills.io specification. Use when designing SKILL.md files, structuring skill folders (references, scripts, assets), ingesting external documentation into skills, running trigger evals, benchmarking skill quality, optimizing descriptions, or performing blind A/B comparisons. Keywords: agentskills.io, SKILL.md, skill authoring, eval, benchmark, trigger optimization.