Skip to main content

๐Ÿค– 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:

PhaseToolOutput
1๏ธโƒฃ Requirement ClarificationConversationClear task description and constraints
2๏ธโƒฃ Project Assessmentassess_workloadFile count, size, complexity analysis
3๏ธโƒฃ Plan ConfirmationtodoStep-by-step execution plan with unique IDs
4๏ธโƒฃ Parallel ExecutiondelegateMultiple sub-agents executing subtasks in parallel

Sub-Agent Typesโ€‹

TypeRoleUse Case
assistantGeneral assistantCode review, document generation, data analysis
sales_managerCRM managementCustomer relationship management, sales process
sales_lead_onlyLead specialistLead 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โ€‹

ParameterTypeDescription
promptstringMain task description
agentsarrayList of sub-agents, each with role and task
rolestringCustom sub-agent role
max_iterationsnumberMax tool invocation iterations per sub-agent
max_depthnumberMax depth for recursive agent delegation

Best Practicesโ€‹

PracticeDescription
๐ŸŽฏ Small, focused subtasksEach sub-agent handles one clear, small task
๐Ÿ”€ Parallelize independent stepsExecute independent subtasks simultaneously for maximum efficiency
๐Ÿ“Š Update status promptlyMark subtasks complete immediately for a clear global view
๐Ÿ›‘ Set iteration limitsUse max_iterations to prevent infinite loops
๐Ÿ’ฐ Control costsKeep 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.