callbacks entry in the run config and records tool starts, results, and errors.
Attach the callback
In this example,agent is your already-built LangGraph/LangChain agent and
my_input is the input it normally accepts.
handler.reset() before
the next run to clear its recorded state.
Let the interrupt reach your application
AtSTOP, the handler raises LoopGuardInterrupt unless observe-only mode is
enabled. LangChain callbacks normally suppress callback errors, so set
handler.raise_error = True when you want to catch the interrupt around invoke.
An agent can have another error boundary around tool execution. If that boundary
catches the interrupt and returns an error message to the model, the agent may
continue. Configure it to propagate LoopGuardInterrupt and verify this using
a repeated-empty-result run before relying on automatic interruption.
For LangGraph’s ToolNode, handle_tool_errors=False propagates tool errors;
this also changes handling of ordinary tool failures. A custom error handler can
instead re-raise LoopGuardInterrupt while handling other exceptions. Check the
behavior of your installed framework version.
REPLAN and PAUSE remain recorded recommendations. This integration does not
automatically replace a plan, suspend a graph, or roll back a completed tool call.
Observe first
Use observe-only mode when tuning thresholds or comparing LoopGuard decisions with your own run labels:interrupted report field records whether STOP was reached,
including in observe-only mode. Track actual execution separately in your application.
Load application settings
Save a smallloopguard.yml in your working directory:
Keep a report with the result
The repository’srun_with_loopguard
helper returns the agent result alongside interruption state, signals, decisions,
and metrics. For example, from a repository checkout with your compiled agent:
config_path.
Use the stream wrapper for supported graph updates
UseLoopGuard.stream() to inspect supported streamed graph updates and the
decisions LoopGuard records: