Your Agent Is Leaking Tokens. Build a Decision Ledger on a Free Server
Description and use
Build an agent that logs every decision to a SQLite ledger and stops when the token budget is exhausted, using a free MonkeyCode server.
Problem
An LLM‑powered agent can repeatedly call the same tool, rephrase, and retry, causing silent token budget leaks without errors.
Outcome
A lightweight, self‑auditing agent that logs every decision and enforces a token budget, preventing silent leaks on a free server.
Workflow
- Provision a free Linux server via MonkeyCode dashboard and install Python 3.10+ and requests
- Export MC_API_KEY, MC_BASE_URL, MC_MODEL, and MC_BUDGET_TOKENS as environment variables
- Create agent.py: initialize SQLite ledger, define call_llm(), a placeholder search_tool(), and main() loop
- In main(), loop while used tokens < BUDGET: call LLM, parse JSON action, execute tool, record decision and token usage in ledger
- Verify token counts from LLM response and update used counter
- Stop loop when budget exceeded or LLM returns stop action
Evidence
MonkeyCode’s free tier includes a 10M token allowance and a free server option.
The final artifact is a SQLite ledger with a hard token budget.
- Record date: 2026-09-06T15:37:08.175Z