Skip to main content

enterprise_ai.subagents

Source: sdks/python/src/enterprise_ai/subagents/__init__.py. Back to the Python SDK reference index.

note

This page is generated by tools/docs/gen_sdk_reference.py from the SDK sources and the OpenAPI text folders. Do not edit it by hand: change the source and regenerate.

Class SubagentSpawner​

Track spawned children of one run and refuse spawns beyond the limits.

Attributes:

NameTypeRequiredDescription
childrenlist[Any]yesChildren spawned so far: server answers for spawn, results for spawn_local.
clientyesPlatform client used for remote children, None for local use only.
depthyesDepth of the current run, 0 for the root.
max_depthyesDeepest level a child may reach.
max_subagentsyesMaximum number of children of this run.
run_idyesParent run on the server, None for local children.

Constructor SubagentSpawner​

SubagentSpawner(client: Any = None, run_id: str | None = None, depth: int = 0, max_depth: int = 1, max_subagents: int = 3) -> None

Spawner of one run with its depth and count limits; no child yet.

NameTypeDefaultRequiredDescription
clientAnyNonenoParent client.
run_idstr | NoneNonenoParent run on the server, needed by spawn.
depthint0noDepth of the current run, 0 for the root (default 0).
max_depthint1noDeepest level a child may reach (default 1); beyond it PolicyDenied subagent_depth_exceeded is raised.
max_subagentsint3noMaximum number of children of this run (default 3); beyond it BudgetExhausted subagent_limit is raised.

SubagentSpawner.child​

child() -> SubagentSpawner

Spawner for a grandchild level (depth + 1), sharing the limits.

This element takes no parameter.

Returns: SubagentSpawner. A SubagentSpawner: Track spawned children of one run and refuse spawns beyond the limits.

SubagentSpawner.from_manifest​

from_manifest(manifest: dict[str, Any], **kwargs: Any) -> SubagentSpawner

Build a spawner with the limits spec.autonomy.max_depth (default 1) and max_subagents (default 3) of an Agent Manifest.

NameTypeDefaultRequiredDescription
manifestdict[str, Any]yesAgent Manifest of the parent, as a dict.
**kwargsAnynoOther constructor arguments: client, run_id, depth.

Returns: SubagentSpawner. A SubagentSpawner: Track spawned children of one run and refuse spawns beyond the limits.

SubagentSpawner.spawn​

spawn(agent: str, input: Any = None, **extra: Any) -> Any

Spawn a sub-agent run. Starts a child run from a pending or running parent (else 409 run_not_running) and returns its Execution Contract. Needs tenant_admin, developer or agent and the scope agents:run. Checks, in order: the Kill Switch Registry; the depth against autonomy.max_depth (default 1, 409 subagent_depth_exceeded); the number of children against autonomy.max_subagents (default 3, 409 subagent_count_exceeded); the child agent against the subagents list of the parent manifest (403 subagent_not_allowed); the parent delegation. The child budget cannot exceed what the parent has left, the child joins the parent session, and a running parent records a subagent step.

Route: /v1/runs/{run_id}/subagents (POST).

NameTypeDefaultRequiredDescription
agentstryesChild agent, name or agent:<name>. Default: the agent of the parent run.
inputAnyNonenoInput of the child run, optional.
**extraAnynoExtra fields merged into the request body.

Returns: Any. Decoded JSON answer of the operation "Spawn a sub-agent run".

Raises: ValueError, the typed errors of the transport (Errors).

SubagentSpawner.spawn_local​

spawn_local(agent: Any, task: Any, **run_kwargs: Any) -> Any

Run a child :class:~enterprise_ai.agent.Agent in-process with depth + 1.

NameTypeDefaultRequiredDescription
agentAnyyesLocal agent; its subagents is set to a spawner one level deeper before it runs.
taskAnyyesTask given to agent.run.
**run_kwargsAnynoExtra arguments of agent.run.

Returns: Any. What agent.run returns.

Model SubagentResult​

Result of one child run.

Fields:

NameTypeRequiredDescription
namestryesName of the child agent (remote name, or the name of the local agent or callable).
run_idstr | NoneyesRun of a remote child, None for a local one.
statestryesFinal state in lowercase, for example completed, succeeded, failed or timed_out.
outputAnynoOutput of the operation (transcript, image references...).
errorstr | NonenoError message of a failed or timed out child, None otherwise.

Class SubagentManager​

Spawn children in parallel, monitor them and inject their results into the parent turn.

SubagentSpawner

Attributes:

NameTypeRequiredDescription
max_parallelyesMaximum number of children running at the same time.
poll_intervalyesSeconds between two reads of a remote child run.
resultslist[SubagentResult]yesEvery SubagentResult collected by run_parallel, in order.
timeoutyesMaximum wait in seconds for a remote child.

Constructor SubagentManager​

SubagentManager(max_parallel: int = 4, poll_interval: float = 1.0, timeout: float = 3600.0, **kwargs: Any) -> None

Build a spawner able to run children in parallel; the limits come from the SubagentSpawner arguments.

NameTypeDefaultRequiredDescription
max_parallelint4noMaximum number of children running at the same time (default 4).
poll_intervalfloat1.0noSeconds between two reads of a remote child run (default 1).
timeoutfloat3600.0noMaximum wait in seconds for a remote child (default 3600); past it the result is timed_out.
**kwargsAnynoArguments of SubagentSpawner: client, run_id, depth, max_depth, max_subagents.

SubagentManager.inject_results​

inject_results(messages: list[dict[str, Any]]) -> int

Append the results not yet announced as one user message. Returns how many were added.

NameTypeDefaultRequiredDescription
messageslist[dict[str, Any]]yesMessage list of the parent turn, extended in place with a user message Subagent results:.

Returns: int. Number of results announced, 0 when none was pending (no message added).

SubagentManager.run_parallel​

run_parallel(tasks: list[tuple[Any, Any]]) -> list[SubagentResult]

Run [(agent, input), ...] in parallel; agent is a name (remote) or a local agent/callable.

NameTypeDefaultRequiredDescription
taskslist[tuple[Any, Any]]yesPairs (agent, input); the limits are checked for every child before any starts.

Returns: list[SubagentResult]. A SubagentResult: Result of one child run.

Raises: ValueError.