Skip to main content
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

The coordinator picks 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 (unless agent_type == "general", in which case role="assistant")
  • name = f"{agent_type}_agent"
  • goal = f"Complete delegated {agent_type} tasks accurately."
  • verbose=False
This is intentionally lightweight — no extra config knobs and no separate registry of agent profiles. For richer control (custom LLM, permission mode, background execution, named-agent resolution), reach for 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.
In CI, set PRAISONAI_AUTO_APPROVE=true explicitly rather than removing the approval decorator.
See Approval Protocol for how the gate works.

Timeout Enforcement

The timeout parameter is now enforced (it was previously discarded).
  • timeout > 0 (default 300): the sub-agent runs on a single-worker ThreadPoolExecutor; 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:
The tool is also available under the plain function and workspace-scoped forms:

Common Patterns

Ad-hoc research delegation — a coordinator agent has delegate_task in its tool list; when it needs research it calls the tool and inlines the result.
Headless batch job — set PRAISONAI_AUTO_APPROVE=true, call delegate_task(...) directly for each work item, parse the JSON return.
Priority-tagged workqueue — pass priority="high" to record intent (echoed back in the response) even though it does not currently affect scheduling.

Best Practices

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.
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.
In headless runs, set PRAISONAI_AUTO_APPROVE=true explicitly rather than removing the approval decorator — the gate stays in place for interactive use.
priority is echoed back in the success response only. There is no scheduler behind it — don’t rely on it to reorder work.

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.