Skip to content

docs(examples): LangChain agent stopped at its budget - #56

Merged
prashar32 merged 1 commit into
mainfrom
examples/langchain
Jun 4, 2026
Merged

docs(examples): LangChain agent stopped at its budget#56
prashar32 merged 1 commit into
mainfrom
examples/langchain

Conversation

@prashar32

Copy link
Copy Markdown
Owner

What

A runnable LangChain example — examples/langchain/. Wrap a LangChain LLM loop with RiskKernelCallbackHandler and the deterministic governor caps it: one governed step per model call, hard-stopped at the loop budget, with the halt propagating out of llm.invoke() to end the chain.

🛑 RiskKernel halted the LangChain run — reason: loop_budget_exceeded
   ── final ledger (enforced by the governor) ──
     LLM calls (loops) :    6   (budget: 6)

Key-free, like wrap-your-agent

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 ChatOpenAI/ChatAnthropic through run.proxy_config() for the dollar/token ceiling, and points to codebase-qa for the real-model dollar kill.

Stacked on #55

This example only actually stops because of the raise_error=True fix 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 to main (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 at loop_budget_exceeded (exit 0). Error paths checked too — daemon-down prints a start-it hint (exit 1); missing langchain-core prints an install hint (exit 1). py_compile clean.

@prashar32
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
prashar32 force-pushed the examples/langchain branch from 51cb08e to 45f78c6 Compare June 4, 2026 00:00
@prashar32
prashar32 merged commit aee4ea2 into main Jun 4, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant