QueryMT Agent - Delegation System
The delegation system enables multi-agent workflows where a planner agent can delegate tasks to specialized delegate agents. This allows for division of labor and specialized expertise.
Overview
Delegation allows agents to: - Delegate tasks to specialized agents - Coordinate work across multiple agents - Verify results from delegates - Run in parallel multiple delegations - Route to remote agents via mesh networking
Architecture
flowchart TD
P["Planner Agent<br/>(Analyzes task, decides which delegate to use)"]
O["Delegation Orchestrator<br/>(Manages delegation lifecycle)"]
D1["Delegate 1<br/>(Coder)"]
D2["Delegate 2<br/>(Tester)"]
P -->|"Delegation Request"| O
O --> D1 & D2
Configuration
Enabling Delegation
Delegation is enabled in the quorum configuration:
Defining Delegates
Planner Configuration
Delegation Lifecycle
1. Delegation Request
The planner decides to delegate and creates a delegation request.
If hooks are enabled, pre_delegation runs before the delegation is recorded. It can block the delegation entirely or rewrite fields such as target_agent_id, objective, context, constraints, and expected_output.
The planner-side tool result is updated when a delegation is blocked, so the model sees Delegation blocked by hook: ... instead of a misleading queued message.
The delegation request shape is:
2. Session Creation
The orchestrator creates a new session for the delegate:
3. Context Injection
The planner's context is injected into the delegate session.
If hooks are enabled, delegation_start runs just before the delegate begins work. This hook is observe-only: it cannot block execution, but its additional_context is appended to the child session planning context.
The planner's context is injected into the delegate session:
4. Task Execution
The delegate receives the task and begins execution:
5. Result Collection
The delegate's work is collected.
If hooks are enabled, post_delegation runs after the delegate summary is extracted. This hook is observe-only and can append context to the summary that gets injected back into the planner session.
The delegate's work is collected:
6. Verification (Optional)
If verification is enabled, the result is verified:
7. Result Injection
The result is injected back into the planner session.
If a delegation fails, delegation_failure runs before the failure message is injected back into the planner. This hook is also observe-only and can append remediation context to the planner-visible failure message.
The result is injected back into the planner session:
Delegation Hooks Summary
| Hook | Matcher | Behavior |
|---|---|---|
pre_delegation |
target agent regex | Block or rewrite the delegation before it is recorded |
delegation_start |
target agent regex | Observe start and append planning context for the child session |
post_delegation |
target agent regex | Observe completion and append context to the injected summary |
delegation_failure |
target agent regex | Observe failure and append context to the injected failure message |
See the Hooks Guide for JSON payloads, schemas, and output examples.
Delegation Status
| Status | Description |
|---|---|
Pending |
Delegation requested, waiting to start |
Running |
Delegate is working on the task |
Complete |
Delegate finished successfully |
Failed |
Delegate encountered an error |
Cancelled |
Delegation was cancelled |
Verification
Verification Types
Example Verification
Delegation Parameters
Wait Policy
Controls how the planner waits for delegate results:
- any: Continue when first delegate completes
- all: Wait for all delegates to complete
Parallel Delegations
Maximum concurrent delegations.
Grace Period
Time to wait for graceful cancellation before force abort.
Remote Delegation
Delegates can run on remote mesh nodes:
When peer is specified:
- LLM calls are routed to the remote node
- Tool execution happens locally
- Enables "remote model, local session" pattern
Delegation Events
Agents emit events during delegation:
Programmatic Delegation
Creating a Delegation
Subscribing to Delegation Events
Error Handling
Common Errors
| Error | Cause | Resolution |
|---|---|---|
AgentNotFound |
Delegate not registered | Register delegate with correct ID |
SessionCreationFailed |
Cannot create delegate session | Check delegate configuration |
VerificationFailed |
Verification check failed | Fix the issue or adjust verification |
Timeout |
Delegation took too long | Increase timeout or optimize task |
Cancelled |
Delegation was cancelled | Retry or handle cancellation |
Error Classification
The system classifies delegation errors:
Best Practices
When to Delegate
Good candidates for delegation: - Well-defined, isolated tasks - Tasks requiring specific expertise - Parallelizable work - Tasks with clear success criteria
Poor candidates for delegation: - Highly ambiguous requirements - Tasks requiring deep context - Interactive, multi-turn tasks - Tasks needing human judgment
Writing Good Delegation Requests
- Clear objective: Be specific about what needs to be done
- Relevant context: Include necessary background information
- Explicit constraints: List any requirements or restrictions
- Expected output: Describe what success looks like
- Verification criteria: If applicable, specify how to verify
Planning for Delegation
- Break down tasks: Split complex tasks into smaller delegations
- Order dependencies: Plan delegation sequence
- Set expectations: Clearly communicate goals to delegates
- Review results: Always review delegate output before integrating
Examples
Simple Delegation
User: "Add a new API endpoint" Planner: Delegates to coder with task details Coder: Implements the endpoint Planner: Reviews and integrates the changes
Parallel Delegation
User: "Implement feature X" Planner: Delegates frontend to frontend-coder, backend to backend-coder Both delegates work in parallel Planner: Integrates both results
Verification Example
Troubleshooting
Delegation Not Starting
- Check delegate is registered:
agent.agent_registry().list_agents() - Verify delegate configuration is valid
- Check for middleware errors
- Review logs for delegation events
Delegate Not Completing
- Check delegate has necessary tools
- Verify delegate can access required files
- Check for infinite loops in delegate logic
- Review timeout settings
Verification Failing
- Check verification command is correct
- Verify delegate made expected changes
- Adjust verification criteria if too strict
- Review delegate output for issues
Related Documentation
- Configuration Guide - Delegation configuration
- Mesh Networking - Remote delegation
- API Reference - Delegation types
- Agent Modes - Mode-aware delegation