← 返回
未分类 中文

Spawn Subagent

Spawn isolated subagents to handle long-running, complex, or blocking tasks without stalling the main session. Use when: a task will take more than 30 second...
创建隔离子代理,处理耗时、复杂或阻塞任务,防止主会话卡顿。适用于任务超过30秒的场景。
netanel-abergel netanel-abergel 来源
未分类 clawhub v1.0.1 1 版本 100000 Key: 无需
★ 0
Stars
📥 354
下载
💾 1
安装
1
版本
#latest

概述

Spawn Subagent Skill

Minimum Model

Any model. Task delegation doesn't require complex reasoning.


When to Spawn vs. Stay in Main Session

Spawn a subagent when:

  • Task takes >30 seconds.
  • Task has many sequential steps (research → draft → send → log).
  • Task could fail and block the main session.
  • Multiple independent tasks can run in parallel.
  • Owner wants results "when ready," not now.

Stay in main session when:

  • Task takes <10 seconds.
  • Task needs back-and-forth with the owner.
  • Task needs the current conversation context.

How to Spawn

Basic Spawn

sessions_spawn(
    task="[Detailed task description here]",
    mode="run",             # "run" = one-shot task
    runtime="subagent",
    runTimeoutSeconds=300   # Kill after 5 min if still running
)

With Custom Model (for expensive reasoning tasks)

sessions_spawn(
    task="[Complex analysis task]",
    mode="run",
    runtime="subagent",
    runTimeoutSeconds=300,
    # Use a capable model only when the task needs it
    model="your-provider/your-capable-model"
    # Examples: "anthropic/claude-opus-4-6", "openai/gpt-4o", "google/gemini-1.5-pro"
)

Writing Good Task Descriptions

A good task description has 4 parts:

  1. What to do — specific actions
  2. Where inputs are — file paths, env vars, API endpoints
  3. What to output — exact format and save location
  4. What "done" looks like — clear completion signal

Good Example

Read all .md files in /tmp/reports/
Summarize each in 2–3 sentences
Save all summaries to /tmp/reports/summary.md — one section per file
Print "DONE: X files summarized" when finished
Do not modify the original files

Bad Example

Summarize the reports

Too vague — subagent won't know where files are or what to do with results.


Common Patterns

Batch Processing

# Spawn one subagent to process all items — not one per item
sessions_spawn(
    task="""
    Process each item in /tmp/items.json:
    1. Read the file
    2. For each item: [describe action]
    3. Save results to /tmp/results/ as one file per item (item_ID.json)
    4. Print "DONE: X items processed"
    """,
    mode="run",
    runtime="subagent",
    runTimeoutSeconds=300
)

Research + Draft

sessions_spawn(
    task="""
    1. Search the web for: [topic]
    2. Summarize the top 5 results in bullet points
    3. Draft a 3-paragraph briefing in plain language
    4. Save the draft to /tmp/briefing.md
    5. Print "DONE" when finished
    """,
    mode="run",
    runtime="subagent",
    runTimeoutSeconds=180
)

Parallel Independent Tasks

# Both spawn at the same time — runs faster than sequential
sessions_spawn(
    task="Fetch latest emails. Save to /tmp/emails.json. Print DONE.",
    mode="run", runtime="subagent", runTimeoutSeconds=60
)
sessions_spawn(
    task="Get today's calendar events. Save to /tmp/calendar.json. Print DONE.",
    mode="run", runtime="subagent", runTimeoutSeconds=60
)
# Wait for both completion events, then read both files

PA Daily Briefing (Non-Blocking)

sessions_spawn(
    task="""
    Generate the daily morning briefing:
    1. Get calendar: GOG_ACCOUNT=owner@company.com gog calendar events primary --from TODAY --to TOMORROW
    2. Get emails: GOG_ACCOUNT=owner@company.com gog gmail search 'is:unread newer_than:1d' --max 5
    3. Format as plain text (use CAPS for section titles, no markdown headers)
    4. Save to /tmp/morning-briefing.txt
    5. Print DONE
    """,
    mode="run",
    runtime="subagent",
    runTimeoutSeconds=120
)
# Main session stays free. Read /tmp/morning-briefing.txt when done, then send it.

Handling Completion

Do not poll. Wait for the push-based completion event.

When the completion event arrives:

  1. Read the output file the subagent created.
  2. Use the results in the main session.
  3. Reply with NO_REPLY if the owner doesn't need a response.

Failure Handling

If a subagent times out or fails:

  1. Log the failure: append to .learnings/ERRORS.md.
  2. Notify owner if the task was time-sensitive.
  3. Retry with a simpler, more explicit task description.
  4. If still failing → run in the main session as a fallback.

Anti-Patterns

❌ Don't✅ Do Instead
------
Poll with sessions_list in a loopWait for push-based completion events
Spawn for a 5-second taskRun quick tasks in main session
Use vague task descriptionsBe explicit about inputs, outputs, file paths
Spawn without a timeoutAlways set runTimeoutSeconds
Ignore subagent failuresCheck for error events and handle them
Spawn a subagent from inside a subagentKeep delegation to one level

Cost Tips

  • Cheaper: Use small models for batch/shell operations — spawn with model="provider/small-model".
  • Larger models only for: Complex reasoning, code generation, analysis.
  • Avoid: Do not spawn many subagents simultaneously — they compete for resources.
  • Batch: One subagent processing 100 items is cheaper than 100 subagents with 1 item each.

版本历史

共 1 个版本

  • v1.0.1 当前
    2026-05-07 06:48 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

ai-agent

self-improving agent

pskoett
记录自身发现以实现自我改进的技能
★ 4,175 📥 946,171
ai-agent

Agent Browser

rez0
用于 AI 代理的浏览器自动化 CLI。当用户需要与网站交互(包括浏览页面、填写表单、点击按钮、截图等)时使用。
★ 874 📥 350,750
knowledge-management

research-synthesizer

netanel-abergel
多源研究综合器。接收问题,进行 3‑5 次并行网页搜索(不同表述),去重后返回带引用的简洁答案。
★ 0 📥 534