r/LangGraph • u/OpenComplaint524 • Oct 25 '26
Lessons from running a 7-agent LangGraph system in finance: why we moved all math and risk vetoes out of the LLM nodes
Hey r/LangGraph,
Over the past few weeks I have been building a multi-agent investment council using LangGraph, and I wanted to share the biggest architectural mistake we made early on in case it saves someone else some debugging pain.
In our first prototype, we passed raw financial metrics and indicator arrays directly into our specialist agent nodes (Value, Macro, Sentiment, Quant) and let the LLM supervisor weigh the numbers and decide position sizing. Even with strong reasoning models, two things kept breaking:
Context bloat and numeric drift: Feeding dozens of raw floating-point features into the shared graph state caused the agents to subtly hallucinate thresholds or anchor onto whatever number the previous agent mentioned in the debate history.
Prompt-based risk rules are too soft: When we told our Risk Manager (CRO) persona in its system prompt to reject trades with high volatility, a persuasive bullish argument from the Growth agent would occasionally convince the LLM to bend its own risk rules.
To fix this, we restructured our StateGraph around a strict division of labor:
First, all heavy quantitative math (158 technical factors and gradient-boosted tree scoring) runs in a deterministic Python pre-processing step before the graph even starts. The LangGraph state only receives clean, semantic regimes and pre-computed scores rather than raw data dumps.
Second, while the persona agents still debate qualitative catalysts in parallel branches, the final Chief Risk Officer (CRO) node is backed by a hard deterministic Python gate. If a ticker violates a mathematical boundary (like an earnings window or drawdown limit), the Python code flips `cro_veto = True` in the state and overrides the LLM output before it reaches the final node.
How are you guys balancing deterministic code checks vs LLM routing inside your production graphs?
(Note: English is not my native language, so I used an LLM to help format and polish my raw architecture notes!)
1
u/LLM-logs 11d ago
The general version of your lesson: LLM nodes should argue about meaning, code should own numbers. What tends to work is passing derived signals instead of raw features - not the 40-indicator array, but "RSI crossed above 70 on Tuesday, rank 3 of 50 by momentum". Thresholds get computed once, in one place, and the agents anchor on facts rather than re-deriving (and drifting on) arithmetic from context.
On the veto: make it a graph edge, not a persona. A CRO node whose "no" is prose can be argued with by the next agent; a conditional edge that checks position size against limits and routes to reject cannot. The persona can still write the explanation of the veto - that's a good use of the LLM - but the veto itself should be code.
is_santos_reddit's middleware question is pointing the same direction.
1
u/OpenComplaint524 10d ago
"LLM nodes should argue about meaning, code should own numbers" — I love this phrasing. That perfectly captures the exact wall we hit.
That was precisely the trap we fell into early on. When our CRO was just an LLM prompt telling other agents "No, this is too risky", the other bullish agents would literally debate it into submission in the next turn. It was classic sycophancy.
We ended up doing exactly what you described: the veto is a deterministic conditional edge in Python. If the calculated exposure, ATR volatility, or drawdown crosses the threshold, the graph immediately routes to the reject/abort sink. Zero LLM debate allowed. The CRO agent only gets called afterwards to generate a clean, human-readable post-mortem explanation for the Discord/logs.
To answer is_santos_reddit as well: rather than an external middleware layer, we just used a simple conditional edge function in LangGraph that checks the state payload against strict numerical invariants before any order dispatch node can ever be reached.
Anchoring agents on pre-computed signals (like percentile rank or explicit threshold breaks) rather than dumping raw feature arrays made an enormous difference in token cost and hallucination rates too. Appreciate you distilling it down so cleanly!
Note: English is not my native language, so I used an LLM to help format and polish my raw notes!
1
u/tyag1abhi 7d ago
Yeah, pretty much exactly my experience. Anything to do with numbers such as budgets, impression allocations, or even keeping track of/count of something etc or indicators that could be derived from arithmetic should belong in deterministic python code; LLM in my opinion should be reserved for truly the reasoning portions. This approach gave us the best results.
2
u/OpenComplaint524 7d ago
100% agree, especially on the counting and budget allocation part. It is wild how an LLM can reason through a nuanced trade-off, yet quietly lose track of a simple running total once the context window gets busy. Moving all counters, splits, and derived indicators into plain Python state and only feeding clean summaries to the LLM nodes made debugging way easier for us too.
0
1
u/jmakov Oct 27 '26
Very interesting, tnx for sharing. Similar experience, for math etc. using tools is better than letting them calculate themselves.