Measure Claude tokens and cost per email for evals (SHY-14) #17
All Vouch review confidence checks passed
Residual risk 0.60 = Change Risk (0.80) × (1 − Review Confidence (0.25)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.80 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 39% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Sensitive Paths
sensitive_paths
0.080
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #17"
general
weight: 0.35
greptile-apps[bot]
Closes SHY-14
Decision
Ryan picked option 3: skip the dashboard, measure cost only in evals. PR #14 had already removed the per-email list, and this decision means cost needs no new place on the dashboard. As a result this PR has:
ProcessedEmailWhat's in it
cost.py: one price table (US dollars per 1M tokens, Anthropic list prices checked 2026-11-22) for Haiku 5.5 ($0.10 / $0.50), Sonnet 5.5 ($2 / $10) and Opus 5.5 ($4 / $20). These are the three models SHY-12 compares.cost.track()collects the tokens of every Claude call made inside it, per model, so the split setup (Haiku classifies, Sonnet drafts) is priced correctly. A model missing from the table raises an error instead of counting as $0.agent.ask/agent.act: report each call's tokens from LangChain'susage_metadata.actcounts every Claude call in its tool loop. A refused call is counted too, because it is billed.cost.track()nothing is kept, so production runs behave as before.How SHY-12's eval uses it:
Tests
make test: 86 tests, all pass. The 8 new tests inaccounts/test_cost.pycover the prices, a split setup across models, nested tracks,ask(including refusals) andact's multi-call loop.No screenshot: nothing in the UI changes.
🤖 Generated with Claude Code
<!-- greptile_comment -->
<!-- greptile_summary -->
<h2><a href="https://app.greptile.com/api/retrigger?id=115934664&sig=8f31c0c2379041ebf7ba37ddfa9f68730d64837b89e1943fa58ba99de53eba9e"><picture><source media="(prefers-color-scheme: dark)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/RetriggerDark.svg?v=2"><source media="(prefers-color-scheme: light)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2"><img alt="Retrigger" src="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2" align="right"></picture></a><a href="https://app.greptile.com/-/switch-tenant?tenant=shyyronnie&next=%2FRyancg3%2Femail-agent-hack-2026%2Fpull%2F17&utm_source=greptile_review&utm_medium=github&utm_campaign=view_in_greptile"><picture><source media="(prefers-color-scheme: dark)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptileDark.svg?v=2"><source media="(prefers-color-scheme: light)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptile.svg?v=2"><img alt="View in Greptile" src="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptile.svg?v=2" align="right"></picture></a>Confidence Score: 4/5</h2>
<!-- greptile-risk -->
Fix failed-loop accounting before merging so eval costs include calls that were already billed.
<h2><a href="https://app.greptile.com/api/ide/conductor?prompt=IMPORTANT%3A%20Work%20in%20the%20repository%20%22ryancg3%2Femail-agent-hack-2026%22%20on%20the%20existing%20branch%20%22Ryancg3%2Fryancg3%2Fshy-14-cost-per-email%22.%20Checkout%20that%20branch%20%E2%80%94%20do%20NOT%20create%20a%20new%20branch%20or%20open%20a%20new%20PR.%20Push%20your%20changes%20to%20%22Ryancg3%2Fryancg3%2Fshy-14-cost-per-email%22.%0A%0A%23%23%23%20Issue%201%0Aagent.py%3A269-272%0AFailed%20loops%20lose%20billed%20calls.%20%60act%60%20records%20usage%20only%20after%20%60graph.invoke%60%20returns.%20If%20one%20Claude%20call%20succeeds%20and%20a%20later%20call%20fails%20after%20retries%2C%20execution%20skips%20this%20entire%20recording%20loop.%20The%20earlier%20call%20was%20billed%2C%20but%20the%20tally%20omits%20it%2C%20so%20evals%20understate%20spending%20on%20failed%20emails.%20Record%20each%20response%20as%20it%20arrives%2C%20such%20as%20through%20model%20middleware%2C%20and%20add%20a%20test%20where%20a%20later%20call%20raises.%0A%0A---%0A%0AFor%20each%20issue%20above%2C%20determine%20whether%20it%20is%20valid%20and%20should%20be%20fixed.%20If%20so%2C%20fix%20it%20directly.&expires=1795983704&sig=895ab5d5ea8a227ca7014b5616334421ac9c77523576a596a85d363f9b1d666b&repo=ryancg3%2Femail-agent-hack-2026"><picture><source media="(prefers-color-scheme: dark)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/FixAllInConductorDark.svg?v=7"><source media="(prefers-color-scheme: light)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/FixAllInConductor.svg?v=7"><img alt="Fix All in Conductor" src="https://greptile-static-assets.s3.amazonaws.com/badges/FixAllInConductor.svg?v=7" align="right"></picture></a>Findings</h2>
1. <img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"> Failed loops lose billed calls <a href="https://github.com/Ryancg3/email-agent-hack-2026/pull/17#discussion_r4659845033">▶</a>
<details open><summary><h3>Summary</h3></summary>
Adds eval-only tracking for Claude token use and estimated cost, without changing the dashboard or storing costs.
One issue needs fixing: a failed
actloop loses the usage from its earlier successful calls.</details>
<!-- greptile_confidence_score:4 -->
<sub>Reviews (1) · Last reviewed commit: "Measure Claude tokens and cost per email..." · Reviewed by Greptile</sub>
<!-- /greptile_comment -->