agentcanvas 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agentcanvas-0.1.0/.gitignore +25 -0
- agentcanvas-0.1.0/CHANGELOG.md +40 -0
- agentcanvas-0.1.0/LICENSE +21 -0
- agentcanvas-0.1.0/PKG-INFO +238 -0
- agentcanvas-0.1.0/README.md +212 -0
- agentcanvas-0.1.0/agentcanvas/__init__.py +22 -0
- agentcanvas-0.1.0/agentcanvas/__main__.py +4 -0
- agentcanvas-0.1.0/agentcanvas/cli.py +79 -0
- agentcanvas-0.1.0/agentcanvas/logfire_client.py +104 -0
- agentcanvas-0.1.0/agentcanvas/models.py +102 -0
- agentcanvas-0.1.0/agentcanvas/parser.py +311 -0
- agentcanvas-0.1.0/agentcanvas/pricing.py +51 -0
- agentcanvas-0.1.0/agentcanvas/render.py +811 -0
- agentcanvas-0.1.0/assets/logo.svg +12 -0
- agentcanvas-0.1.0/pyproject.toml +79 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Python-generated files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[oc]
|
|
4
|
+
build/
|
|
5
|
+
dist/
|
|
6
|
+
wheels/
|
|
7
|
+
*.egg-info
|
|
8
|
+
|
|
9
|
+
# Virtual environments
|
|
10
|
+
.venv
|
|
11
|
+
|
|
12
|
+
# Secrets — never commit real tokens (keep .env.example)
|
|
13
|
+
.env
|
|
14
|
+
.env.local
|
|
15
|
+
|
|
16
|
+
# Generated report
|
|
17
|
+
agent_flow.html
|
|
18
|
+
|
|
19
|
+
# Tooling caches
|
|
20
|
+
.pytest_cache/
|
|
21
|
+
.ruff_cache/
|
|
22
|
+
.mypy_cache/
|
|
23
|
+
|
|
24
|
+
# macOS
|
|
25
|
+
.DS_Store
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to **agentcanvas** are documented here.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.1.0] - 2026-06-12
|
|
11
|
+
|
|
12
|
+
Initial release.
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
|
|
16
|
+
- **Logfire client** (`LogfireClient`) — reads agent traces via the Logfire Query API
|
|
17
|
+
(SQL + read token); region configurable with `LOGFIRE_BASE_URL`.
|
|
18
|
+
- **Span-tree parser** (`parse_run`) — turns the OpenTelemetry GenAI spans emitted by
|
|
19
|
+
Pydantic AI into a typed `WorkflowReport`: conversation turns, model rounds, tool
|
|
20
|
+
calls, and **nested agents-as-tools** (recursive, to any depth).
|
|
21
|
+
- **Exact cost** — per model call and per run, computed from tokens via
|
|
22
|
+
[`genai-prices`](https://github.com/pydantic/genai-prices); reported as "unknown"
|
|
23
|
+
when the model is not in the price database.
|
|
24
|
+
- **Reasoning & token usage** — per-call thinking summaries and input/output/reasoning
|
|
25
|
+
token counts, aggregated for the whole run.
|
|
26
|
+
- **Self-contained HTML report** (`render_html`) — a Figma-style, pan/zoom/drag canvas
|
|
27
|
+
with a single consistent Logfire-inspired palette, featuring:
|
|
28
|
+
- block diagram of the full workflow with nested agent frames,
|
|
29
|
+
- a guided tour with **auto** and **manual** (Space / click / arrows) stepping,
|
|
30
|
+
- a click-through, resizable inspector and a full conversation transcript,
|
|
31
|
+
- long content expanding into a modal; everything embedded, works offline.
|
|
32
|
+
- **CLI** — `agentcanvas` console script (and `python -m agentcanvas`): build the report
|
|
33
|
+
from the latest or a specific trace, list recent runs, choose the output file.
|
|
34
|
+
- **Example agent** (`assets/scripts/main.py`) — a thinking agent with five tools, a
|
|
35
|
+
nested sub-agent and a multi-turn conversation, plus scripts to record the demo media.
|
|
36
|
+
- Packaging, typing (mypy), linting (ruff), tests (pytest), and CI/CD (GitHub Actions
|
|
37
|
+
with PyPI Trusted Publishing).
|
|
38
|
+
|
|
39
|
+
[Unreleased]: https://github.com/vstorm-co/agentcanvas/compare/v0.1.0...HEAD
|
|
40
|
+
[0.1.0]: https://github.com/vstorm-co/agentcanvas/releases/tag/v0.1.0
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Vstorm
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agentcanvas
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Visualize Pydantic AI agent workflows from Logfire traces as an interactive HTML diagram.
|
|
5
|
+
Project-URL: Homepage, https://github.com/vstorm-co/agentcanvas
|
|
6
|
+
Project-URL: Repository, https://github.com/vstorm-co/agentcanvas
|
|
7
|
+
Author-email: Vstorm <info@vstorm.co>
|
|
8
|
+
License: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: agents,logfire,observability,pydantic-ai,visualization
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
17
|
+
Requires-Python: >=3.12
|
|
18
|
+
Requires-Dist: genai-prices>=0.0.66
|
|
19
|
+
Requires-Dist: httpx>=0.27
|
|
20
|
+
Requires-Dist: pydantic>=2.0
|
|
21
|
+
Requires-Dist: python-dotenv>=1.2.2
|
|
22
|
+
Provides-Extra: demo
|
|
23
|
+
Requires-Dist: logfire>=4.36.0; extra == 'demo'
|
|
24
|
+
Requires-Dist: pydantic-ai==2.0.0b7; extra == 'demo'
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
|
|
27
|
+
<p align="center">
|
|
28
|
+
<img src="assets/logo.svg" alt="agentcanvas logo" width="92">
|
|
29
|
+
</p>
|
|
30
|
+
|
|
31
|
+
<h1 align="center">agentcanvas</h1>
|
|
32
|
+
|
|
33
|
+
<p align="center">
|
|
34
|
+
<b>See exactly how your AI agent works.</b><br>
|
|
35
|
+
Turn Pydantic AI runs logged to Logfire into a polished, animated diagram of the whole workflow —
|
|
36
|
+
every model call, tool, nested sub-agent, token and dollar.
|
|
37
|
+
</p>
|
|
38
|
+
|
|
39
|
+
<p align="center">
|
|
40
|
+
<a href="#-what-it-shows">Features</a> ·
|
|
41
|
+
<a href="#-quick-start">Quick start</a> ·
|
|
42
|
+
<a href="#-how-it-works">How it works</a> ·
|
|
43
|
+
<a href="#-architecture">Architecture</a> ·
|
|
44
|
+
<a href="CONTRIBUTING.md">Contributing</a>
|
|
45
|
+
</p>
|
|
46
|
+
|
|
47
|
+
<p align="center">
|
|
48
|
+
<img src="assets/demo.gif" alt="Stepping through an agent workflow" width="900">
|
|
49
|
+
</p>
|
|
50
|
+
|
|
51
|
+
<table>
|
|
52
|
+
<tr>
|
|
53
|
+
<td width="50%"><img src="assets/screenshot-inspector.png" alt="Model call inspector"><br><sub>Click any node for a full inspector — tokens, exact cost, reasoning, the tools the model could call.</sub></td>
|
|
54
|
+
<td width="50%"><img src="assets/screenshot-conversation.png" alt="Conversation transcript"><br><sub>The full multi-turn conversation, with tool calls and reasoning.</sub></td>
|
|
55
|
+
</tr>
|
|
56
|
+
<tr>
|
|
57
|
+
<td width="50%"><img src="assets/screenshot-tool.png" alt="Tool inspector"><br><sub>Per-tool input, output and timing.</sub></td>
|
|
58
|
+
<td width="50%"><img src="assets/screenshot-tour.png" alt="Guided tour"><br><sub>A guided tour (auto or manual) narrates each step for client demos.</sub></td>
|
|
59
|
+
</tr>
|
|
60
|
+
</table>
|
|
61
|
+
|
|
62
|
+
<p align="center">
|
|
63
|
+
<a href="https://www.python.org/downloads/"><img src="https://img.shields.io/badge/python-3.12+-1F5FFF?logo=python&logoColor=white" alt="Python 3.12+"></a>
|
|
64
|
+
<a href="https://github.com/pydantic/pydantic-ai"><img src="https://img.shields.io/badge/Powered%20by-Pydantic%20AI-E92063?logo=pydantic&logoColor=white" alt="Pydantic AI"></a>
|
|
65
|
+
<a href="https://pydantic.dev/logfire"><img src="https://img.shields.io/badge/Data-Logfire-7C3AED?logo=pydantic&logoColor=white" alt="Logfire"></a>
|
|
66
|
+
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-1F5FFF.svg" alt="License: MIT"></a>
|
|
67
|
+
<a href="https://vstorm.co"><img src="https://img.shields.io/badge/Made%20by-Vstorm-0F1B33" alt="Made by Vstorm"></a>
|
|
68
|
+
</p>
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## Why
|
|
73
|
+
|
|
74
|
+
Clients rarely understand what an "AI agent" actually does. They see a prompt and an answer —
|
|
75
|
+
not the reasoning, the tool calls, the sub-agents, or the cost. **agentcanvas** reads the
|
|
76
|
+
trace your agent already sends to Logfire and renders it as a clear, interactive block diagram you
|
|
77
|
+
can put on screen in a meeting: *this is the question, here is what the model decided, these are the
|
|
78
|
+
tools it ran, this is what each step cost, and here is the answer.*
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## ✨ What it shows
|
|
83
|
+
|
|
84
|
+
<table>
|
|
85
|
+
<tr>
|
|
86
|
+
<td><b>🧩 Block diagram</b></td>
|
|
87
|
+
<td>The full run as a flow: <code>User → Agent → model call → tools → model call → answer</code>, on a pan / zoom / drag canvas.</td>
|
|
88
|
+
</tr>
|
|
89
|
+
<tr>
|
|
90
|
+
<td><b>🪆 Nested agents</b></td>
|
|
91
|
+
<td>When a tool is itself another agent (with its own tools), it is drawn as a nested frame — recursively, to any depth. The diagram grows with the system.</td>
|
|
92
|
+
</tr>
|
|
93
|
+
<tr>
|
|
94
|
+
<td><b>💬 Full conversation</b></td>
|
|
95
|
+
<td>Every turn is its own frame, connected in sequence. A side panel shows the complete <code>user → assistant → user → assistant</code> transcript.</td>
|
|
96
|
+
</tr>
|
|
97
|
+
<tr>
|
|
98
|
+
<td><b>🧠 Reasoning</b></td>
|
|
99
|
+
<td>The model's "thinking" summary and reasoning-token counts, shown on each model call and in the transcript.</td>
|
|
100
|
+
</tr>
|
|
101
|
+
<tr>
|
|
102
|
+
<td><b>💰 Exact cost</b></td>
|
|
103
|
+
<td>Per model call and for the whole run, computed from tokens via <a href="https://github.com/pydantic/genai-prices">genai-prices</a>.</td>
|
|
104
|
+
</tr>
|
|
105
|
+
<tr>
|
|
106
|
+
<td><b>🔢 Token usage</b></td>
|
|
107
|
+
<td>Input / output / reasoning tokens, per step and aggregated.</td>
|
|
108
|
+
</tr>
|
|
109
|
+
<tr>
|
|
110
|
+
<td><b>🔎 Deep detail</b></td>
|
|
111
|
+
<td>Provider, finish reason, response id, the tools available to the model (with descriptions), output mode and thinking config — in a click-through, resizable inspector.</td>
|
|
112
|
+
</tr>
|
|
113
|
+
<tr>
|
|
114
|
+
<td><b>🎬 Guided tour</b></td>
|
|
115
|
+
<td>An <b>auto</b> walkthrough and a <b>manual</b> step mode (Space / click / arrows, with back), each with plain-language narration for client demos.</td>
|
|
116
|
+
</tr>
|
|
117
|
+
<tr>
|
|
118
|
+
<td><b>📦 Self-contained</b></td>
|
|
119
|
+
<td>The output is a single HTML file — no server, no build, works offline, easy to send.</td>
|
|
120
|
+
</tr>
|
|
121
|
+
</table>
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## 🚀 Quick start
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
pip install agentcanvas
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Set `LOGFIRE_READ_TOKEN` in your environment (or a `.env` file), then build the
|
|
132
|
+
report from your latest agent run:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
agentcanvas # latest run → agent_flow.html (opens in browser)
|
|
136
|
+
agentcanvas --list # list recent runs
|
|
137
|
+
agentcanvas --trace-id <id> # a specific run
|
|
138
|
+
agentcanvas -o report.html --no-open
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Or use it as a library:
|
|
142
|
+
|
|
143
|
+
```python
|
|
144
|
+
from agentcanvas import LogfireClient, parse_run, render_html
|
|
145
|
+
|
|
146
|
+
client = LogfireClient() # reads LOGFIRE_READ_TOKEN
|
|
147
|
+
trace_id = client.latest_trace_id()
|
|
148
|
+
report = parse_run(client.fetch_trace(trace_id), trace_id)
|
|
149
|
+
open("report.html", "w").write(render_html(report))
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
| Variable | Used for |
|
|
153
|
+
|----------|----------|
|
|
154
|
+
| `LOGFIRE_READ_TOKEN` | reading traces via the Logfire Query API (required) |
|
|
155
|
+
| `LOGFIRE_BASE_URL` | optional region override (default US; EU: `https://logfire-eu.pydantic.dev`) |
|
|
156
|
+
| `LOGFIRE_WRITE_TOKEN` | the example agent sending telemetry to Logfire |
|
|
157
|
+
| `OPENROUTER_API_KEY` | the example agent (model via OpenRouter) |
|
|
158
|
+
|
|
159
|
+
### Try the example agent
|
|
160
|
+
|
|
161
|
+
The repo ships a runnable example (`assets/scripts/main.py`) — a thinking agent with five tools,
|
|
162
|
+
a nested sub-agent and a multi-turn conversation. From a checkout:
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
uv sync --all-extras --prerelease=allow # installs the `demo` extra
|
|
166
|
+
uv run --prerelease=allow python assets/scripts/main.py # generates a sample trace in Logfire
|
|
167
|
+
agentcanvas # visualize it
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
## 🔍 How it works
|
|
173
|
+
|
|
174
|
+
```
|
|
175
|
+
Logfire (OpenTelemetry GenAI spans) ──query──► parser ──► payload ──render──► agent_flow.html
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Pydantic AI's instrumentation emits OpenTelemetry GenAI spans (`invoke_agent`, `chat`,
|
|
179
|
+
`execute_tool`). agentcanvas reads them through the Logfire **Query API** (SQL + a read token),
|
|
180
|
+
rebuilds the span tree into a recursive workflow (turns → rounds → tools → nested agents), prices it
|
|
181
|
+
with `genai-prices`, and renders a single self-contained HTML report.
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
## 🏗️ Architecture
|
|
186
|
+
|
|
187
|
+
| Module | Role |
|
|
188
|
+
|--------|------|
|
|
189
|
+
| `logfire_client.py` | Logfire Query API client (SQL → rows) |
|
|
190
|
+
| `parser.py` | span tree → recursive payload (turns, rounds, tools, nested agents) |
|
|
191
|
+
| `pricing.py` | exact cost from tokens via `genai-prices` |
|
|
192
|
+
| `render.py` | payload → embedded HTML / CSS / JS report |
|
|
193
|
+
| `viz.py` | CLI entry point |
|
|
194
|
+
| `assets/scripts/main.py` | demo agent: thinking, five tools, a nested sub-agent, a multi-turn conversation |
|
|
195
|
+
| `assets/scripts/make_demo.py` · `make_screenshots.py` | record the demo video / capture doc screenshots |
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
## Development
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
git clone https://github.com/vstorm-co/agentcanvas.git
|
|
203
|
+
cd agentcanvas
|
|
204
|
+
make install # uv sync (incl. dev tools)
|
|
205
|
+
make all # ruff + mypy + pytest
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
The library is fully typed and tested; `make all` must pass before a PR.
|
|
209
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
## Changelog
|
|
214
|
+
|
|
215
|
+
See [CHANGELOG.md](CHANGELOG.md).
|
|
216
|
+
|
|
217
|
+
## License
|
|
218
|
+
|
|
219
|
+
MIT — see [LICENSE](LICENSE).
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
<div align="center">
|
|
224
|
+
|
|
225
|
+
### Need help shipping AI agents in production?
|
|
226
|
+
|
|
227
|
+
<p>We're <a href="https://vstorm.co"><b>Vstorm</b></a> — an Applied Agentic AI Engineering Consultancy<br>
|
|
228
|
+
with 30+ production agent implementations.</p>
|
|
229
|
+
|
|
230
|
+
<a href="https://vstorm.co/contact-us/">
|
|
231
|
+
<img src="https://img.shields.io/badge/Talk%20to%20us%20%E2%86%92-1F5FFF?style=for-the-badge&logoColor=white" alt="Talk to us">
|
|
232
|
+
</a>
|
|
233
|
+
|
|
234
|
+
<br><br>
|
|
235
|
+
|
|
236
|
+
Made with **care** by <a href="https://vstorm.co"><b>Vstorm.co</b></a>
|
|
237
|
+
|
|
238
|
+
</div>
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="assets/logo.svg" alt="agentcanvas logo" width="92">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">agentcanvas</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<b>See exactly how your AI agent works.</b><br>
|
|
9
|
+
Turn Pydantic AI runs logged to Logfire into a polished, animated diagram of the whole workflow —
|
|
10
|
+
every model call, tool, nested sub-agent, token and dollar.
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
<p align="center">
|
|
14
|
+
<a href="#-what-it-shows">Features</a> ·
|
|
15
|
+
<a href="#-quick-start">Quick start</a> ·
|
|
16
|
+
<a href="#-how-it-works">How it works</a> ·
|
|
17
|
+
<a href="#-architecture">Architecture</a> ·
|
|
18
|
+
<a href="CONTRIBUTING.md">Contributing</a>
|
|
19
|
+
</p>
|
|
20
|
+
|
|
21
|
+
<p align="center">
|
|
22
|
+
<img src="assets/demo.gif" alt="Stepping through an agent workflow" width="900">
|
|
23
|
+
</p>
|
|
24
|
+
|
|
25
|
+
<table>
|
|
26
|
+
<tr>
|
|
27
|
+
<td width="50%"><img src="assets/screenshot-inspector.png" alt="Model call inspector"><br><sub>Click any node for a full inspector — tokens, exact cost, reasoning, the tools the model could call.</sub></td>
|
|
28
|
+
<td width="50%"><img src="assets/screenshot-conversation.png" alt="Conversation transcript"><br><sub>The full multi-turn conversation, with tool calls and reasoning.</sub></td>
|
|
29
|
+
</tr>
|
|
30
|
+
<tr>
|
|
31
|
+
<td width="50%"><img src="assets/screenshot-tool.png" alt="Tool inspector"><br><sub>Per-tool input, output and timing.</sub></td>
|
|
32
|
+
<td width="50%"><img src="assets/screenshot-tour.png" alt="Guided tour"><br><sub>A guided tour (auto or manual) narrates each step for client demos.</sub></td>
|
|
33
|
+
</tr>
|
|
34
|
+
</table>
|
|
35
|
+
|
|
36
|
+
<p align="center">
|
|
37
|
+
<a href="https://www.python.org/downloads/"><img src="https://img.shields.io/badge/python-3.12+-1F5FFF?logo=python&logoColor=white" alt="Python 3.12+"></a>
|
|
38
|
+
<a href="https://github.com/pydantic/pydantic-ai"><img src="https://img.shields.io/badge/Powered%20by-Pydantic%20AI-E92063?logo=pydantic&logoColor=white" alt="Pydantic AI"></a>
|
|
39
|
+
<a href="https://pydantic.dev/logfire"><img src="https://img.shields.io/badge/Data-Logfire-7C3AED?logo=pydantic&logoColor=white" alt="Logfire"></a>
|
|
40
|
+
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-1F5FFF.svg" alt="License: MIT"></a>
|
|
41
|
+
<a href="https://vstorm.co"><img src="https://img.shields.io/badge/Made%20by-Vstorm-0F1B33" alt="Made by Vstorm"></a>
|
|
42
|
+
</p>
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## Why
|
|
47
|
+
|
|
48
|
+
Clients rarely understand what an "AI agent" actually does. They see a prompt and an answer —
|
|
49
|
+
not the reasoning, the tool calls, the sub-agents, or the cost. **agentcanvas** reads the
|
|
50
|
+
trace your agent already sends to Logfire and renders it as a clear, interactive block diagram you
|
|
51
|
+
can put on screen in a meeting: *this is the question, here is what the model decided, these are the
|
|
52
|
+
tools it ran, this is what each step cost, and here is the answer.*
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## ✨ What it shows
|
|
57
|
+
|
|
58
|
+
<table>
|
|
59
|
+
<tr>
|
|
60
|
+
<td><b>🧩 Block diagram</b></td>
|
|
61
|
+
<td>The full run as a flow: <code>User → Agent → model call → tools → model call → answer</code>, on a pan / zoom / drag canvas.</td>
|
|
62
|
+
</tr>
|
|
63
|
+
<tr>
|
|
64
|
+
<td><b>🪆 Nested agents</b></td>
|
|
65
|
+
<td>When a tool is itself another agent (with its own tools), it is drawn as a nested frame — recursively, to any depth. The diagram grows with the system.</td>
|
|
66
|
+
</tr>
|
|
67
|
+
<tr>
|
|
68
|
+
<td><b>💬 Full conversation</b></td>
|
|
69
|
+
<td>Every turn is its own frame, connected in sequence. A side panel shows the complete <code>user → assistant → user → assistant</code> transcript.</td>
|
|
70
|
+
</tr>
|
|
71
|
+
<tr>
|
|
72
|
+
<td><b>🧠 Reasoning</b></td>
|
|
73
|
+
<td>The model's "thinking" summary and reasoning-token counts, shown on each model call and in the transcript.</td>
|
|
74
|
+
</tr>
|
|
75
|
+
<tr>
|
|
76
|
+
<td><b>💰 Exact cost</b></td>
|
|
77
|
+
<td>Per model call and for the whole run, computed from tokens via <a href="https://github.com/pydantic/genai-prices">genai-prices</a>.</td>
|
|
78
|
+
</tr>
|
|
79
|
+
<tr>
|
|
80
|
+
<td><b>🔢 Token usage</b></td>
|
|
81
|
+
<td>Input / output / reasoning tokens, per step and aggregated.</td>
|
|
82
|
+
</tr>
|
|
83
|
+
<tr>
|
|
84
|
+
<td><b>🔎 Deep detail</b></td>
|
|
85
|
+
<td>Provider, finish reason, response id, the tools available to the model (with descriptions), output mode and thinking config — in a click-through, resizable inspector.</td>
|
|
86
|
+
</tr>
|
|
87
|
+
<tr>
|
|
88
|
+
<td><b>🎬 Guided tour</b></td>
|
|
89
|
+
<td>An <b>auto</b> walkthrough and a <b>manual</b> step mode (Space / click / arrows, with back), each with plain-language narration for client demos.</td>
|
|
90
|
+
</tr>
|
|
91
|
+
<tr>
|
|
92
|
+
<td><b>📦 Self-contained</b></td>
|
|
93
|
+
<td>The output is a single HTML file — no server, no build, works offline, easy to send.</td>
|
|
94
|
+
</tr>
|
|
95
|
+
</table>
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## 🚀 Quick start
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
pip install agentcanvas
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Set `LOGFIRE_READ_TOKEN` in your environment (or a `.env` file), then build the
|
|
106
|
+
report from your latest agent run:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
agentcanvas # latest run → agent_flow.html (opens in browser)
|
|
110
|
+
agentcanvas --list # list recent runs
|
|
111
|
+
agentcanvas --trace-id <id> # a specific run
|
|
112
|
+
agentcanvas -o report.html --no-open
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Or use it as a library:
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
from agentcanvas import LogfireClient, parse_run, render_html
|
|
119
|
+
|
|
120
|
+
client = LogfireClient() # reads LOGFIRE_READ_TOKEN
|
|
121
|
+
trace_id = client.latest_trace_id()
|
|
122
|
+
report = parse_run(client.fetch_trace(trace_id), trace_id)
|
|
123
|
+
open("report.html", "w").write(render_html(report))
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
| Variable | Used for |
|
|
127
|
+
|----------|----------|
|
|
128
|
+
| `LOGFIRE_READ_TOKEN` | reading traces via the Logfire Query API (required) |
|
|
129
|
+
| `LOGFIRE_BASE_URL` | optional region override (default US; EU: `https://logfire-eu.pydantic.dev`) |
|
|
130
|
+
| `LOGFIRE_WRITE_TOKEN` | the example agent sending telemetry to Logfire |
|
|
131
|
+
| `OPENROUTER_API_KEY` | the example agent (model via OpenRouter) |
|
|
132
|
+
|
|
133
|
+
### Try the example agent
|
|
134
|
+
|
|
135
|
+
The repo ships a runnable example (`assets/scripts/main.py`) — a thinking agent with five tools,
|
|
136
|
+
a nested sub-agent and a multi-turn conversation. From a checkout:
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
uv sync --all-extras --prerelease=allow # installs the `demo` extra
|
|
140
|
+
uv run --prerelease=allow python assets/scripts/main.py # generates a sample trace in Logfire
|
|
141
|
+
agentcanvas # visualize it
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## 🔍 How it works
|
|
147
|
+
|
|
148
|
+
```
|
|
149
|
+
Logfire (OpenTelemetry GenAI spans) ──query──► parser ──► payload ──render──► agent_flow.html
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Pydantic AI's instrumentation emits OpenTelemetry GenAI spans (`invoke_agent`, `chat`,
|
|
153
|
+
`execute_tool`). agentcanvas reads them through the Logfire **Query API** (SQL + a read token),
|
|
154
|
+
rebuilds the span tree into a recursive workflow (turns → rounds → tools → nested agents), prices it
|
|
155
|
+
with `genai-prices`, and renders a single self-contained HTML report.
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## 🏗️ Architecture
|
|
160
|
+
|
|
161
|
+
| Module | Role |
|
|
162
|
+
|--------|------|
|
|
163
|
+
| `logfire_client.py` | Logfire Query API client (SQL → rows) |
|
|
164
|
+
| `parser.py` | span tree → recursive payload (turns, rounds, tools, nested agents) |
|
|
165
|
+
| `pricing.py` | exact cost from tokens via `genai-prices` |
|
|
166
|
+
| `render.py` | payload → embedded HTML / CSS / JS report |
|
|
167
|
+
| `viz.py` | CLI entry point |
|
|
168
|
+
| `assets/scripts/main.py` | demo agent: thinking, five tools, a nested sub-agent, a multi-turn conversation |
|
|
169
|
+
| `assets/scripts/make_demo.py` · `make_screenshots.py` | record the demo video / capture doc screenshots |
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## Development
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
git clone https://github.com/vstorm-co/agentcanvas.git
|
|
177
|
+
cd agentcanvas
|
|
178
|
+
make install # uv sync (incl. dev tools)
|
|
179
|
+
make all # ruff + mypy + pytest
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
The library is fully typed and tested; `make all` must pass before a PR.
|
|
183
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
## Changelog
|
|
188
|
+
|
|
189
|
+
See [CHANGELOG.md](CHANGELOG.md).
|
|
190
|
+
|
|
191
|
+
## License
|
|
192
|
+
|
|
193
|
+
MIT — see [LICENSE](LICENSE).
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
<div align="center">
|
|
198
|
+
|
|
199
|
+
### Need help shipping AI agents in production?
|
|
200
|
+
|
|
201
|
+
<p>We're <a href="https://vstorm.co"><b>Vstorm</b></a> — an Applied Agentic AI Engineering Consultancy<br>
|
|
202
|
+
with 30+ production agent implementations.</p>
|
|
203
|
+
|
|
204
|
+
<a href="https://vstorm.co/contact-us/">
|
|
205
|
+
<img src="https://img.shields.io/badge/Talk%20to%20us%20%E2%86%92-1F5FFF?style=for-the-badge&logoColor=white" alt="Talk to us">
|
|
206
|
+
</a>
|
|
207
|
+
|
|
208
|
+
<br><br>
|
|
209
|
+
|
|
210
|
+
Made with **care** by <a href="https://vstorm.co"><b>Vstorm.co</b></a>
|
|
211
|
+
|
|
212
|
+
</div>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""agentcanvas — visualize a Pydantic AI agent workflow from Logfire logs.
|
|
2
|
+
|
|
3
|
+
Reads the OpenTelemetry (GenAI) spans emitted by Pydantic AI's instrumentation,
|
|
4
|
+
parses them into a typed :class:`WorkflowReport` (turns, rounds, tools, nested
|
|
5
|
+
agents), prices each model call with ``genai-prices``, and renders a
|
|
6
|
+
self-contained, interactive HTML report.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from .logfire_client import LogfireClient
|
|
10
|
+
from .models import AgentRun, ModelCall, ToolCall, WorkflowReport
|
|
11
|
+
from .parser import parse_run
|
|
12
|
+
from .render import render_html
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"LogfireClient",
|
|
16
|
+
"WorkflowReport",
|
|
17
|
+
"AgentRun",
|
|
18
|
+
"ModelCall",
|
|
19
|
+
"ToolCall",
|
|
20
|
+
"parse_run",
|
|
21
|
+
"render_html",
|
|
22
|
+
]
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"""Command-line interface: pull an agent run from Logfire and build the HTML report."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import sys
|
|
7
|
+
import webbrowser
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from dotenv import load_dotenv
|
|
11
|
+
|
|
12
|
+
from .logfire_client import LogfireClient
|
|
13
|
+
from .parser import parse_run
|
|
14
|
+
from .render import render_html
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def main(argv: list[str] | None = None) -> int:
|
|
18
|
+
load_dotenv()
|
|
19
|
+
parser = argparse.ArgumentParser(
|
|
20
|
+
prog="agentcanvas",
|
|
21
|
+
description="Visualize a Pydantic AI agent workflow from Logfire logs.",
|
|
22
|
+
)
|
|
23
|
+
parser.add_argument("--trace-id", help="Trace id to visualize (default: latest).")
|
|
24
|
+
parser.add_argument("--list", action="store_true", help="List recent runs and exit.")
|
|
25
|
+
parser.add_argument("-o", "--output", default="agent_flow.html", help="Output HTML file.")
|
|
26
|
+
parser.add_argument(
|
|
27
|
+
"--no-open", action="store_true", help="Do not open the report in a browser."
|
|
28
|
+
)
|
|
29
|
+
args = parser.parse_args(argv)
|
|
30
|
+
|
|
31
|
+
try:
|
|
32
|
+
client = LogfireClient()
|
|
33
|
+
except RuntimeError as exc:
|
|
34
|
+
print(f"✖ {exc}", file=sys.stderr)
|
|
35
|
+
return 1
|
|
36
|
+
|
|
37
|
+
if args.list:
|
|
38
|
+
rows = client.list_recent_traces()
|
|
39
|
+
if not rows:
|
|
40
|
+
print("No agent runs found in the project.")
|
|
41
|
+
return 0
|
|
42
|
+
print("Recent agent runs:\n")
|
|
43
|
+
for row in rows:
|
|
44
|
+
dur = row.get("duration")
|
|
45
|
+
suffix = f" ({float(dur):.2f}s)" if dur else ""
|
|
46
|
+
print(f" {row['trace_id']} {row.get('start_timestamp', '')}{suffix}")
|
|
47
|
+
return 0
|
|
48
|
+
|
|
49
|
+
trace_id = args.trace_id or client.latest_trace_id()
|
|
50
|
+
if not trace_id:
|
|
51
|
+
print("✖ No trace found in Logfire.", file=sys.stderr)
|
|
52
|
+
return 1
|
|
53
|
+
|
|
54
|
+
print(f"→ Fetching trace {trace_id} …")
|
|
55
|
+
spans = client.fetch_trace(trace_id)
|
|
56
|
+
if not spans:
|
|
57
|
+
print("✖ Trace contains no spans.", file=sys.stderr)
|
|
58
|
+
return 1
|
|
59
|
+
|
|
60
|
+
report = parse_run(spans, trace_id)
|
|
61
|
+
totals = report.totals
|
|
62
|
+
cost = f", cost ${totals.total_cost_usd:.6f}" if report.meta.cost_known else ", cost unknown"
|
|
63
|
+
print(
|
|
64
|
+
f"→ Parsed: {totals.num_turns} turn(s), {totals.num_model_calls} model call(s), "
|
|
65
|
+
f"{totals.num_tools} tool call(s), {totals.num_nested_agents} nested agent(s), "
|
|
66
|
+
f"{totals.total_tokens} tokens{cost}"
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
out = Path(args.output).resolve()
|
|
70
|
+
out.write_text(render_html(report), encoding="utf-8")
|
|
71
|
+
print(f"✓ Report written: {out}")
|
|
72
|
+
|
|
73
|
+
if not args.no_open:
|
|
74
|
+
webbrowser.open(out.as_uri())
|
|
75
|
+
return 0
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
if __name__ == "__main__":
|
|
79
|
+
raise SystemExit(main())
|