docs(examples): LangChain agent stopped at its budget - #56
Merged
Conversation
prashar32
changed the base branch from
fix/langchain-callback-propagates-halts
to
main
June 3, 2026 23:36
A runnable LangChain example: wrap a LangChain LLM loop with the RiskKernelCallbackHandler and the deterministic governor caps it at the loop budget — the halt propagates out of llm.invoke() and ends the chain. Key-free: it uses LangChain's FakeListLLM, so the loop enforcement runs with nothing but `riskkernel serve` (no model call, no spend). The README shows the few lines to route a real model through the run's proxy for the dollar/token ceiling, and points to codebase-qa for the real-model kill. Linked from the main README.
prashar32
force-pushed
the
examples/langchain
branch
from
June 4, 2026 00:00
51cb08e to
45f78c6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A runnable LangChain example —
examples/langchain/. Wrap a LangChain LLM loop withRiskKernelCallbackHandlerand the deterministic governor caps it: one governed step per model call, hard-stopped at the loop budget, with the halt propagating out ofllm.invoke()to end the chain.Key-free, like wrap-your-agent
Uses LangChain's
FakeListLLM, so the loop enforcement runs with nothing butriskkernel serve— no model call, no spend. The README shows the few lines to route a realChatOpenAI/ChatAnthropicthroughrun.proxy_config()for the dollar/token ceiling, and points tocodebase-qafor the real-model dollar kill.Stacked on #55
This example only actually stops because of the
raise_error=Truefix in #55 — without it LangChain swallows the halt and the loop runs on. Base is set to the #55 branch; merge #55 first and this will retarget tomain(diff becomes example-only).Verification
Ran end-to-end against a keyless daemon with
langchain-core 1.4.0: 6 calls allowed, the 7th halted atloop_budget_exceeded(exit 0). Error paths checked too — daemon-down prints a start-it hint (exit 1); missinglangchain-coreprints an install hint (exit 1).py_compileclean.