Agent skill

Ag2 Subagent Delegation

by ag2ai in ag2ai/build-with-ag2

Delegate work from one AG2 beta Agent to another. An agent skill from ag2ai/build-with-ag2.

Apache-2.0Auto-check passedAgent Workflows

Install Ag2 Subagent Delegation

skills CLI
$ npx skills add ag2ai/build-with-ag2 --skill ag2-subagent-delegation -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install ag2ai/build-with-ag2 ag2-subagent-delegation --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/ag2ai/build-with-ag2.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.agents/skills/ag2-subagent-delegation .claude/skills/ag2-subagent-delegation && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
ag2-subagent-delegation
GitHub stars
252
Token cost
~2.3k tokens
SKILL.md length
680 words
Files
2 (incl. assets)
Skills in repo
16
Repo updated
First seen
Licence
Apache-2.0

At a glance

Delegate work from one AG2 beta Agent to another. An agent skill from ag2ai/build-with-ag2.

  • One coordinator should spawn sub-tasks
  • SKILL.md covers When to use, Two patterns, Pattern 1 — auto-injected… and Pattern 2 — Agent.as_tool(), plus 4 more sections
  • Runs Python scripts from its folder
  • Fan out concurrent work

What it does

Ag2 Subagent Delegation is an agent skill from ag2ai/build-with-ag2. Delegate work from one AG2 beta Agent to another. Two patterns — auto-injected runsubtask / runsubtasks(parallel=True) (opt in via tasks=TaskConfig(...)) for self-delegation and parallel fan-out, and Agent.astool() for named delegates between distinct agents. Use when one coordinator should spawn sub-tasks, fan out concurrent work, or hand off to a specialist agent. Covers context flow, recursion safety, and persistentstream for sub-task history.

Its SKILL.md is about 2.3k tokens, which your agent loads only when the skill is triggered. The skill folder holds 2 other files, including assets (for example `assets/research_squad.py`).

It sits in Agent Workflows, covering Task breakdown and Subagents. The repository describes itself as: Sample code and application showcases to get you going with AG2 (formally AutoGen). The licence is Apache-2.0.

When your agent uses it

  • One coordinator should spawn sub-tasks
  • Fan out concurrent work
  • Hand off to a specialist agent

Example prompts

  • “/ag2-subagent-delegation”

Requirements

  • Python 3

What it can do on your machine

Read from SKILL.md and the folder at commit 29eeac3. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Ships script files (Python), which the agent can run.

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Ag2 Subagent Delegation loads about 2.3k tokens when it runs. Until then it costs about 123 tokens; SKILL.md has 680 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~123
When it runs · the whole SKILL.md, loaded when a task matches
~2.3k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from ag2ai/build-with-ag2 at commit 29eeac3, republished under its Apache-2.0 licence (© ag2ai). 680 words, ~2,267 tokens.

Download SKILL.mdSave it as .claude/skills/ag2-subagent-delegation/SKILL.md (or your agent's skills folder). This skill also uses 1 other file; get the full folder from GitHub.
name
ag2-subagent-delegation
description
Delegate work from one AG2 beta `Agent` to another. Two patterns — auto-injected `run_subtask` / `run_subtasks(parallel=True)` (opt in via `tasks=TaskConfig(...)`) for self-delegation and parallel fan-out, and `Agent.as_tool()` for named delegates between distinct agents. Use when one coordinator should spawn sub-tasks, fan out concurrent work, or hand off to a specialist agent. Covers context flow, recursion safety, and `persistent_stream` for sub-task history.
license
Apache-2.0

Subagent delegation

When to use

  • "Coordinator + specialists" — a parent agent should hand parts of a task to a research agent, math agent, etc.
  • "Fan out then collect" — multi-part questions where each part is independent and parallel execution saves wall time.
  • "Self-delegation" — one agent breaks complex work into focused sub-tasks for itself.

Two patterns

PatternReach for it whenAPI
Auto-injected run_subtask / run_subtasksLightweight self-delegation, dynamic fan-out, parallel sub-questionstasks=TaskConfig(...) on the parent
Agent.as_tool()Distinct named delegates the LLM should reason about ("call the researcher", "call the writer")Wrap a child Agent as a tool on the parent

The two compose — a coordinator can have both.

Pattern 1 — auto-injected run_subtasks

Subtask tools are off by default (tasks=False). Opt in with tasks=TaskConfig(...) and the agent gains:

  • run_subtask(task: str) — one isolated sub-task agent.
  • run_subtasks(tasks: list[str], parallel: bool = True) — fan out multiple in one tool call (default concurrent).
python
from autogen.beta import Agent, TaskConfig
from autogen.beta.config import GeminiConfig

config = GeminiConfig(model="gemini-3-flash-preview")

coordinator = Agent(
    "coordinator",
    prompt=(
        "You answer multi-part questions by dispatching run_subtasks "
        "with parallel=True. Use one tool call with every sub-question "
        "packed into the 'tasks' list."
    ),
    config=config,
    tasks=TaskConfig(),  # opt in
)

reply = await coordinator.ask(
    "In one run_subtasks call, answer: "
    "(a) tallest waterfall, (b) Eiffel Tower year, (c) boiling point of nitrogen."
)

TaskConfig controls how the sub-task agents are built:

python
@dataclass
class TaskConfig:
    config: ModelConfig | None = None    # falls back to parent's config
    prompt: str = "You are a task agent..."
    include_tools: Iterable[str] | None = None   # None = inherit all parent tools
    exclude_tools: Iterable[str] = ()
    extra_tools: Iterable[Callable | Tool] = ()

Common shape — cheaper model for sub-tasks, narrow tool surface:

python
TaskConfig(
    config=worker_config,                  # smaller model
    prompt="You are a focused worker; one step only.",
    include_tools=["search", "fetch_url"], # don't expose `summarize` to children
)

Sub-task agents are built with tasks=False — they never gain run_subtask tools themselves. Recursive delegation is structurally impossible; no depth limit needed.

Pattern 2 — Agent.as_tool()

Expose a whole agent as a tool the LLM can name and call:

python
from autogen.beta import Agent
from autogen.beta.config import AnthropicConfig

config = AnthropicConfig(model="claude-sonnet-4-6")

researcher = Agent("researcher", prompt="Provide concise factual findings.", config=config, tools=[search_tool])
writer     = Agent("writer", prompt="Turn research into clear prose.", config=config)

coordinator = Agent(
    "coordinator",
    prompt="First delegate research, then pass findings to the writer.",
    config=config,
    tools=[
        researcher.as_tool(description="Research a topic and return findings."),
        writer.as_tool(description="Write an article. Pass research notes in the context parameter."),
    ],
)

The coordinator's LLM sees task_researcher and task_writer. Each call has two parameters:

  • objective (required) — what the sub-task should do.
  • context (optional) — relevant info the parent wants to share.

as_tool() accepts:

ParameterDescription
descriptionTool description shown to the LLM (required)
nameOverride the default task_{agent.name}
streamStreamFactory for custom sub-task streams (see below)
middlewareToolMiddleware callables (e.g. approval_required)

For more control, use subagent_tool() directly:

python
from autogen.beta.tools.subagents import subagent_tool

coordinator = Agent("coordinator", config=config, tools=[
    subagent_tool(researcher, description="Research a topic."),
])

Self-delegation via as_tool()

If you want a named self-delegate (sub_task instead of generic run_subtask), give an agent its own tool:

python
analyst = Agent(
    "analyst",
    prompt=(
        "You have search and sub_task tools. "
        "Only use sub_task when the task has clearly independent parts."
    ),
    config=config,
    tools=[search_tool],
)

analyst.add_tool(
    analyst.as_tool(
        description="Break work into a focused sub-task for independent analysis.",
        name="sub_task",
    )
)
Recursion safety

Self-delegation via as_tool() can recurse — the child has the same sub_task tool, so without a guard the LLM may chain calls indefinitely.

The simplest safe pattern is to prefer the auto-injected run_subtask / run_subtasks path for self-delegation. Sub-tasks spawned that way are constructed with tasks=False, so they have no run_subtask tools and recursion is structurally impossible.

If you genuinely need recursive as_tool() self-delegation, write a tool middleware that increments a depth counter in context.dependencies and short-circuits past a threshold. The subagents module exports subagent_tool, persistent_stream, and StreamFactory from autogen.beta.tools.subagents — verify the current public surface there before relying on a built-in depth-limiting helper.

Show full SKILL.md (295 more words)Show less

Sub-task streams

By default, each sub-task gets a fresh MemoryStream — its history is isolated and starts empty. Context flow:

WhatBehaviourWhy
DependenciesCopied (top-level shallow)Isolated; treat dependencies as read-only inside subtasks
VariablesCopied; synced back on successConcurrent-safe — sibling subtasks won't race-clobber a shared dict
HistoryFresh streamClean context; relevant info passes via the context tool parameter
ToolsInherited from parent (filtered by TaskConfig)Sub-tasks need real capabilities to do work
persistent_stream()

When a sub-agent benefits from seeing its prior calls (e.g. avoid repeating searches), give it a stream that persists across invocations within the parent context:

python
from autogen.beta.tools.subagents import persistent_stream

researcher.as_tool(
    description="Research a topic",
    stream=persistent_stream(),
)

Stores stream id in context.dependencies keyed by f"ag:{agent.name}:stream" and reuses the parent stream's storage backend.

Custom factory
python
from autogen.beta import Agent, Context
from autogen.beta.streams.redis import RedisStream

def make_redis_stream(agent: Agent, ctx: Context) -> RedisStream:
    return RedisStream(MY_REDIS_URL, prefix=f"ag2:sub:{agent.name}")

researcher.as_tool(description="Research a topic", stream=make_redis_stream)

Going deeper

  • Working starter: assets/research_squad.py (mirrors code_examples/05) — covers both run_subtasks(parallel=True) and Agent.as_tool(), with TaskStarted / TaskCompleted lifecycle events.
  • Full reference: website/docs/beta/task_delegation.mdx.
  • tasks= constructor knob (with KnowledgeConfig, etc.): website/docs/beta/agent_harness.mdx.

Common pitfalls

  • Forgetting to opt in — tasks=False is the default. No TaskConfig, no run_subtask tools.
  • Expecting sub-tasks to recurse with run_subtask — they can't. Sub-tasks themselves have tasks=False. If you need deeper trees, use Agent.as_tool() self-delegation with a manual depth-counter middleware (see "Recursion safety" above).
  • Sharing mutable variables expecting them to merge — concurrent sub-tasks each copy variables; sibling mutations don't propagate. Each sub-task's variable mutations stay local until sync-back on success.
  • Treating dependencies as scoped per sub-task — only the top-level dict is copied. Mutable values inside it are still shared by reference. Treat dependencies as read-only inside sub-tasks.
  • No description= on as_tool() — the LLM doesn't know when to call it. Required parameter.
  • run_subtasks(parallel=False) when work is concurrent — defaults to True for a reason; only set False when later tasks depend on earlier results.
  • Confusing task_{agent.name} collisions — pass name= to override if you want shorter names or distinct delegates of the same agent.

© ag2ai, Apache-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 1 other file (assets) in .agents/skills/ag2-subagent-delegation of ag2ai/build-with-ag2.

  • SKILL.md
  • assets/research_squad.py

Open the folder on GitHubat commit 29eeac3

Compare with similar skills

Ag2 Subagent Delegation next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Ag2 Subagent Delegation compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Ag2 Subagent Delegation this skillag2ai/build-with-ag2252—~2.3kAutomated safety check: PassApache-2.0
OMA Multi-Agent Orchestratorfirst-fluke/oh-my-agent1.3k—~3.1kAutomated safety check: PassMIT
Swarm Parallel Dispatchlangchain-ai/langchain-skills1.3k—~3kAutomated safety check: PassMIT
Cursor Orchestratecursor/plugins11k—~1.1kAutomated safety check: PassNone
Launching Agent Teamslexler/skill-factory239—~1.3kAutomated safety check: PassApache-2.0
Agents Project Coordinatorasgeirtj/system_prompts_leaks69k—~2.9kAutomated safety check: PassCC0-1.0

Similar skills

  • OMA Multi-Agent Orchestrator

    first-fluke/oh-my-agent

    Splits a complex feature into prioritized tasks, spawns specialist CLI subagents in parallel, tracks them through shared memory and verifies each result.

    1.3k GitHub stars~3.1k tokensUpdated today
    Agent WorkflowsAuto-check passed
  • Swarm Parallel Dispatch

    langchain-ai/langchain-skills

    Official

    Fans a list of independent items out to subagents in parallel, merges the results back into a table and supports retrying only the rows that failed.

    1.3k GitHub stars~3k tokensUpdated yesterday
    Agent WorkflowsAuto-check passed
  • Cursor Orchestrate

    cursor/plugins

    Official

    Splits a large goal into a tree of parallel Cursor cloud agents, with planners, workers and verifiers coordinated by a script and reporting through structured handoffs.

    11k GitHub stars~1.1k tokensUpdated today
    Agent WorkflowsAuto-check passed
  • Launching Agent Teams

    lexler/skill-factory

    Plans and launches Claude Code agent teams with distinct roles, right-sized tasks and detailed spawn prompts, and says when subagents or worktrees fit better.

    239 GitHub stars~1.3k tokensUpdated today
    Agent WorkflowsAuto-check passed
  • Agents Project Coordinator

    asgeirtj/system_prompts_leaks

    Runs a goal as a project in which the agent coordinates separate agent threads, judging when to split the work, and interviews you first when nothing can be verified.

    69k GitHub stars~2.9k tokensUpdated today
    Agent WorkflowsAuto-check passed
  • Vspawn

    vlinx-io/VelaTerm

    Explicitly spawn a standalone child session under the current vlx-term session, passing the task in as its first message (mirrors spawntask).

    281 GitHub stars~2.5k tokensUpdated 3 days ago
    Agent WorkflowsAuto-check passed

More from ag2ai/build-with-ag2

All 16 skills in this repo
  • Ag2 Add Custom Tool

    ag2ai/build-with-ag2

    Add a custom Python tool to an AG2 beta Agent using the @tool decorator.

    252 GitHub stars~1.9k tokensUpdated 1 mo ago
    Auto-check passed
  • Ag2 Middleware

    ag2ai/build-with-ag2

    Intercept the AG2 beta agent loop with BaseMiddleware — wrap full turns (onturn), each LLM call (onllmcall), each tool execution (ontoolexecution), or each human-input request (onhumaninput).

    252 GitHub stars~1.9k tokensUpdated 1 mo ago
    Auto-check passed
  • Ag2 Use Builtin Tools

    ag2ai/build-with-ag2

    Wire AG2 beta's shipped tools into an Agent — both provider-native server-side tools (web search, web fetch, code execution, MCP, image generation, memory) and locally-executed common toolkits…

    252 GitHub stars~1.3k tokensUpdated 1 mo ago
    Auto-check passed
  • Ag2 Knowledge And Memory

    ag2ai/build-with-ag2

    Persist agent state across runs, shape what the LLM sees per turn, and cap history to fit a context window.

    252 GitHub stars~2.9k tokensUpdated 1 mo ago
    Auto-check passed
  • Ag2 Observers And Alerts

    ag2ai/build-with-ag2

    Monitor an AG2 beta agent's stream — log events, detect repeated tool calls, track token spend, build trigger-driven observers, route observer alerts to the model, and halt on FATAL conditions.

    252 GitHub stars~2.5k tokensUpdated 1 mo ago
    Auto-check passed
  • Ag2 Quickstart

    ag2ai/build-with-ag2

    Build a minimal AG2 beta Agent end to end — pick a model provider, set a prompt, call agent.ask(), then continue the conversation with reply.ask() (multi-turn).

    252 GitHub stars~1.7k tokensUpdated 1 mo ago
    Auto-check: notes

Categories

Questions about Ag2 Subagent Delegation

What does Ag2 Subagent Delegation do?

Delegate work from one AG2 beta Agent to another. An agent skill from ag2ai/build-with-ag2. Ag2 Subagent Delegation is an agent skill from ag2ai/build-with-ag2. Delegate work from one AG2 beta Agent to another.

When should I use Ag2 Subagent Delegation?

Ag2 Subagent Delegation fits situations like: one coordinator should spawn sub-tasks; fan out concurrent work; hand off to a specialist agent.

How do I install Ag2 Subagent Delegation in Claude Code?

Run `npx skills add ag2ai/build-with-ag2 --skill ag2-subagent-delegation -a claude-code`. Or copy the skill folder (.agents/skills/ag2-subagent-delegation in ag2ai/build-with-ag2) into .claude/skills/ag2-subagent-delegation in your project. Claude Code loads it when a task matches its description.

How do I install Ag2 Subagent Delegation in Codex?

Run `npx skills add ag2ai/build-with-ag2 --skill ag2-subagent-delegation -a codex`. Or copy the skill folder (.agents/skills/ag2-subagent-delegation in ag2ai/build-with-ag2) into .agents/skills/ag2-subagent-delegation in your project. Codex loads it when a task matches its description.

Can I use Ag2 Subagent Delegation in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add ag2ai/build-with-ag2 --skill ag2-subagent-delegation -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/ag2-subagent-delegation, .gemini/skills/ag2-subagent-delegation, .github/skills/ag2-subagent-delegation and .opencode/skills/ag2-subagent-delegation in your project.

What does Ag2 Subagent Delegation need to run?

Going by SKILL.md and its folder, Ag2 Subagent Delegation needs Python for the scripts in its folder. Our summary lists: Python 3.

Does Ag2 Subagent Delegation access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Ag2 Subagent Delegation safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Ag2 Subagent Delegation use?

Ag2 Subagent Delegation is published under the Apache-2.0 licence (declared in SKILL.md). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Ag2 Subagent Delegation use?

About 2.3k tokens (SKILL.md is roughly 9.1k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Ag2 Subagent Delegation?

Skills that share tags, products or a category with Ag2 Subagent Delegation: OMA Multi-Agent Orchestrator (first-fluke/oh-my-agent, 1.3k stars), Swarm Parallel Dispatch (langchain-ai/langchain-skills, 1.3k stars), Cursor Orchestrate (cursor/plugins, 11k stars) and Launching Agent Teams (lexler/skill-factory, 239 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Ag2 Subagent Delegation?

ag2ai (a GitHub organization) maintains it in ag2ai/build-with-ag2, which has 252 GitHub stars. The repository holds 16 skills in this directory. The repository was last updated on September 6, 2026.

Source: ag2ai/build-with-ag2 on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.