Documentation Index
Fetch the complete documentation index at: https://docs.swarms.world/llms.txt
Use this file to discover all available pages before exploring further.
Overview
SubagentRegistry runs agent tasks in the background on a ThreadPoolExecutor, tracking each as a SubagentTask with status, retries, depth, and parent linkage. Use it when one agent needs to fan out work to other agents — recursively if needed — and gather results later.
The module exports three symbols:
| Export | Kind | Purpose |
|---|---|---|
SubagentRegistry | class | Spawns and tracks tasks, gathers results |
SubagentTask | dataclass | Per-task record with status, result, retry info |
TaskStatus | str enum | PENDING, RUNNING, COMPLETED, FAILED, CANCELLED |
Installation
TaskStatus
(str, Enum), so the values compare equal to plain strings (TaskStatus.PENDING == "pending").
SubagentTask
Dataclass describing a single in-flight or completed task. Populated bySubagentRegistry.spawn().
Unique task ID, e.g.
task-a1b2c3d4.The agent instance assigned to this task.
The prompt/task handed to
agent.run(...).Current execution status.
Return value from the agent — set when
status == COMPLETED.Last exception raised — set when
status == FAILED.Underlying
Future returned by the thread pool.ID of the parent task that spawned this one, if any.
Recursion depth — incremented when an agent spawns another subagent.
Number of retries used so far.
Retry budget for this task.
Whitelist of exception classes that trigger retries.
None retries on any exception.Unix timestamp when the task was spawned.
Unix timestamp when the task entered a terminal state.
SubagentRegistry
Constructor
Maximum recursion depth.
spawn() raises ValueError if depth > max_depth.Thread-pool size.
None defers to ThreadPoolExecutor’s default.Methods
spawn()
Submit an agent task to the pool. Returns the new task ID synchronously; the agent runs in the background.Agent instance with a
.run(task) method.The prompt to run.
Set when this task was spawned by another task. Used for tracking trees.
Recursion depth. Spawning from inside another task increments this.
Retry budget on failure.
Only retry on these exception types.
None retries on any exception.When
True, the underlying thread re-raises on final failure (the exception surfaces when you call future.result()). When False, the failure is captured on the SubagentTask and the thread returns None.ValueError if depth > max_depth.
get_task()
Look up aSubagentTask by ID.
KeyError if the ID is not in the registry.
get_results()
Return aDict[task_id, Any] for every completed or failed task. Failed tasks map to their exception object.
cancel()
Attempt to cancel a not-yet-started task. ReturnsTrue if the underlying Future accepted the cancellation.
gather()
Block until tasks complete and return a list of results.Wait policy.
"wait_all" returns once every pending task settles; "wait_first" returns as soon as one does.Max seconds to wait.
None blocks indefinitely.shutdown()
Tear down the thread pool without waiting for outstanding tasks.tasks
Read-only property — snapshot of all known tasks asDict[task_id, SubagentTask].