cyberine
UsageRun recipes

Worker-internal subagents — delegate_subtask (T313)

Implementer-class loop workers (loop--build) automatically get a delegatesubtask tool that lets the worker spawn a scoped subagent — a focused nested LoopAgentAdapter with its own system prompt, a...

Implementer-class loop workers (loop-*-build) automatically get a delegate_subtask tool that lets the worker spawn a scoped subagent — a focused nested LoopAgentAdapter with its own system prompt, a caller-restricted tool set, and an isolated context window.

Use cases:

  • A worker that must write code AND investigate a codebase section can delegate the investigation to a read-only subagent, keeping its own context clean for writing.
  • A worker can delegate a test run to a subagent that only has run_bash, returning a bounded result without tool-call noise in the parent.

Recursion cap — nesting is bounded by CYBERINE_SUBAGENT_NESTING_CAP (default 2). A call that would exceed the cap is refused and returns an error string to the parent. Set to 0 to disable delegation entirely.

Usage/cost — the subagent's LLM token usage rolls up into the parent run's Usage object, so cost accounting stays accurate end-to-end.

How the model calls it:

{
  "name": "delegate_subtask",
  "arguments": {
    "task": "Scan src/auth/ for all exported function signatures. Return a list.",
    "system_prompt": "You are a codebase investigator. Read files, list directories, search with grep. Return a structured summary. Be concise.",
    "tools": ["read_file", "list_dir", "grep_files"],
    "max_tool_rounds": 8,
    "max_tokens": 4096
  }
}

Parameters:

FieldRequiredDefaultDescription
taskyes—The sub-task text. Self-contained — the subagent has no parent context.
system_promptno(none)Persona / constraints for the subagent. Prepended to the task.
toolsno[] (text-only)Names from the parent's tool set the subagent may use. Unknown names error immediately.
max_tool_roundsno6Tool-calling budget for the subagent (max 20).
max_tokensno4096Max completion tokens per API call inside the subagent's loop.

Env vars:

VarDefaultPurpose
CYBERINE_SUBAGENT_NESTING_CAP2Maximum nesting depth. 0 disables delegation.

Extend recipe — to enable subagents on a custom adapter, pass enableSubagents: true to LoopAgentAdapterOptions. The delegate tool is auto-injected and closes over the adapter's connection details (baseURL / apiKey / model) so the subagent reaches the same endpoint:

new LoopAgentAdapter({
  id: 'my-worker',
  provider: 'deepseek:deepseek-v4-pro',
  model: 'deepseek-v4-pro',
  baseURL: 'https://api.deepseek.com',
  apiKey: process.env.DEEPSEEK_API_KEY!,
  tools: myTools,
  enableSubagents: true,   // inject delegate_subtask
})