Skip to content

docs(examples): codebase-qa demo — watch the governor kill a runaway agent - #31

Merged
prashar32 merged 2 commits into
mainfrom
feat/example-codebase-qa
May 31, 2026
Merged

docs(examples): codebase-qa demo — watch the governor kill a runaway agent#31
prashar32 merged 2 commits into
mainfrom
feat/example-codebase-qa

Conversation

@prashar32

Copy link
Copy Markdown
Owner

Adds examples/codebase-qa/, a self-contained, runnable demo that shows the headline feature end to end: deterministic budget/loop governance halting a runaway agent, with a real model.

What it is

A plain ReAct-style codebase Q&A agent (no RAG, no vector DB, no framework) built on the Python SDK. Every model call is routed through run.proxy_config(), so the proxy meters tokens/cost and the governor enforces the per-run loop / dollar / time budget around the loop. The kill comes from the daemon (HTTP 402), surfaced as BudgetExceeded — never faked in the script.

Two modes:

  • --mode normal — a sensible question that completes within budget; prints each step, tokens, and running USD cost, then the answer.
  • --mode runaway — the same agent with a deliberately weak stopping condition (told to re-read every file), so it loops. Counters climb, then the loop budget halts it cleanly.

Layout

examples/codebase-qa/
├── agent.py            # the governed ReAct agent (stdlib + RiskKernel SDK only)
├── requirements.txt    # the RiskKernel SDK (stdlib-only itself)
├── README.md           # 60-second run for both modes + expected output
└── sample/             # a tiny todo app used as the target codebase
    ├── main.py  store.py  models.py  config.py  README.md

Dependencies

None beyond the RiskKernel Python SDK and an LLM provider key (BYO ANTHROPIC_API_KEY on the daemon). The proxy call uses stdlib urllib.

Notes

  • Read-only agent, so it doesn't exercise the approval gate; the README points to governed_tool / run.approve for the side-effecting case.
  • Also wired into the root README and CHANGELOG ([Unreleased]).

prashar32 added 2 commits May 31, 2026 18:21
A self-contained, runnable demo (Python SDK + proxy) that shows RiskKernel's
headline feature end to end: a real ReAct loop over a codebase that the
deterministic governor halts on its loop/dollar budget — the kill comes from
the daemon (HTTP 402), not the script.

- examples/codebase-qa/agent.py: --mode normal (finishes within budget) and
  --mode runaway (loops until the governor halts it); routes every model call
  through run.proxy_config() so the proxy meters cost and enforces the budget;
  stdlib-only (urllib) beyond the RiskKernel SDK. No RAG, vector DB, or framework.
- examples/codebase-qa/sample/: a tiny todo app used as the target codebase.
- examples/codebase-qa/README.md: 60-second run for both modes + expected output.
- README + CHANGELOG: link the example.
Ran both modes against a real model and replaced the placeholder output with the
actual runs. The halt summary now reports the authoritative signal — the gateway's
402 loop_budget_exceeded surfaced as BudgetExceeded — and the governor's own ledger
(loops vs budget, cost vs budget), rather than the run's persisted status field,
which lags for loop/time-budget halts (see #34). The deterministic kill is
unchanged; only the demo's reporting is made precise.
@prashar32
prashar32 merged commit 6678e63 into main May 31, 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