▶ Demo film, 4:53 (click the picture to play). Agents propose, the kernel decides: a real account and setup, approved, refused and held requests, the attack lab (the unsafe version spends 2,400 of a 900 budget; the kernel approves exactly three of eight), and the on-chain evidence. The screens are the real dashboard; the payment in the film is simulated settlement, and the three testnet hashes shown are from earlier real runs. Source of the film: video/.
AI agents can propose payments, but only a deterministic kernel can authorize them. A human owner funds a mandate, delegates narrower grants to agents, and every spend is checked against live database state: scope, per-transaction limit, balance, expiry and the whole revocation chain. Language models never decide anything. Their output is parsed into an untrusted, strictly typed proposal, and anything unclear is held for a human.
2026 Shenzhen FinTechathon, International Track, Topic F: Agent Wallet with testnet settlement.
- Mandate → grants. Delegation moves funds from parent to child. Scope can only narrow, expiry can only shorten, and depth is capped. Authority is transferred, never created.
- Concurrency-safe. One Postgres transaction per operation, serialized by a per-mandate row lock, with conditional updates as a second line of defense. Ledger invariants (conservation, reservation backing, settlement backing, movement-log reconciliation) are checked in tests after every step and exposed in the API.
- Safe retries. Idempotency keys are bound to the payload. A replay returns the stored decision.
- Natural-language requests. Deterministic fast path first (free), then a cheap model, then a stronger one only for defined failure classes. Every paid call reserves its worst-case cost in a monthly budget ledger first. Exhausted budget means "unresolved", never "approved".
- Attack demo. The same attacks run against an intentionally unsafe baseline and the real kernel, with measured results.
- Testnet settlement (Topic F). The kernel reserves, then a settlement service sends a Base Sepolia USDC transfer to an operator-allow-listed address and records the transaction hash. Two kernel-approved payments and one anchor of the audit history are on chain (
evidence/SETTLEMENTS.md). Every audit and movement row is hash-chained;GET /mandates/{id}/integrityrecomputes the chain. - Dashboard. A Next.js app (
frontend/) over the real API: mandate cheque with history seal, who may spend, decisions as proposal beside verdict, Ask, Review, Activity, Attack lab, Settings. Full-bleed, scales with the screen, phone layout included.
| Submission pack index (the six deliverables and where each lives) | docs/submission/PACK.md |
| Technical document | docs/submission/TECH_DOC_DRAFT.md |
| Deck | docs/submission/DECK_DRAFT.md |
| Demo film (4:53) and its script and storyboard | docs/demo/budget-kernel-demo.mp4, docs/demo/VOICEOVER.md, docs/demo/STORYBOARD.md |
| Execution evidence (settlements, anchor, hashes) | evidence/SETTLEMENTS.md |
| Security self-assessment (tiers, controls, known risks) | docs/SECURITY_SELF_ASSESSMENT.md |
| Measured results (kernel scripts, evaluation, attacks) | memory/evaluation/RESULTS.md |
| Architecture decisions | memory/decisions/ (ADR-0004 accounting, 0005 concurrency, 0006 cost ledger, 0007 settlement) |
| Competition requirements and checklist | memory/research/COMPETITION.md |
Requirements: Python 3.12, uv, a Postgres database (we use Supabase, session pooler on port 5432).
cp .env.example .env # then fill in DATABASE_URL and BK_ADMIN_TOKEN (model keys are optional)
cd backend
uv sync
uv run python -m budget_kernel.db.migrate # creates the "bk" schema (BK_SCHEMA)
uv run uvicorn budget_kernel.api.app:app --port 8000Interactive API docs are at http://localhost:8000/docs.
With the API running:
uv run --project backend python scripts/demo.py # people, mandate, delegation, requests, revocation, invariants
uv run --project backend python scripts/demo.py --attacks # plus the baseline-vs-kernel attack scenariosIt creates fresh principals and a fresh mandate on every run, so it can be replayed any number of times. It exits 0 only if every expectation held.
People sign in with a username and password (agents and operators with an API key). Public sign-up is off by default; set BK_ALLOW_SIGNUP=1 on the API to show "Create account", or create people with POST /admin/accounts (admin token). A new account has no money: the dashboard walks them through funding a mandate, adding agents and giving them budgets. The first time someone opens the dashboard, a hand-drawn guide circles each tab and says what it is for; any scroll or click closes it, and Settings brings it back (npm run check:tour).
With the API running (BK_SETTLEMENT_MODE=simulated BK_ALLOW_SIGNUP=1 for a local demo; add BK_SCHEMA=bk_dev to keep it off your main schema):
uv run --project backend python scripts/demo_seed.py # seeds a mandate for Nabil (username nabil, password kernel-demo-2026), Ops bot, Research bot; writes frontend/.env.local
cd frontend && npm install && npm run dev # http://localhost:3000, one-tap sign-in per demo account
npm run check:layout # layout check at 1366, 1920, 2560, 1024 and 390 px (needs the above running)
npm run check:flow # the demo story through the UI (agent asks, owner approves, breaker, reinstate, revoke)
npm run check:login # sign-up, setup, sign-in, wrong password, password change (API needs BK_ALLOW_SIGNUP=1)The demo sign-in buttons exist only in development builds; a production build contains no key. The demo owner's password is a demo value for a testnet prototype (override with BK_DEMO_PASSWORD).
cd backend
BK_TEST_SCHEMA=bk_test_<yourname> uv run python -m budget_kernel.db.migrate --test
BK_TEST_SCHEMA=bk_test_<yourname> uv run pytest -q -m "not slow"- Tests run against a real Postgres schema that is truncated at the start of each run. Use your own
BK_TEST_SCHEMAand never run two pytest sessions on the same schema. -m slowadds the long property-based state-machine test.- Some tests take about a minute because every kernel operation makes several round trips to the hosted database.
cd eval
uv run --project ../backend python make_dataset.py # deterministic dataset (seed 20261015)
uv run --project ../backend python runner.py --config offline # kernel scripts + recorded-output gate + rules-only config A
uv run --project ../backend python runner.py --config B # live models: needs DASHSCOPE_API_KEY (C also needs DEEPSEEK_API_KEY, or OPENROUTER_API_KEY with BK_ESCALATION_PROVIDER=openrouter)Results are written to eval/results/<date>/. See eval/README.md.
- Database. Create a Supabase project (or any Postgres 15+). Put the session pooler URL (port 5432) in
DATABASE_URL. Do not use the transaction pooler (port 6543). The kernel relies onSET LOCALand row locks inside one transaction. - Schema. Run
uv run python -m budget_kernel.db.migrate. It is forward-only and idempotent. Do not expose the schema through Supabase's REST API. Theanonandauthenticatedroles must have no access, and the tables have row-level security enabled with no policies. - Secrets. Set these on the server only, never in the browser or the repository:
DATABASE_URL,BK_ADMIN_TOKEN, optional model keys (DASHSCOPE_API_KEY,DEEPSEEK_API_KEY,OPENROUTER_API_KEY) and, for settlement,SETTLEMENT_PRIVATE_KEY(a testnet-only wallet). - Worker (optional).
BK_WORKER=1starts a housekeeping thread inside the API process everyBK_WORKER_INTERVALseconds (default 30): settlement and anchor reconcile (testnet mode), cost-ledger stale sweep, and the kernel sweep for due mandates. It authorizes nothing. For payment reconcile setBK_WORKER_PRINCIPALto a service principal that owners have bound as settler; without it only anchors, the sweeps and ticks run. - Run.
uv run uvicorn budget_kernel.api.app:app --host 0.0.0.0 --port 8000, behind a TLS proxy. SetBK_CORS_ORIGINSto the dashboard's origin. - Rate limiting. The API limits requests itself (
api/ratelimit.py): 120 per minute per principal (per client IP when not authenticated), plus a separate 30 per minute bucket forPOST /agent/requestandPOST /interpret, which cost real money./healthis exempt. A limited call gets HTTP 429, codeRATE_LIMITEDand aRetry-Afterheader. Tune withBK_RATE_DEFAULT_PER_MINandBK_RATE_MODEL_PER_MIN(0 turns a bucket off). The limiter is per process: with several replicas the effective limit is multiplied by the replica count (a shared store is future work).X-Forwarded-Foris ignored unlessBK_TRUST_PROXY=1; set that only behind a proxy that appends the real client address, because the last entry is then used as the client IP. - Bootstrap. Create principals with
POST /admin/principalsand theX-Admin-Tokenheader. Each API key is shown once and stored only as a SHA-256 hash.
backend/src/budget_kernel/
kernel/ the only code that changes balances (ops, funds, sweep, invariants)
api/ FastAPI layer: authentication, strict request schemas, error mapping
proposals/ untrusted proposal schema and deterministic semantic checks
routing/ fast path, model routing, interpret-then-decide
providers/ OpenAI-compatible adapter for Qwen / DeepSeek / OpenRouter
costledger/ monthly inference-budget reservation and reconciliation
simulation/ attack scenarios; naive_baseline/ is the deliberately unsafe comparison
backend/migrations/ plain SQL, applied in name order
backend/tests/ integration, concurrency, boundary (import-graph and secret scans)
eval/ labelled dataset, runner, dated results
scripts/demo.py clean-start replay; demo_seed.py seeds the dashboard demo accounts; wipe_dev.py empties the scratch schema bk_dev before a re-seed; reset-demo.ps1 does both and restarts the dashboard
frontend/ Next.js dashboard (components/ui = shared layout parts; scripts/ = browser checks and the capture-*.mjs screenshot scripts)
video/ Remotion source of the demo film: cd video, npm install, add your voice-over as public/vo.wav, npm run render (screenshots are copied in from docs/submission/screenshots/r3)
evidence/ on-chain evidence: settlements, anchor, hashes
memory/, docs/ decisions, plans, results, submission documents
The kernel never imports model, routing or provider code, and only simulation/ may import the unsafe baseline. Both rules are enforced by tests in backend/tests/boundary/.
Team members: read ONBOARDING.md first, then AGENTS.md (Claude Code also reads CLAUDE.md). Claim your task on memory/WHO_IS_WORKING.md before you start, and update memory/TASK_BOARD.md when you finish. Keep API keys, credentials and real financial data out of the repository.
Full non-slow backend suite: 412 passed on 2026-10-20 (plus the login review tests, 61 passed in the login, setup and rate-limit files). An independent review of the login change found two issues, both fixed with tests (docs/SECURITY_SELF_ASSESSMENT.md, review log).
This is a hackathon prototype on testnet. It has not been externally audited and must not hold real funds. The known limitations (for example, per-transaction limits can be split into smaller purchases) are listed in the security self-assessment.
