Agent Graph Review — October 2026
A review of svc-ai's system-node pipeline (app/agents/graph.py), prompted by a chat turn that produced a poor answer and this trace error:
Planning skipped: 1 validation error for ExecutionPlan
node_plans
Field required [type=missing, input_value={'task_summary': 'Find cu...[], 'tool_guidance': {}}, input_type=dict]
It covers answer quality first, then reliability and serialisation, then cost and latency. Its sequel — conversation quality and memory, October 2026 — is the Conversation Quality Review. The priority is fixed: quality may not be traded away for either of the others. How the graph works today is in Agent Graph. This page holds the findings, the evidence behind them, and the remaining plan.
How it was verified
The real graph, driven offline.
tests/agents/scripted_model.pyis a realBaseChatModel. It answers each structured-output call with raw tool-call arguments, as a provider does, so LangChain's own parser validates them. It also records every message list each node sends. Replaying the reported planner output reproduced the error above character for character. It also showed what the answering model received (below).Library behaviour checked against the installed packages, not from memory: langchain-core 1.4.7, langchain-openai 1.1.14, langchain-anthropic 1.4.6, langgraph 1.2.5, langgraph-checkpoint 4.1.1, pydantic 2.12.5, anthropic 0.109.2, openai 2.41.1.
Not verified live. The OpenAI and Anthropic keys in
modules/dotenv/dev/ai.envreturned 401 on 2026-10-06, so no live model calls were made. It is not known which model produced the reported failure. Latency and dollar figures below are call counts and prompt sizes, not measurements.
What went wrong in the reported turn
Four defects stacked up:
The planner was rejected for following its instructions. The prompt said "leave
active_nodesempty" for a lookup and "only includenode_plansfor nodes listed inactive_nodes". Butnode_planswas required. A correct plan for a simple question, with nothing dispatched and nothing planned, failed validation.retrieval_focushad the same flaw. The contradiction dated from commit61ac79d2.The fallback wrote the exception into the conversation. It read
Planning skipped: {exc}, the full pydantic dump, and every skill node was then dispatched.Every answering node replayed this run's messages as the agent's own earlier replies.
_context_messages_from_statepassed on every non-tool message. The model received:``
System Human <the current question> ← before the history Human <earlier question> AI <earlier answer> AI "Recon — complexity: simple, …" AI "Planning skipped: 1 validation error for ExecutionPlan …" AI <the web-retrieval node's summary> Human <the current question again>``This happened on every chat turn, not only on failure.
When planning succeeded, the configured agent did not run. The planner-skip path (and recon's direct-answer path) hand the answer to
__synthesis__. Synthesis had no date and no agent name, only render tools, and an instruction not to introduce anything absent from its input. On a direct answer, its input said "respond directly".
Findings and status
| # | Area | Finding | Status |
|---|---|---|---|
| Q2 | Quality | Node status, error text and retrieval summaries replayed to the answering model as assistant turns; current question placed before the history | Fixed (Phase 0) |
| Q3 | Quality | Synthesis answered with no date or agent name; direct answers told not to use the model's own knowledge | Fixed (Phase 0) |
| Q4 | Quality | "yes", "no", "great" sent to the agent's own question got a canned greeting | Fixed (Phase 0) |
| Q5 | Quality | An unavailable evaluation's error text written into long-term memory | Fixed (Phase 0) |
| Q6 | Quality | System nodes always told "Perform your assigned role." (they are never planned) | Fixed (Phase 0) |
| Q7 | Quality | On the planner-skip and direct-answer paths the configured agent never runs: its tools (web search, webhooks, knowledge tools) are unavailable | Fixed (Phase 2) |
| Q8 | Quality | The evaluator's revision of a failed draft is a full rewrite inside a JSON tool argument: unstreamed, can be truncated, never re-checked | Fixed (Phase 2) |
| Q9 | Quality | External retrieval summarises web results and the answer re-summarises the summary; the raw evidence is dropped | Fixed (Phase 2) |
| Q10 | Quality | Maths-proof <reasoning_standards> injected into every skill-node prompt regardless of task | Fixed (Phase 2) |
| Q11 | Quality | Fallbacks pick the wrong default silently. A failed gate on a no-knowledge agent routes direct, so no web search for "latest" questions. A failed recon reports scope_check="clear" | Fixed (Phase 1) |
| R1 | Reliability | null for a defaulted field, one malformed list item, or a fractional score failed the whole structured object | Fixed (Phase 0) |
| R2 | Reliability | No system-node call uses native constrained decoding, include_raw, or a retry that sends the validation error back | Fixed (Phase 1) |
| R3 | Reliability | tool_guidance: dict[str, list[str]] cannot be enforced under any provider's strict mode. PlannerAgent's schema exposes server-owned fields (plan_id, created_at, status) | Fixed (Phase 1) |
| R4 | Reliability | Auth and other 4xx errors are swallowed node by node. With a bad key, gate, recon and planning each failed and carried on, writing the provider's response body into the run | Fixed (Phase 1) |
| R5 | Reliability | Fields named reasoning / rationale can trigger a billed reasoning_extraction refusal on Claude 5.x | Fixed (Phase 1) |
| R6 | Reliability | WorkerAgent._structure_output repair uses with_structured_output without a method. On ChatOpenAI that defaults to strict json_schema, which rejects the dict[str, Any] an object field maps to, so the repair fails | Fixed (Phase 1) |
| R7 | Reliability | The parse transform runs json.loads on raw model text and aborts the run on fenced JSON | Fixed (Phase 1) |
| R8 | Reliability | RouterAgent, LoopAgent and ReviewerAgent call string methods on response.content, which is a list on the Responses API | Fixed (Phase 1) |
| R9 | Reliability | Model and pipeline engines stream raw str(exc) to the client | Fixed (Phase 1) |
| S1 | Serialisation | _sse used bare json.dumps: one datetime, UUID, cycle or NaN replaced the whole turn with "An internal error has occurred." | Fixed (Phase 0) |
| S2 | Serialisation | A structured terminal result reached the user as a Python dict repr | Fixed (Phase 0) |
| S3 | Serialisation | Pydantic objects held in graph state revive from checkpoints with a warning today, and will not in a future langgraph release (LANGGRAPH_STRICT_MSGPACK). Integers beyond 64 bits fail the checkpoint write | Fixed (Phase 1) |
| T1 | Tests | Graph tests mocked with_structured_output to return constructed objects, so the model → parser boundary was never exercised | Fixed (Phase 0): scripted model, boundary and context tests |
| C1 | Cost / latency | A simple "current information" question makes at least 6 sequential model calls (gate → recon → planning → retrieval → answer → evaluator), all on the agent's own model | Reduced (Phase 2): 4 calls for that question, 3 when nothing is retrieved |
| C2 | Cost / latency | No prompt caching anywhere. Every system prompt starts with a timestamp precise to the minute, so no prefix can match | Fixed (Phase 3) |
| C3 | Cost / latency | Gate and recon are two sequential classification calls on the same inputs. For a single-node agent the planner decides only whether to run it | Fixed (Phase 2); recon merged into the gate (October 2026): it had become a re-read of triage, plus a second call in another prompt whenever triage failed. One triage node, capped at 4,096 output tokens, falls back without asking again (see Agent Graph) |
Prompt sizes measured on the scripted run (no knowledge bases, no history):
| Call | Instructions | Tool definitions |
|---|---|---|
| Recon | ~0.5K | — |
| Planning | ~0.7K | — |
| External retrieval | ~0.9K | plus web tools |
| Answer | ~4K | ~7.6K (agent) / ~5.2K (synthesis) |
| Evaluator | ~3K | — |
All of them grow with evidence and history.
Phase 0 — shipped
| Change | Where |
|---|---|
| Planner prompt, schema and field descriptions agree: plans only for dispatched skill nodes, none when none are dispatched. A system node with no plan works to the overall goal instead of a placeholder | app/agents/graph.py |
Answering nodes read [system, …earlier turns, task] (_history_messages). Every node names the messages it writes (_name_node_messages), which is how history is told apart from the run. System messages in the history become a <conversation_notes> block, because Anthropic refuses one mid-thread. _context_messages_from_state was removed | app/agents/graph.py |
Node failures go to state.errors as a one-line note (now model_errors.describe): a pydantic error names its fields, a provider error its status. They never go into message content, the evaluator's critique, or memory | app/agents/graph.py |
| Synthesis gets the date and the agent's name. A direct answer, with nothing retrieved and nothing produced, may use the model's own knowledge | app/agents/graph.py |
| Bare replies ("yes", "great", "later") short-circuit only with no conversation; social inputs (greetings, thanks, farewells) always do | app/agents/graph.py |
app/util/safe_json.dumps never raises. Every SSE frame goes through it, and _result_text is the one way a result becomes text | app/util/safe_json.py, app/inference/engine.py, app/inference/rules.py, app/routers/agent.py, app/inference/engines/graph_based.py |
Tests at the boundary: raw arguments through the real parser for every schema, plus a walk over every ModelOutput subclass. The real graph is checked for what the answering model receives | tests/agents/scripted_model.py, test_system_node_schemas.py, test_answer_context.py, tests/test_safe_json.py |
Phase 1 — shipped
| Change | Where |
|---|---|
native_structured_output per model: every seeded model; an unknown, Azure-deployment or pre-4.5 Claude model keeps function calling | app/services/model_capabilities.py |
Fatal provider errors (401, 403, 404, exhausted quota) end the turn once: one stream error frame with an actionable message and a code, a 502 on the batch API. Every other failure degrades its step. No error frame carries exception text | app/services/model_errors.py, graph_based._stream_graph, main.py |
tool_guidance is a list of {node_id, tools} items (stored as a map). PlannerAgent's model fills ProposedPlan and code builds the ExecutionPlan. The gate's reasoning field is basis | app/agents/graph.py, app/agents/planner/ |
The gate's fallback route reads the request (_fallback_route). Recon reports scope_check: unavailable when the check did not run | app/agents/graph.py |
Role agents read block content. The parse transform reads fenced or prefixed JSON (safe_json.loads_lenient) | app/agents/*.py, app/agents/operations.py |
| Checkpoints: svc-ai's state types registered to revive as themselves, and a write that cannot fail | app/agents/checkpoint.py |
| Structured calls are tagged and their tokens never reach the stream | STRUCTURED_OUTPUT_TAG, graph_based._stream_graph |
Tests: tests/services/test_structured_output.py covers the schema rules for every ModelOutput. It also checks offline the request payload each client builds (Chat Completions, Responses API, Anthropic), and the call paths. The other suites are tests/agents/test_fatal_errors.py, tests/agents/test_checkpoint.py, and the native capability cases in tests/services/test_model_capabilities.py.
Decisions taken in Phase 1:
Graph state keeps its pydantic objects (
EvaluatorVerdictand the role agents' results); their types are registered instead of being converted to dicts. Converting would have changed every reader ofstate.resultsfor no behavioural gain.LangGraph
RetryPolicywas not adopted. The provider clients already retry transient failures (MODEL_CALL_RETRIES), and the policy's default retries 400s and 401s on top. If it is ever adopted it needs an explicitretry_on.The retrieval query planner and reranker degrade even on a fatal error. Retrieval also runs without a chat model behind it (knowledge search), and in a turn the gate has already reported the error.
Not migrated in Phase 1: the generative setup routers. They moved onto
structured_callwith Phase 3 (below).
Still unverified live. The request payloads are checked offline against the installed clients. A provider-side refusal of a strict schema falls back to function calling on its own and is logged ([structured:…] … refused native …); watch for that line on the first live runs.
Phase 2 — first three items shipped
| Change | Where |
|---|---|
No planner call for a single-node graph. __planning__ returns the node with no model call | app/agents/graph.py (SINGLE_NODE_PLAN_NOTE) |
One triage call replaces gate + recon. The gate asks TriageProfile (route and task shape together). Recon reads it and calls a model only when the triage failed. The gate prompt keeps the route a data-source decision | app/agents/graph.py (TriageProfile, _task_structure_brief), app/prompts.py (build_gate_routing_prompt(task_structure=…)) |
Effect, on the reported question (counted on the real graph with a scripted model):
| Before | After | |
|---|---|---|
| Calls when nothing is retrieved | 4 or 5 | 3: triage, agent, evaluator (pinned by test_a_chat_costs_three_model_calls_when_nothing_is_retrieved) |
| Triage prompt | gate ~0.5K + recon ~0.5K tokens, sequential | ~1.05K tokens, one call |
| Answering node | __synthesis__, 7 render tools (~5.2K tokens of definitions), no agent tools | the agent, its 13 tools (~7.6K tokens of definitions) |
The answering node's larger tool list is deliberate: it is the agent's own set. The pipeline still needs measuring on the gold datasets (below) before this is called a quality gain rather than a correctness fix; the live keys returned 401.
Phase 2 — the rest shipped (October 2026)
Found while CHAINR Bot scored 77% on the gold datasets, with a spread of ±40 points. Section 1 of that work made the benchmark trustworthy (evaluation.md#the-platform-benchmark); these are the pipeline fixes.
| Change | Where |
|---|---|
| Any tool that answered is a citable source. The ledger knew web, document and knowledge sources only, so citing an agent's own tool, or a case's scripted one, was "FABRICATED" | app/agents/source_ledger.py (_called_tools) |
A plain agent does its own web and tool work. Triage saw only the general tools, and on a web or tool route a pre-step ran the real tools (never the agent's, never a case's scripted ones, even with tools switched off), summarised the result as primary knowledge, and told the agent to reuse it. A one-node agent now pre-retrieves from its knowledge bases only and calls its tools itself. Graphs keep the fan-out | app/agents/graph.py (_plain_agent_route) |
Evidence, not a summary (Q9), for plain agents. Knowledge retrieval already passes rendered passages with [S#] ids, and web and tool results now come from the agent's own calls. Graphs' web and tool workers still summarise; that is a cost change to measure on its own | — |
| Reasoning standards only where a derivation is asked (Q10). The maths-proof rules were the last thing the model read on every request. They now go to a task triage calls complex or one that asks to prove, derive, solve or find all | app/agents/graph.py (_needs_reasoning_standards) |
| Citations for sources, not for everything. The response standards asked for a marker after every fact from a tool result, so plain tool data and supplied material got invented Sources entries. Now only retrieved knowledge, web pages and documents are cited | app/prompts.py (RESPONSE_FORMATTING_STANDARDS) |
| The pipeline's own decisions at temperature 0. Triage, recon, the evaluator and the memory summary ran at the agent's temperature (0.7 by default), so a route or a verdict varied run to run. Models that take no temperature are left alone | app/agents/graph.py (_deterministic) |
| A revision starts on an empty preview. fe-core already cleared the live preview at each node's end; Stop now keeps only what the preview shows, not the draft and the revision run together | fe-core Chat.tsx |
Measured by the platform benchmark on the deploy that ships it, against the section 1 baseline. Not verified live from the devcontainer.
The plan from here
Guardrail for every phase: the platform's gold datasets, before and after. The platform benchmark does this for CHAINR Bot whenever the code that shapes its answers changes (below). A call is removed or moved to a cheaper model only when the scores hold.
Nothing in this review is still open. The changes below are measured by the platform benchmark on the deploy that ships them.
How to measure a pipeline change
On a deployed environment this is automatic. The platform benchmark (evaluation.md#the-platform-benchmark) runs CHAINR Bot on every gold dataset whenever the code that shapes its answers changes, and compares each run with the bot's last one. The bot is a fixed reference agent that answers through this pipeline, so a deploy that moves its scores without changing the bot's own definition has moved the pipeline. Its page shows the score per release, its trend, and its place among the built-in models (which run once per dataset version, as a baseline). A regressed verdict on a benchmark run is the signal to look.
To measure a change before it ships, or on an agent of your own, every evaluation run is compared automatically against its evaluation's last comparable run (a regressed / improved / unchanged verdict, per-case movement). So:
Before deploying, press Evaluate on a representative agent (Assurance, or the agent's page). The gold datasets are ticked by default.
Deploy the change.
Press Evaluate again. It reuses the same experiments, so each run gets a verdict against the last. Governance → Evaluation → Reports shows the verdicts, and Assurance shows the agent's status.
The agent's version does not change, because the pipeline is not part of it, so the comparison is like for like. Cost per case is on the leaderboard.
Phase 3 and the leftovers — shipped (October 2026)
| Change | Where |
|---|---|
Cache marks per provider. Anthropic caches only what is marked, so the system message is sent as one text block with cache_control: ephemeral. Tools come before the system prompt in Anthropic's prefix, so that one mark caches the tool definitions too. OpenAI caches any prefix of 1,024 tokens or more on its own. The call carries a prompt_cache_key (a hash of the model, the system message and the tool names), so calls that share a prefix go to the same cache, on both Chat Completions and the Responses API. Other providers get neither. A prefix below a model's minimum (above) is simply not cached | app/services/prompt_cache.py, tests/services/test_prompt_cache.py (each client's request payload, offline) |
| Evidence, not a summary, for graphs too (Q9). The web and tool retrieval workers in multi-node graphs used to hand the answering nodes their own summary of what they found. They now pass the results themselves, with each tool result labelled (up to 4,000 characters each, 16,000 in all). The worker's notes follow as a summary, marked as yielding to the results wherever the two differ | app/agents/graph.py (_retrieval_evidence) |
A cheaper triage model, optional. TRIAGE_MODEL (svc-ai, provider/model) names the model that triages every agent run. It is off by default. It is used only for an agent on the same provider. Triage reads the whole request, so a model on another provider would receive prompts that the agent, and any routing or residency rule that chose its model, never sent there. A model the deployment cannot reach falls back to the agent's own, with a warning. The setting is part of /health's fingerprint, so changing it re-runs CHAINR Bot's benchmark. Adopt one only when that run holds | app/agents/graph.py (_configured_triage_llm, _same_provider), app/routers/health.py (ANSWERING_SETTINGS) |
Generative setup on the structured-call layer (the Phase 1 leftover). Agent, skill, skillset, toolkit, knowledge and rules setup now make one structured_call. That brings native decoding where the model takes it, salvage, and one retry that says what was wrong, inside the same 100-second budget. They used to rely on function calling and a blind second attempt. A provider that refuses the model answers 422 with an actionable reason, never exception text. Usage comes from the meter, no longer estimated by hand. The six proposal schemas inherit ModelOutput, so their reasoning field (which Claude 5.x can refuse) is explanation to the model and still reasoning in the response | app/services/structured_generation.py (generate), the six app/routers/*_setup.py, app/skills/generation.py |
| CHAINR Bot's instructions beyond the platform (section 3 of the score work). The bot now has explicit guidance for six things. Supplied material comes first. It never invents. It reports tool results exactly. On contested questions it gives no verdict of its own and no false balance. It never infers sensitive characteristics. It answers what only sounds sensitive, and asks one question when a request is ambiguous | svc-core app/services/system_resources/definition.py (BOT_SYSTEM_PROMPT) |
Not verified live (the dev keys returned 401). The first deploy's provider usage shows whether caching works: cache-read tokens on the bot's calls, priced at the cache-read rate (cost-monitoring.md#exact-per-call-cost). The platform benchmark run that the same deploy triggers shows whether the scores held.
Not done, by choice: cache marks on the pipeline's own short prompts (triage, the evaluator). Most sit below the minimum cacheable length, and Haiku's minimum is 4,096 tokens.
Phase 3 — the plan as written
Prompt caching:
Order each call as tools → fixed instructions → per-agent context → history → volatile content (date, query, evidence).
Make the date day-granular, in the user turn.
Use Anthropic
cache_controlbreakpoints and an OpenAIprompt_cache_key.Minimum cacheable lengths differ by model (Anthropic's prompt-caching docs, October 2026): 512 tokens on Opus 5 / 5.5 and Sonnet 5.5, 1,024 on Sonnet 4.5 / 4.6 / 5, 4,096 on Haiku 4.5. Short classification prompts on Haiku do not cache at all.
An optional faster model tier for triage, adopted only if the gold datasets show no regression. Adaptive-RAG and CRAG both use small classifiers for these decisions, and Anthropic's "Building effective agents" recommends routing easy work to smaller models.
Cost levers (October 2026)
The cost-control programme's token work, after the review above. Where a turn's tokens go is measured per call since svc-ai migration 27: every call carries a step and a pass_index beside its node, and POST /stats/steps sums a set of turns by them (see cost-monitoring.md). Any agent's or skill's page now shows it as Where the tokens go, per answer, and the benchmark and Assurance rows show cost per answer beside the score. The baseline — CHAINR Bot and one customer-shaped agent on the gold datasets, cost per answer by step — is not yet recorded: it needs a benchmark run, and the deployment's monthly spending ceiling was reached in October 2026, so the benchmark stands aside until the month resets. It goes here when it is.
Each lever is one of two kinds:
Waste removal — the model is sent the same thing it was sent before, once. Measured on cost alone.
Proportionate effort — the model is sent less, or a cheaper model does some of the work. Measured on the gold datasets, paired against the agent as configured, before it joins a cost profile.
| Lever | Kind | Status |
|---|---|---|
| The memory block is held to a fixed size; a plain agent's memory is the turn cut to 400 + 800 characters, not the whole answer | Waste removal (memory content changes) | Shipped (B1.2) — evaluations run with memory off, so no benchmark sees it: cost only |
| A direct chat's system prompt is sent once, not once per turn | Waste removal | Shipped (B1.2) |
| svc-core sends at most the newest 100 messages / ~1M characters of a conversation, every system message kept | Waste removal | Shipped (B1.2) — svc-ai's own budget (B1.3) is what keeps a prompt under the model's limits |
| A cache breakpoint at the end of the history, so the next turn reads the conversation from cache | Waste removal | Shipped (B1.1) — unmeasured: keep where cache reads outweigh writes (writes cost 1.25× on Anthropic) |
| Every tool-loop round caches up to its tail, so the next round reads it | Waste removal | Shipped (B1.1) — unmeasured; a turn that calls no tool pays the write premium on its task for nothing |
| Triage and the quality check cache their system prompts; triage's conversation moved into its user message so its system prompt is the same every turn | Waste removal | Shipped (B1.1) — unmeasured; a prompt below the model's minimum cacheable length is simply not cached |
| A conversation is fitted to the model's window and long-context price tier: old documents stubbed, whole turns dropped in blocks of four | Waste removal (bounds) | Shipped (B1.3) — changes nothing for a conversation that fits; one that did not fit would have failed or been billed at the higher tier |
| The 10-turn history window slides one turn at a time, so past turn 10 the history breakpoint is never read | Proportionate effort | In Balanced and Economy (B2.2: the window moves four turns at a time); Thorough keeps one at a time. Measured with them by B2.3 |
Cost profiles — the pipeline's depth chosen per agent: history turns, revisions, memory, a history token cap (app/agents/effort.py), sent on every request by one builder (svc-core app/services/agent_spec.py) | Plumbing | Shipped (B2.1) |
| Balanced: no quality check on a simple request, one revision rather than two, 6–9 turns replayed in blocks of four (so the history breakpoint is read), half the memory, a 24K-token history cap | Proportionate effort | Built, opt-in per agent and unmeasured (B2.2). Measured by B2.3 (below), which needs approval |
| Economy: Balanced, with the agent's maker's lightest model in the same region (svc-core's choice, under the workspace's rules) running triage, planning, retrieval's query planning and reranking, the quality check and memory summaries, and answering a request triage calls simple on a plain agent | Proportionate effort (a cheaper model does some of the work) | Built, opt-in per agent and unmeasured (B3). Saves nothing for an agent already on its maker's lightest model — every agent on today's deployment, whose two models are light. Measured beside Balanced by B2.3 |
Measuring Balanced and Economy (B2.3)
Balanced or Economy becomes anyone's default only on evidence: the gold datasets, run under both profiles, scored by the same judge. The instrument is the Cost profiles evaluation preset (presets.CostProfilesPreset): one agent, one variant per profile, the agent's own profile as configured. Run on every gold dataset with repeats, its leaderboard puts each profile's mean score, spread and cost per answer side by side, and the regression verdicts compare like with like.
The measurement is CHAINR Bot (it decides whether the bot switches) and one customer-shaped agent with a skill graph, each on the seven gold datasets (83 cases) with three repeats, under all three profiles: about 2 × 83 × 3 × 3 ≈ 1,500 answers and as many judge calls, roughly $0.75–2.25K. Economy only differs from Balanced where a lighter model exists, so it is measured once Claude routes are available (on the open-weight stand-ins both models are already the lightest tier). It needs approval before it runs, and the deployment's monthly spending ceiling must have room. A profile is adopted where its mean score is within the datasets' tolerance of Thorough's on every dataset and no gate case breaks (the regression verdict's per-case movement); Economy is also compared with Balanced, which isolates the lighter model's effect. Otherwise the lever that cost the score is dropped from it and it is measured again.