Skip to main content

C-04 Sub-Agent Manager

Brick C: Agents, autonomy, execution. French version: C-04-sub-agent-manager

1. Role and responsibilities​

Creates child runs from a parent run, with depth and count limits and restricted permission inheritance. On the engine side, enterprise_ai.subagents.SubagentManager runs sub-agents in parallel (run_parallel), monitors their state and injects their results into the parent turn (inject_results).

2. Position in the architecture and interactions​

  • Remote children: POST /v1/runs/{id}/subagents then polling with GET /v1/runs/{id}; local children: agents or callables run in a thread pool.
  • The parent keeps the decision: results reach its context on the next turn.

3. Open source component and developed part​

  • Engine: Navin architecture of the Python SDK, with no declared graph. enterprise_ai.loop.AgentLoop takes in messages, prepares the context, manages sessions, resumes a run after a crash, handles stop, cron and heartbeat, and exposes serve(); enterprise_ai.runtime.AgentRunner runs one turn; enterprise_ai.subagents.SubagentManager runs sub-agents in parallel; enterprise_ai.loop.plan.RunPlan carries the plan; enterprise_ai.runtime.bus.MessageBus links channels and engine.
  • Optional adapters: LangGraph (enterprise_ai.runtime.langgraph.build_graph) and Temporal (enterprise_ai.runtime.temporal.build_workflow) reuse the same steps; neither is required.
  • Server side, python -m eai.worker runs the periodic jobs: scheduler tick, event outbox drain, quota reservation expiry, stale heartbeat detection, retention.

4. Data model​

Tables (schema eai, tenant_id RLS):

  • eai.runs (parent_run_id, depth)

Common columns: id uuid, tenant_id uuid NOT NULL, created_at, updated_at; RLS policy current_setting('app.tenant_id', true)::uuid.

5. Contract​

  • Applied contract: execution-contract
  • JSON Schema: contracts/v1/execution-contract.schema.json
  • Key fields: parent_run_id, depth, budgets
  • Validation: POST /v1/contracts/{name}/validate; manifest apply: POST /v1/manifests/apply.

6. API endpoints​

  • POST /v1/runs/{id}/subagents
  • GET /v1/runs/{id}/subagents

Request POST /v1/runs/{id}/subagents:

{
"agent_id": "agt_researcher",
"task": {
"input": "Find similar incidents"
},
"budgets": {
"max_steps": 10
}
}

Response:

{
"run_id": "run_01JA",
"parent_run_id": "run_01J9",
"depth": 1,
"state": "queued"
}

7. SDK examples​

Python:

from enterprise_ai import EnterpriseAI
from enterprise_ai.subagents import SubagentManager

client = EnterpriseAI(base_url="<control-plane-url>", api_key="eai_xxx_secret")
child = client.runs.spawn_subagent("run_01J9", agent="agt_researcher", task="Find the related incidents")
manager = SubagentManager(client=client, max_parallel=4)
results = manager.run_parallel([("agt_researcher", "INC-42 history"), ("agt_billing", "INC-42 invoices")])

TypeScript:

import { EnterpriseAI } from "@enterprise-ai/sdk";

const client = new EnterpriseAI({ baseUrl: "<control-plane-url>", apiKey: process.env.EAI_API_KEY });
const child = await client.subagents.spawn("run_01J9", { agent: "agt_researcher", task: { input: "..." } });

Java:

EnterpriseAIClient client = EnterpriseAIClient.builder()
.baseUrl("<control-plane-url>")
.apiKey(System.getenv("EAI_API_KEY"))
.build();
JsonNode child = client.runs().spawnSubagent("run_01J9", Map.of("agent", "agt_researcher", "task", Map.of("goal", "Collect the sources")));

Go:

c, _ := eai.NewClient(eai.WithBaseURL("<control-plane-url>"), eai.WithAPIKey(os.Getenv("EAI_API_KEY")))
child, _ := c.Runs.SpawnSubagent(ctx, "run_01J9", map[string]any{"agent": "agt_researcher", "task": "Collect the INC-42 timeline"})

8. Configuration​

  • Environment variables: EAI_DATABASE_URL
  • Helm keys: controlPlane.config
  • Client side: SubagentManager(max_parallel=..., poll_interval=..., timeout=..., max_depth=..., max_subagents=...)

9. Security controls​

  • No escalation: the child never holds more scopes than the parent
  • Child budget deducted from parent budget
  • Every request carries the tenant resolved from the credential; PostgreSQL RLS
  • Every mutation and policy decision writes a hash-chained audit event

10. Observability​

  • Prometheus metrics: eai_subagents_spawned_total, eai_subagent_depth
  • Traces: OpenTelemetry spans with GenAI semantic conventions (gen_ai.operation.name, gen_ai.agent.id, gen_ai.tool.name), attributes eai.tenant_id, eai.run_id, traceparent propagation.
  • Audit actions: run.create

11. FinOps units​

  • Child cost aggregated on parent run and root agent.
  • Emitted as Usage Event (POST /v1/finops/usage) with tenant, project, agent and run.

12. Failure modes and resilience​

  • Depth exceeded: 409 subagent_limit
  • Parent cancellation propagated to children
  • Normalized errors (error envelope, message_i18n en/fr)

13. Standalone adoption (client of a client)​

  • enterprise_ai.agent + Control Plane.
  • SDK: enterprise_ai.agent (AgentsClient, RunsClient, SessionsClient)
  • Minimal deployment: Helm chart with controlPlane.enabled=true and PostgreSQL; disabled external components use their in-process fallback.

14. Acceptance tests​

  1. Spawn at max depth + 1 refused
  2. Cancel parent -> children cancelled
  3. Cross-tenant access refused
  4. Error returned in fr with Accept-Language: fr
  5. A sub-agent receives a delegation restricted from its parent one (scopes intersected with its own, classification not higher, same expiry at most, depth + 1): never wider rights; a revoked parent delegation blocks the next spawn and the next sensitive step of every descendant (tests/test_identity_context_delegation.py, see identity-context-delegation.md)