delegate_task gives an agent a single tool to spawn a specialist sub-agent for one task and return its output.
Quick Start
1
Agent picks the tool
delegate_task, spins up a sub-agent whose role is derived from agent_type, and returns the result.2
Direct call (headless / CI)
Which Delegation Primitive?
Three delegation entry points overlap — pick the simplest one that fits.How It Works
delegate_task runs the sub-agent, waits for it (bounded by timeout), and returns a JSON string.
agent_type maps to the sub-agent’s identity:
role=agent_type(unlessagent_type == "general", in which caserole="assistant")name=f"{agent_type}_agent"goal=f"Complete delegated {agent_type} tasks accurately."verbose=False
create_subagent_tool directly — see Subagent Tool.
Signature
Return Shapes
The tool returns a JSON string in one of four shapes.Approval Gate
delegate_task is decorated with @require_approval(risk_level="medium") because spawning a sub-agent is a medium-risk action.
- Interactive: users get a prompt to approve or deny the call.
- Headless / CI: set
PRAISONAI_AUTO_APPROVE=true(or configure per-tool auto-approval) or the call is blocked before the sub-agent is spawned.
Timeout Enforcement
Thetimeout parameter is now enforced (it was previously discarded).
timeout > 0(default300): the sub-agent runs on a single-workerThreadPoolExecutor; if it does not return in time, a structured timeout JSON is returned.timeout <= 0: bound disabled — the call blocks for as long as the sub-agent takes. Use this only when you have another way to cap runtime (e.g. an outer scheduler).
Bot / Registry Usage
delegate_task is not auto-injected into the bot default toolset. Opt in explicitly:
Common Patterns
Ad-hoc research delegation — a coordinator agent hasdelegate_task in its tool list; when it needs research it calls the tool and inlines the result.
PRAISONAI_AUTO_APPROVE=true, call delegate_task(...) directly for each work item, parse the JSON return.
priority="high" to record intent (echoed back in the response) even though it does not currently affect scheduling.
Best Practices
Prefer delegate_task for one-line delegation
Prefer delegate_task for one-line delegation
Use
delegate_task when you want a single-line tool an agent can pick up automatically. For anything else — background jobs, a custom model, or a named agent — reach for create_subagent_tool.Always pass a realistic timeout
Always pass a realistic timeout
The default is 300 s, but a scoped task usually completes in under 60 s. Set
timeout to bound runtime and get a structured timeout JSON instead of a hang.Set PRAISONAI_AUTO_APPROVE in CI
Set PRAISONAI_AUTO_APPROVE in CI
In headless runs, set
PRAISONAI_AUTO_APPROVE=true explicitly rather than removing the approval decorator — the gate stays in place for interactive use.Treat priority as an observability tag
Treat priority as an observability tag
priority is echoed back in the success response only. There is no scheduler behind it — don’t rely on it to reorder work.Related
Subagent Tool
Full-featured factory with model / permission mode / background.
Subagent Delegation
Programmatic async delegation with concurrency control.
Named Agent Delegation
Delegate to your own
.praisonai/agents/*.md by name.Bot Default Tools
Where
delegate_task sits in the opt-in registry.
