sub-agent-spawning
Skill0 starsChanged 6 months agoMITView on GitHub
Shows how an orchestrator agent spawns multiple sub-agents and aggregates their results. Use when building hierarchical multi-agent systems where a coordinator delegates specialised tasks to sub-agents, either sequentially or in parallel via asyncio.gather.
In this repository65 other files it gives its agents.
- AGENTS.mdAGENTS.md
- skills/building-agents/agents.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- llms-full.txtllms.txt
- llms.txtllms.txt
- adding-guardrailsSkill
- agent-health-timeoutSkill
- agent-permission-scopingSkill
- agent-session-isolationSkill
- agent-step-loggingSkill
- agent-supervisor-routerSkill
- agent-telemetrySkill
- async-agent-backgroundSkill
- building-agentsSkill
- building-teamsSkill
- building-toolsSkill
- calendar-scheduling-toolSkill
- callback-tracing-handlerSkill
- chain-of-thought-promptingSkill
- chat-model-configurationSkill
- code-execution-sandboxSkill
- common-agent-patternsSkill
- context-window-managementSkill
- conversation-memorySkill
- conversation-state-dbSkill
- database-query-toolSkill
- document-loadersSkill
- document-rerankingSkill
- email-notification-toolSkill
- embedding-model-ingestionSkill
- fallback-model-chainSkill
- few-shot-injectionSkill
- filesystem-toolSkill
- human-in-the-loopSkill
- hybrid-searchSkill
- inspecting-streamsSkill
- integrating-with-laurenSkill
- json-schema-enforcementSkill
- llm-provider-connectionSkill
- llm-rate-limitingSkill
- long-term-vector-memorySkill
- managing-memorySkill
- migrating-to-lauren-aiSkill
- multi-agent-delegationSkill
- multi-tool-orchestrationSkill
- multi-turn-tool-stateSkill
- output-guardrailsSkill
- plan-and-execute-agentSkill
- prompt-injection-defenseSkill
- prompt-versioningSkill
- rag-pipelineSkill
- react-agent-loopSkill
- response-validation-retrySkill
- rest-api-toolSkill
- securing-agentsSkill
- semantic-cacheSkill
- streaming-response-handlerSkill
- structured-output-parsingSkill
- system-prompt-templatingSkill
- testing-agentsSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 90
When sub-agents live in different AgentModules, inject via AgentRunner[SubAgentClass]:
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Use
codemap find "SymbolName"to locate any symbol before reading — it gives exact file + line range and is faster than grep across the whole repo.
Sub-Agent Spawning & Result Aggregation
Overview
AgentRunnerBase.run() can be called multiple times with different @agent
classes. An orchestrator function calls runner.run(sub_agent, prompt) for
each delegated task and collects AgentResponse.content strings.
Sequential and parallel patterns are both straightforward:
Sequential sub-agent spawning
# orchestrator.py — from __future__ import annotations is safe here
from __future__ import annotations
import asyncio
from lauren_ai import agent
from lauren_ai._agents._runner import AgentRunnerBase as AgentRunner
@agent(model=None, system="You are a research specialist.")
class ResearchSubAgent: ...
@agent(model=None, system="You are a writing specialist.")
class WritingSubAgent: ...
async def spawn_sequential(runner: AgentRunner, prompts: list[tuple]) -> list[str]:
"""Run sub-agents one at a time and collect results."""
results = []
for sub_agent, prompt in prompts:
response = await runner.run(sub_agent, prompt)
results.append(response.content)
return resultsParallel sub-agent spawning
async def spawn_parallel(runner: AgentRunner, prompts: list[tuple]) -> list[str]:
"""Run sub-agents concurrently and collect all results."""
tasks = [runner.run(sub_agent, prompt) for sub_agent, prompt in prompts]
responses = await asyncio.gather(*tasks)
return [r.content for r in responses]
asyncio.gatherruns all coroutines on the same event loop. BecauseMockTransportuses a shared dequeue, parallel tests must queue enough responses for every concurrent call.
Runner setup for tests
from lauren_ai._agents._runner import AgentRunnerBase as AgentRunner
from lauren_ai._config import LLMConfig
from lauren_ai._transport import Completion, TokenUsage
from lauren_ai._transport._mock import MockTransport
def _make_runner(mock=None):
if mock is None:
mock = MockTransport()
cfg = LLMConfig(provider="anthropic", model="mock-model", api_key="mock")
runner = AgentRunner(transport=mock)
return runner, mock
def _completion(content="OK", *, n=1):
return Completion(
id=f"c{n}", model="mock-model", content=content,
tool_calls=[], stop_reason="end_turn",
usage=TokenUsage(input_tokens=10, output_tokens=5),
)Cross-module AgentRunner injection
When sub-agents live in different AgentModules, inject via
AgentRunner[SubAgentClass]:
class OrchestratorService:
def __init__(self, research: AgentRunner[ResearchSubAgent]) -> None:
self._research = research
async def run_task(self, topic: str) -> str:
response = await self._research.run(ResearchSubAgent(), topic)
return response.contentReference files
| File | Contents |
src/lauren_ai/_agents/_runner.py | AgentRunnerBase.run() |
src/lauren_ai/_agents/__init__.py | @agent(), AgentResponse |
src/lauren_ai/_transport/_mock.py | MockTransport |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

