TraceLens — Local-First Flight Recorder For AI Agents
Problem
When an AI agent misbehaves or runs up a bill, the usual answer is a cloud dashboard that needs an SDK around every LLM call, an account, and your API keys. Meanwhile the agent already writes logs that nobody can read easily.
Business Impact
It is for developers who build or run AI agents and want to know what an agent did and what it cost, without wiring in a vendor SDK or sending transcripts to a third party. The cost view shows which steps used the most money, and the replay shows where a run hit an error. Because it works from logs that already exist, it can be tried on a past run in a minute.
System Approach
- A FastAPI backend parses JSONL with a universal parser that detects the format per line (Anthropic, OpenAI or generic event) and keeps unknown lines as raw message steps.
- A pricing module holds a static USD-per-million-token table, matched by model name substring, to compute per-step and cumulative cost.
- An analytics step builds totals, cost by model, tool usage and the three most expensive steps.
- A live tail endpoint streams new lines from a growing log file to the browser over Server-Sent Events.
- A wire tap proxy sits in front of the Anthropic API, forwards requests untouched, and splits each one into system prompt, tool schemas, history and the text the user typed.
- The Next.js frontend is hand-styled with no component library, and proxies /api calls to the backend.
Key Decisions & Trade-offs
- Read existing logs instead of requiring an SDK, so any agent that writes a transcript works with no code changes.
- Keep unknown lines as raw message steps, so nothing is silently dropped.
- Store parsed runs as files under backend/data/runs and keep everything on the local machine, so no trace data leaves it.
- Forward auth headers through the wire tap but never write them to disk.
- Use a static price table rather than a live pricing lookup, so cost estimates work offline.
- Ship a mock Anthropic server and a demo script, so the wire tap can be tried without an API key.
Current Status
Working and open source under the MIT license. Run the FastAPI backend with uvicorn and the Next.js frontend with npm run dev, then press Load demo run to replay the bundled sample trace. No automated test suite is included in the repository.
Roadmap
- Add automated tests for the parser and the pricing table.
- Support more trace formats beyond OpenAI, Anthropic and the generic event format.
- Keep the price table current as new models are released.
- Add search and filtering across stored runs.
What I'd Improve Next
- Costs come from a hard-coded price table, so they are estimates and need manual updates when providers change prices.
- The backend port (4651) is hard-coded in the frontend config and wire tap page, so changing it means editing source files.
Explore More
- agentgrade — Production-Readiness Auditor For AI Agents — Most AI agents work in a demo and then fail with real users, because nobody can say whether the agent is getting worse, what it actually did on a bad answer, or who owns it when it breaks.
- Ordermez — Menu Engineering That Shows Which Dishes to Reprice — Most restaurants know their total sales but not which dishes make the money.
- Swarm — An AI-First Community For Agent Builders — A normal developer forum is empty until hundreds of strangers show up every day, which a solo founder cannot fix.
- LedgerMatch — Open-Source Payment Reconciliation For Small Businesses — A Stripe payout is one lump sum that covers dozens of orders, with the fees buried inside.
- All 47 projects — the full catalogue, with live links and repos.