๐ค Multi-Agent Orchestration
๐ค Who it's for: Developers / integrators
โฑ๏ธ Read time: ~8 minutes
๐ก In one line: Multiple AIs collaborate like a team โ more reliable and faster than a single AI.
Multi-agent orchestration is one of YingClaw's core features: automatically decompose complex tasks into subtasks, executed in parallel by multiple sub-agents, dramatically improving efficiency and throughput.
Core Conceptโ
Each sub-agent has an isolated context and toolset โ they don't interfere with one another, and the main agent only consumes the aggregated result.
Mandatory Four-Phase Workflowโ
Every complex task in YingClaw goes through four phases:
| Phase | Tool | Output |
|---|---|---|
| 1๏ธโฃ Requirement Clarification | Conversation | Clear task description and constraints |
| 2๏ธโฃ Project Assessment | assess_workload | File count, size, complexity analysis |
| 3๏ธโฃ Plan Confirmation | todo | Step-by-step execution plan with unique IDs |
| 4๏ธโฃ Parallel Execution | delegate | Multiple sub-agents executing subtasks in parallel |
Sub-Agent Typesโ
| Type | Role | Use Case |
|---|---|---|
assistant | General assistant | Code review, document generation, data analysis |
sales_manager | CRM management | Customer relationship management, sales process |
sales_lead_only | Lead specialist | Lead discovery and follow-up |
Core Toolsโ
delegate โ Dispatch Executionโ
Delegate subtasks to one or more sub-agents for parallel execution.
// Parallel delegation to multiple sub-agents
delegate({
prompt: "Review the authentication module under src/auth/",
agents: [
{ role: "Security Reviewer", task: "Check for security vulnerabilities" },
{ role: "Performance Analyst", task: "Analyze performance bottlenecks" },
{ role: "Documentation Checker", task: "Verify documentation completeness" }
]
})
todo โ Task Trackingโ
Automatically manage task state transitions.
// Create a task plan
todo({
todos: [
{ id: "step-1", content: "Scan project structure", status: "pending" },
{ id: "step-2", content: "Analyze dependencies", status: "pending" },
{ id: "step-3", content: "Generate optimization suggestions", status: "pending" }
]
})
Complete Exampleโ
This example shows the full delegate + todo workflow:
// Scenario: Comprehensive code review of a project
// Phase 2: Assess the project
assess_workload({ path: "src/" })
// โ { files: 45, total_size_kb: 320, complexity: "medium" }
// Phase 3: Create a plan
todo({
merge: false,
todos: [
{ id: "s1", content: "Security review: Auth & authorization", status: "pending" },
{ id: "s2", content: "Performance: DB queries & caching", status: "pending" },
{ id: "s3", content: "Code style: Naming & structure", status: "pending" },
{ id: "s4", content: "Test coverage: Unit test completeness", status: "pending" }
]
})
// Phase 4: Parallel execution
delegate({
prompt: "Comprehensive code review of src/",
agents: [
{ role: "Security Expert", task: "Review auth, authorization, input validation" },
{ role: "Performance Engineer", task: "Analyze DB queries, N+1 issues, cache strategy" },
{ role: "Code Reviewer", task: "Check naming, structure, comment conventions" },
{ role: "Test Engineer", task: "Check test coverage, edge cases" }
]
})
// Todo statuses update automatically during execution:
// s1: pending โ in_progress โ completed
// s2: pending โ in_progress โ completed
// s3: pending โ in_progress โ completed
// s4: pending โ in_progress โ completed
Key Parametersโ
| Parameter | Type | Description |
|---|---|---|
prompt | string | Main task description |
agents | array | List of sub-agents, each with role and task |
role | string | Custom sub-agent role |
max_iterations | number | Max tool invocation iterations per sub-agent |
max_depth | number | Max depth for recursive agent delegation |
Best Practicesโ
| Practice | Description |
|---|---|
| ๐ฏ Small, focused subtasks | Each sub-agent handles one clear, small task |
| ๐ Parallelize independent steps | Execute independent subtasks simultaneously for maximum efficiency |
| ๐ Update status promptly | Mark subtasks complete immediately for a clear global view |
| ๐ Set iteration limits | Use max_iterations to prevent infinite loops |
| ๐ฐ Control costs | Keep parallel agents to 5 or fewer, balancing efficiency and API cost |
Next Stepsโ
Multi-agent orchestration breaks complex tasks into manageable pieces. Dive deeper into ๐ Workflow Engine for task lifecycle and error handling.