Task Delegation
Learn how to effectively delegate tasks between agents for complex workflows.
Overview
Task delegation allows your primary agent to route specific tasks to specialized sub-agents. This enables complex multi-agent workflows where each agent handles what it does best.
Delegation Architecture
┌─────────────────────────────────────────────────────────┐
│ Primary Agent │
│ (Customer Support Lead) │
├─────────────────────────────────────────────────────────┤
│ Analyzes query → Determines specialist needed │
└────────────────────────┬────────────────────────────────┘
│
┌──────────────┼──────────────┐
▼ ▼ ▼
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Billing │ │ Technical │ │ Sales │
│ Agent │ │ Agent │ │ Agent │
└─────────────┘ └─────────────┘ └─────────────┘
│ │ │
└──────────────┼──────────────┘
▼
Response to User
Delegation Methods
1. Automatic Routing
Let the primary agent decide which sub-agent to use:
json{ "delegation": { "mode": "automatic", "sub_agents": [ { "id": "billing_agent", "triggers": ["billing", "payment", "invoice", "refund"] }, { "id": "technical_agent", "triggers": ["bug", "error", "technical", "api", "integration"] }, { "id": "sales_agent", "triggers": ["pricing", "demo", "upgrade", "enterprise"] } ], "fallback": "handle_directly" } }
2. Explicit Delegation
Call specific sub-agents from system prompt:
markdownYou are a support coordinator. When users have questions: 1. For billing issues, delegate to the Billing Specialist: Use: @billing_agent with the user's billing question 2. For technical problems, delegate to Technical Support: Use: @technical_agent with error details 3. For sales inquiries, delegate to Sales: Use: @sales_agent with the user's interest Always explain to the user that you're connecting them with a specialist.
3. Conditional Delegation
Delegate based on conditions:
json{ "delegation": { "rules": [ { "condition": "user.plan === 'enterprise'", "delegate_to": "enterprise_support_agent", "priority": "high" }, { "condition": "message.sentiment < -0.5", "delegate_to": "escalation_agent", "include_context": true }, { "condition": "message.language !== 'en'", "delegate_to": "multilingual_agent" } ] } }
Delegation Configuration
Sub-Agent Definition
json{ "sub_agents": [ { "id": "research_agent", "name": "Research Specialist", "description": "Handles deep research and analysis tasks", "model": "gpt-4", "capabilities": ["web_search", "document_analysis"], "delegation_config": { "timeout_seconds": 120, "max_iterations": 5, "return_format": "structured" } } ] }
Delegation Parameters
| Parameter | Type | Description |
|---|---|---|
timeout_seconds | number | Max time for sub-agent task |
max_iterations | number | Max back-and-forth exchanges |
include_context | boolean | Pass conversation history |
return_format | string | "text", "json", "structured" |
wait_for_response | boolean | Sync or async delegation |
Context Passing
Full Context
Pass entire conversation to sub-agent:
json{ "delegation": { "context_mode": "full", "include": ["messages", "user_info", "session_data"] } }
Selective Context
Pass only relevant information:
json{ "delegation": { "context_mode": "selective", "include": { "last_n_messages": 5, "user_fields": ["id", "name", "plan"], "custom_context": "{{extracted_issue}}" } } }
Context Template
Format context for the sub-agent:
json{ "delegation": { "context_template": "User {{user.name}} ({{user.plan}} plan) needs help with: {{task_description}}\n\nRelevant history:\n{{recent_messages}}" } }
Response Handling
Direct Response
Sub-agent response goes directly to user:
json{ "response_handling": { "mode": "direct", "attribution": "Response from our {{sub_agent.name}}" } }
Processed Response
Primary agent processes sub-agent response:
json{ "response_handling": { "mode": "processed", "instructions": "Review the specialist's response and present it in a friendly way to the user. Add relevant follow-up suggestions." } }
Merged Response
Combine responses from multiple sub-agents:
json{ "response_handling": { "mode": "merged", "format": "## {{agent.name}}\n{{agent.response}}\n\n", "summary": true } }
Parallel Delegation
Execute multiple sub-agents simultaneously:
json{ "delegation": { "mode": "parallel", "tasks": [ { "agent": "market_research_agent", "task": "Research competitor pricing for {{product}}" }, { "agent": "internal_data_agent", "task": "Get our historical pricing for {{product}}" }, { "agent": "analysis_agent", "task": "Prepare pricing recommendation template" } ], "aggregation": { "strategy": "merge", "final_agent": "synthesis_agent" } } }
Delegation Chains
Sequential Chain
Research Agent → Analysis Agent → Summary Agent → User
json{ "chain": { "type": "sequential", "steps": [ { "agent": "research_agent", "output_key": "research_data" }, { "agent": "analysis_agent", "input": "{{research_data}}", "output_key": "analysis" }, { "agent": "summary_agent", "input": "{{analysis}}", "output_key": "final_response" } ] } }
Conditional Chain
json{ "chain": { "type": "conditional", "steps": [ { "agent": "classifier_agent", "output_key": "category" }, { "condition": "{{category}} === 'technical'", "agent": "technical_agent" }, { "condition": "{{category}} === 'billing'", "agent": "billing_agent" }, { "condition": "default", "agent": "general_agent" } ] } }
Error Handling
Delegation Failures
json{ "error_handling": { "on_timeout": { "action": "fallback", "fallback_agent": "general_support_agent", "message": "Our specialist is taking longer than expected. Let me help you directly." }, "on_error": { "action": "retry", "max_retries": 2, "fallback_message": "I apologize, but I'm having trouble connecting with our specialist. Let me try to help you myself." } } }
Validation
Validate sub-agent responses:
json{ "validation": { "required_fields": ["answer", "confidence"], "min_confidence": 0.7, "on_low_confidence": { "action": "escalate", "escalate_to": "human_agent" } } }
Monitoring Delegation
Metrics
Track delegation performance:
| Metric | Description |
|---|---|
| Delegation rate | % of queries delegated |
| Success rate | % of successful delegations |
| Avg delegation time | Time to complete delegation |
| Fallback rate | % of fallbacks triggered |
Logging
json{ "logging": { "log_delegations": true, "log_context": false, "log_responses": true, "alert_on_high_fallback": true } }
Best Practices
1. Clear Agent Specialization
Each sub-agent should have a distinct purpose:
json{ "sub_agents": [ { "name": "Billing Agent", "specialization": "Handles ONLY billing, payments, invoices", "not_for": ["technical issues", "product questions"] } ] }
2. Graceful Handoffs
Make transitions smooth for users:
markdownSystem prompt for primary agent: When delegating to a specialist: 1. Acknowledge the user's request 2. Explain you're connecting them with a specialist 3. Briefly describe what the specialist will help with 4. Ensure continuity - don't make them repeat information
3. Appropriate Context
Pass enough context, but not too much:
json{ "context_passing": { "always_include": ["user_name", "user_plan", "issue_summary"], "include_if_relevant": ["order_history", "previous_tickets"], "never_include": ["internal_notes", "sensitive_data"] } }
4. Fallback Planning
Always have fallbacks:
json{ "fallback_chain": [ "specialized_agent", "general_agent", "human_escalation" ] }
5. Monitor and Optimize
Review delegation patterns regularly:
- Which agents are most used?
- Where do delegations fail?
- Are users satisfied with handoffs?
API Reference
Trigger Delegation
bashcurl -X POST "https://api.arcanflows.com/api/v1/agents/{agent_id}/delegate" \ -H "X-API-Key: your_api_key" \ -H "Content-Type: application/json" \ -d '{ "sub_agent_id": "technical_agent", "task": "Help user with API integration error", "context": { "conversation_id": "conv_123", "user_id": "user_456", "error_code": "AUTH_FAILED" } }'
Get Delegation Status
bashcurl -X GET "https://api.arcanflows.com/api/v1/agents/{agent_id}/delegations/{delegation_id}" \ -H "X-API-Key: your_api_key"
Cancel Delegation
bashcurl -X DELETE "https://api.arcanflows.com/api/v1/agents/{agent_id}/delegations/{delegation_id}" \ -H "X-API-Key: your_api_key"