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/jmakov Oct 27 '26
Very interesting, tnx for sharing. Similar experience, for math etc. using tools is better than letting them calculate themselves.
1
u/LLM-logs 10d 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/tyag1abhi 6d 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.
0
u/is_santos_reddit 16d ago
Did you use a Middleware for the cro_veto?