agentprof 是用 Rust 写的开源命令行工具,专门用来分析 AI agent CLI(Claude Code / GitHub Copilot CLI / OpenAI Codex)每一次对话烧掉的 token 都花在哪。 不止统计花了多少,更回答「花得值不值」。
🕳️
看不见 token 去向
总数对,归属不明 — 哪个 turn / tool 拿走的?
📉
没有 ROI 信号
MCP 装了 20 个 tool,到底用了几个?
🌫️
Prompt cache 黑盒
命中率多少?省了多少 token / 钱?
🔌 生活类比
把 AI agent 想成一台很费油的车。市面上的 token 计费工具只告诉你「这次开了 500 公里、烧了 30 升油」。
agentprof 是装在车上的仪表盘 + 行车记录仪:
把每次踩油门 / 刹车 / 怠速都记下来,做成一张「这趟旅程的油耗火焰图」+「每个绕路决策的 ROI 表」,
让你能下一次少绕远路、关掉没用的发动机配件、避开堵车路段。
它到底解决什么问题?
直接看 OpenAI / Anthropic Dashboard 当然能看到 token 总数,但真实排查里你会很快遇到三类痛点, 这正是 agentprof 要替你抹平的:
| 痛点 | 没工具时 | agentprof 的做法 |
|---|---|---|
| 看不见 token 去向 | 总数 = 几万,不知道哪个 turn / tool / hook 拿走的 | 火焰图 + Turn Summary + Tool Rank 把 token 切到 turn / tool / hook 级 |
| 没有 ROI 信号 | MCP 装了 20 个 tool,不知道哪个真正被 agent 用过 | MCP Waste 报表:标出加载了但从没被调用的 tool + 估算浪费 token |
| Prompt cache 黑盒 | Claude 缓存命中率多少?省了多少?不知道 | Cache 段:诚实 / 朴素两种 hit rate + 净节省 + 总节省 |
👇 想深入理解每一类痛点?点开下面的折叠卡片,每张都给你:① 示例 · ② 为什么必要 · ③ agentprof 的做法 · ④ 还有什么其他方案。
1 看不见 token 去向 点击展开
🧪 示例
直接看官方 dashboard:
2026-06-11 conversation-7f3a 42,317 input 8,124 output
🤔 为什么必要
这只告诉你「整次对话用了 50k」,但你不知道:哪一个 turn 是 token 大户?哪个 tool call 拿走最多 context?是不是有 MCP 工具加载了 schema 但从来没用?
✅ agentprof 的做法
把 events.jsonl 流式解析成
Episodes(一个 turn 的所有 tool/hook/skill 调用集合),再用 compute_analysis 生成火焰图 SVG + Turn Summary 表 + Tool Rank 表。每一行 token 都有「归属」。🔀 其他方案
手写脚本 grep + jq 也能从 events.jsonl 提数据,但火焰图渲染 / 跨 session 聚合 / TUI 交互都得自己写一遍。agentprof 把这些做成开箱即用。
2 没有 ROI 信号 点击展开
🧪 示例
你给 Copilot CLI 装了 GitHub MCP server(17 个工具)+ Filesystem MCP(8 个工具)+ 自家 Jira MCP(12 个工具)。每次对话 system prompt 多 5k tokens 描述这 37 个工具。问题:agent 到底用过哪些?
🤔 为什么必要
MCP 工具的 schema 是常驻 context window 的;加载了但不用 = 直接浪费钱 + 挤掉真正需要的上下文。
✅ agentprof 的做法
agentprof mcp-waste --tool-descriptions sidecar.json 给出每个 MCP server 的「加载次数 / 零调用次数 / 估算浪费 token」三栏报表,并 list 出"从没被调用过的工具"。这是 agentprof 区别于其他 token 工具的核心卖点。🔀 其他方案
官方 Anthropic console 不显示工具维度;某些自建可观测平台(如 Helicone)可以打 tag,但需要先在 prompt 中手工注入 metadata。agentprof 直接从 session 日志反推,零侵入。
3 Prompt cache 黑盒 点击展开
🧪 示例
Claude Sonnet 启用 prompt caching 后理论上能省到 10% 价格。但你的 cache hit rate 到底是 30% 还是 90%?省了多少钱?
🤔 为什么必要
cache 是按 5 分钟 TTL 自动失效的;如果 agent 调用之间间隔过长,cache 实际命中率会比想象的低很多。
✅ agentprof 的做法
agentprof analyze --export md 输出的 Cache 段会给出 honest hit rate(cache_read / (cache_read + cache_creation))+ naive hit rate(cache_read / (cache_read + input_tokens))+ net saved / gross saved tokens(按 Claude Sonnet 4.x 2026-06 价格估算)。aggregate --by model 给出跨 session 的 CacheCr / CacheRd / Hit% / NetSaved 列。🔀 其他方案
官方 console 显示 cache_read / cache_creation 原始数字但不算 hit rate 也不算节省金额;agentprof 一次性给出 6 个数字 + 价格对照表。
下一步
读完本课你已经知道 agentprof 解决什么问题。下一课用 5 分钟装好工具,跑出你的第一张火焰图。
📂 相关源码:
agentprof-core/analyzer/mod.rs
compute_analysis
📂 相关源码:
agentprof-cli/cmd/analyze.rs
run