← Projects

TraceLens — Local-First Flight Recorder For AI Agents

Active
Next.js 15React 19TypeScriptPythonFastAPIUvicornhttpxServer-Sent Events
View Repository →
▶Product demo

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