Commit 734b298
fix(langgraph): accumulate multi-step usage in LangGraphTurn [greptile]
_capture overwrote self._usage on every AIMessage, so a multi-step turn (text
-> tool decision -> final text) reported only the last LLM call's tokens and
silently dropped the rest — undercounting in any billing/monitoring that reads
turn.usage(). Accumulate additively across calls via _accumulate_turn_usage
(None+None stays None; real 0 contributes 0). Add a test asserting summed
input/output/total/cache/reasoning tokens across two AIMessages.
The separate 06-18 "TurnResult.usage empty via auto_send_turn" comment is
resolved by the foundation (emitter reads turn.usage() after stream exhaustion).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent eab5388 commit 734b298
2 files changed
Lines changed: 79 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
65 | 92 | | |
66 | 93 | | |
67 | 94 | | |
| |||
89 | 116 | | |
90 | 117 | | |
91 | 118 | | |
92 | | - | |
| 119 | + | |
| 120 | + | |
93 | 121 | | |
94 | 122 | | |
95 | 123 | | |
| |||
105 | 133 | | |
106 | 134 | | |
107 | 135 | | |
108 | | - | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
109 | 141 | | |
110 | 142 | | |
111 | 143 | | |
112 | 144 | | |
113 | 145 | | |
114 | | - | |
| 146 | + | |
115 | 147 | | |
116 | | - | |
117 | | - | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
118 | 151 | | |
119 | 152 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
171 | 212 | | |
172 | 213 | | |
173 | 214 | | |
| |||
0 commit comments