ai-powered-conversational-intelligence

Prompt 34 – Multi-Agent Supervisor

A governed supervisor that routes one analysis turn across typed specialist agents, behind ENABLE_MULTI_AGENT_SUPERVISOR (default off). Served at POST /analyst/supervise. The Prompt 33 analyst (POST /analyst/investigate) and /ask are unchanged.

Is multi-agent justified here? (The decision)

Inspected first: the existing LangGraph is a single deterministic state machine (agent/graph.py, 18 nodes) plus the Prompt 33 analyst graph. The only LLM-driven routing already in the codebase is the multi-source router, which fans out to sources. The specialists this prompt names are mostly pure functions over data that already exists: analytics, forecasting, root cause, recommendation linking, governance. Only the planner calls a model.

Decision: no LLM-to-LLM agent mesh. A model choosing which agent to call next, or agents messaging each other, adds unbounded routing, cost and injection surface without adding capability. Instead, a plain-Python supervisor applies a fixed routing policy. Every routing decision is inspectable, and every refusal (budget, circuit, timeout, permission) is an explicit, testable value. Agents return typed outputs and never talk to each other.

LangGraph was not used for the supervisor, because the routing has no branches that need graph state. The Prompt 33 graph is kept as-is and is the comparison baseline.

Specialist agents

Each agent is an AgentSpec (agent/multiagent/contracts.py): its allowed tools, its truth-level ceiling, its cost per call, and its retry count.

Agent Kind Allowed tools Truth ceiling Cost Does
planner llm llm_plan (ASK) AI_INFERENCE 3 Splits the question. Output is text only.
governance control none AI_INFERENCE 0 Refuses sensitive requests. Redacts rows before any engine sees them.
semantic retrieval business_context (ASK, 2 attempts) CONFIRMED_BUSINESS_TRUTH 2 Governed metric definitions.
sql_data data governed_sql (EXECUTE_SQL, 1 attempt) DATABASE_FACT 5 The only path to data. Wraps run_agent.
analytics engine analytics_engine (ASK) DATABASE_FACT 1 Statistics over the governed rows.
forecast engine forecast_engine (ASK) AI_INFERENCE 1 Projections. Runs only for a forecast intent.
root_cause engine root_cause_engine (ASK) AI_INFERENCE 1 Attribution. Runs only for an explicit comparison pair.
recommendation engine none AI_INFERENCE 0 Reuses the analyst’s recommend node, unchanged.

Reused components

Supervisor policy

agent/multiagent/supervisor.py. Per turn, in order:

  1. Input guard on the question (no cost). A rejection ends the turn.
  2. Governance request: a refuse or require_authorization decision ends the turn before any data is touched.
  3. Planner, then each sub-question re-checked by the input guard. A planner failure falls back to the single question.
  4. Semantic definitions, once, for the tenant’s first database.
  5. For each data task: sql_data -> governance rows -> analytics -> forecast (conditional). Only governed rows reach an engine.
  6. root_cause for each explicit RootCausePair. Never planner-created.
  7. recommendation, over the data tasks’ recommendations.
  8. Validation (agent/multiagent/resolution.py), conflict resolution, status, report.

Every call passes these checks, in order, before it runs: the wall-clock deadline, the turn budget (call count and cost units), and the agent’s circuit breaker. A refusal by any of them is recorded in the trace and in the open items.

Controls

Status

API

POST /analyst/supervise (api/analyst.py, schemas in api/analyst_schemas.py). Same request body and identity rules as /analyst/investigate: requires ASK and EXECUTE_SQL, rejects client-supplied tenant, roles or budget (422), validates the model against the allowlist (400), and shares the /ask concurrency cap. Returns 404 while the flag is off.

Response: status, stop_reason, subquestions, claims (each with agent, task_id, text, truth_level, grounded_in), conflicts (task, key, agents, outcome; never values), violation_count (a count, never the rejected text), open_items, trace, usage, report_markdown.

Configuration

Setting Env var Default
enable_multi_agent_supervisor ENABLE_MULTI_AGENT_SUPERVISOR false
multiagent_max_agent_calls MULTIAGENT_MAX_AGENT_CALLS 16
multiagent_max_cost_units MULTIAGENT_MAX_COST_UNITS 40
multiagent_circuit_failure_threshold MULTIAGENT_CIRCUIT_FAILURE_THRESHOLD 3
multiagent_circuit_cooldown_seconds MULTIAGENT_CIRCUIT_COOLDOWN_SECONDS 60

The per-turn timeout reuses analyst_timeout_seconds. The .env.example block lists them.

Benchmark: supervisor versus the Prompt 33 analyst

eval/multiagent_benchmark.py, run with python -m eval.multiagent_benchmark. Both flows run the same scenarios, with the same fake LLM and the same fake governed SQL. The table comes from that run.

scenario              flow                      status               sql  llm  spec  obs        ms
--------------------------------------------------------------------------------------------------
single_lookup         analyst (LangGraph)       succeeded              1    1     0    1      9.68
single_lookup         supervisor (multi-agent)  succeeded              1    1     5    1      6.07
two_step_question     analyst (LangGraph)       succeeded              2    1     0    2      4.65
two_step_question     supervisor (multi-agent)  succeeded              2    1     7    2      6.13
forecast_intent       analyst (LangGraph)       succeeded              1    1     0    1      3.30
forecast_intent       supervisor (multi-agent)  succeeded              1    1     6    1      3.48
planner_unavailable   analyst (LangGraph)       succeeded              1    1     0    1      2.89
planner_unavailable   supervisor (multi-agent)  succeeded              1    1     5    1      2.99
one_step_fails        analyst (LangGraph)       partial                2    1     0    1      3.75
one_step_fails        supervisor (multi-agent)  partial                2    1     5    1      2.69

Columns: sql = governed SQL executions, llm = planner LLM calls, spec = non-skipped specialist invocations, obs = observed row-count claims, ms = wall time (reported, not asserted, and noisy at this size).

Reading it:

Regression tests: tests/test_multiagent_benchmark.py asserts the equalities above (SQL and planner calls, observed data, partial status on a failing step, the analyst’s zero specialist overhead) and does not assert timing.

Tests

Results: 3,916 backend tests pass (the full suite, including tests/security/). ruff clean on new files, mypy clean on new files. The one remaining mypy error is pre-existing in db/schema_introspection.py.

Limitations (honest)

Risks

Next prompt

Recommended: Prompt 35 – merge the investigation loop into the supervisor and close the registry escalation. Give the supervisor the anomaly follow-up that Prompt 33 has, with the same bounds. Make ToolRegistry always overwrite caller_roles, and update the pinned test. Then run the live evaluation (the Prompt 34 benchmark, plus the real-model questions from Prompt 33’s next section) to decide whether the supervised route should replace the analyst route.