Any model. Task delegation doesn't require complex reasoning.
Spawn a subagent when:
Stay in main session when:
sessions_spawn(
task="[Detailed task description here]",
mode="run", # "run" = one-shot task
runtime="subagent",
runTimeoutSeconds=300 # Kill after 5 min if still running
)
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"
)
A good task description has 4 parts:
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
Summarize the reports
Too vague — subagent won't know where files are or what to do with results.
# 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
)
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
)
# 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
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.
Do not poll. Wait for the push-based completion event.
When the completion event arrives:
NO_REPLY if the owner doesn't need a response.If a subagent times out or fails:
.learnings/ERRORS.md.| ❌ Don't | ✅ Do Instead |
|---|---|
| --- | --- |
| Poll with sessions_list in a loop | Wait for push-based completion events |
| Spawn for a 5-second task | Run quick tasks in main session |
| Use vague task descriptions | Be explicit about inputs, outputs, file paths |
| Spawn without a timeout | Always set runTimeoutSeconds |
| Ignore subagent failures | Check for error events and handle them |
| Spawn a subagent from inside a subagent | Keep delegation to one level |
model="provider/small-model".共 1 个版本