A tool that maps AI agent steps, tokens, and cost
agentcanvas turns recorded Pydantic AI agent runs into an interactive HTML diagram. It reads traces already stored in Logfire and connects the user question, agent decisions, model calls, tool calls, nested sub-agents, and final answer into one step-by-step view. Each model call shows input tokens, output tokens, reasoning tokens, and cost, and the report also totals the full run cost.
Clicking a step opens more detail, such as tool input, tool output, timing, available tools, provider, response id, and model settings. The output is one self-contained HTML file, so it can be opened without a server and shared in meetings. After installation, setting LOGFIRE_READ_TOKEN lets it build a report from the latest run, a selected trace id, or a chosen output file.
The repository includes a demo agent with five tools, a nested sub-agent, and a multi-turn conversation.
Key points
- It converts Pydantic AI runs from Logfire into an interactive HTML workflow diagram.
- It shows model calls, tool calls, nested sub-agents, and multi-turn conversations.
- It reports tokens and cost for each step and for the full run.
- The report is a single HTML file that works offline and is easy to share.
- For cost control, it helps teams find which agent steps are using the most tokens or money.
Quick term guide
- Pydantic AI
- A Python tool for building AI agents.
- nested sub-agents
- Smaller agents called by a main agent to handle part of a task.
- input tokens
- Small pieces of text sent into an AI model as part of a request.
- output tokens
- Small pieces of text produced by an AI model and used for pricing.
- output token
- A small piece of text the AI produces in its answer.
- reasoning tokens
- Tokens a model uses for its internal thought process before answering — invisible in the output but included in the bill.
- reasoning token
- A small piece of text the model uses while working through an answer, which can add to cost.
- self-contained HTML
- An HTML file that includes what it needs to display the page by itself.