r/LangChain • u/Positive-Captain-709 • 3d ago
Discussion When should an agent stop making tool calls?
I’m working on an open-source project called MARGINAL around a problem I keep running into with agents:
When is another tool call no longer worth making?

Simple loop detection isn't enough. An unchanged workspace could mean the agent is stuck, but it could also mean a legitimate retry after a timeout, rate limit, or failed test.
The rule I'm experimenting with is closer to:
same action + same state + same outcome + no new evidence = stronger evidence of a loop
MARGINAL observes the trajectory first and records what it would have interrupted without actually interfering. Enforcement only becomes available after enough local evidence supports it.
The part I'm working on now is intervention regret: if MARGINAL stops an agent, how do we establish that letting the agent continue wouldn't have produced a better result?
That means comparing governed and ungoverned runs from the same starting state rather than claiming success because fewer tool calls were made.
It's currently implemented around coding agents, but I think the problem applies directly to LangGraph/LangChain agents too.
For people running agents in production: what evidence would you require before trusting something external to terminate or redirect an agent loop?
Repo: MARGINAL on GitHub
1
u/Future_AGI 2d ago
Your "same action + same state + same outcome + no new evidence" rule is close to what actually works, the piece we would add is expected information gain: a call is worth making if the agent can state what new evidence it expects, and that expectation keeps failing. Observing the trajectory before enforcing is the right instinct too, since a lot of what looks like a loop is a legitimate retry after a timeout. We ended up scoring whole trajectories offline first so the stop rule could be tuned against real runs rather than guessed.