Commit 494fbe4
committed
feat(strategies): accumulate costUSD/cache tokens, render debate as judge verdict
Strategy compilers (sequential/parallel/debate/graph/review-loop/
hierarchical) were initialising totalUsage with only promptTokens/
completionTokens/totalTokens, so costUSD/cacheReadTokens/
cacheCreationTokens were always undefined on agency.execute() and
.stream() results. Hierarchical also discarded sub-agent usage entirely
(only the manager turn was reported).
- Replace accumulateCacheTokens with accumulateExtraUsage (forwards
costUSD too) and add buildAgentCallUsage so per-call records keep
cost + cache visibility down to AgentCallRecord.usage. Old name kept
as a deprecated alias.
- Hierarchical now sums sub-agent usage into a separate accumulator and
merges it with the manager's usage at the end.
- Widen AgentCallRecord.usage / CompiledStrategyStreamResult.usage /
AgencyStreamResult.usage to expose cacheReadTokens +
cacheCreationTokens (TokenUsage already had them; the strategy layer
was the gap).
Note for OpenAI: per-call cache tokens still come back undefined
because the API does not expose them at that layer. Anthropic returns
them and they will now propagate.
Debate strategy was producing a balanced essay because the per-turn
prompt told agents to "present your perspective" and the synthesis
prompt asked for "a single coherent answer". Reframed:
- Per-turn: opening statement (no hedging, take a side) for the first
agent; rebuttal turns (quote + attack the opposing claim, advance one
new point, ~150 word cap) for the rest.
- Synthesis: the agency-level model is the JUDGE, rendering a
structured verdict (Verdict / Why / strongest point per side / what
was conceded). Explicitly forbid "on the other hand" framing.
Updates the agency.test.ts expectations to assert the new prompt
shape.1 parent 404e328 commit 494fbe4
9 files changed
Lines changed: 405 additions & 167 deletions
File tree
- src/api
- runtime
- __tests__
- strategies
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
690 | 690 | | |
691 | 691 | | |
692 | 692 | | |
693 | | - | |
| 693 | + | |
694 | 694 | | |
695 | | - | |
696 | | - | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
697 | 698 | | |
698 | | - | |
| 699 | + | |
699 | 700 | | |
700 | | - | |
| 701 | + | |
701 | 702 | | |
702 | | - | |
| 703 | + | |
| 704 | + | |
703 | 705 | | |
704 | 706 | | |
705 | 707 | | |
| |||
764 | 766 | | |
765 | 767 | | |
766 | 768 | | |
767 | | - | |
| 769 | + | |
| 770 | + | |
768 | 771 | | |
769 | 772 | | |
770 | 773 | | |
771 | | - | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
772 | 777 | | |
773 | 778 | | |
774 | 779 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
38 | 61 | | |
39 | 62 | | |
40 | 63 | | |
| |||
78 | 101 | | |
79 | 102 | | |
80 | 103 | | |
81 | | - | |
| 104 | + | |
82 | 105 | | |
83 | 106 | | |
84 | 107 | | |
| |||
92 | 115 | | |
93 | 116 | | |
94 | 117 | | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
104 | 150 | | |
105 | 151 | | |
106 | 152 | | |
107 | 153 | | |
108 | 154 | | |
109 | 155 | | |
110 | | - | |
| 156 | + | |
111 | 157 | | |
112 | 158 | | |
113 | 159 | | |
| |||
119 | 165 | | |
120 | 166 | | |
121 | 167 | | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
| 168 | + | |
127 | 169 | | |
128 | 170 | | |
129 | 171 | | |
130 | 172 | | |
131 | 173 | | |
132 | 174 | | |
133 | | - | |
| 175 | + | |
134 | 176 | | |
135 | 177 | | |
136 | 178 | | |
137 | | - | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
138 | 184 | | |
139 | | - | |
| 185 | + | |
140 | 186 | | |
141 | 187 | | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
146 | 210 | | |
147 | 211 | | |
148 | 212 | | |
| |||
153 | 217 | | |
154 | 218 | | |
155 | 219 | | |
156 | | - | |
| 220 | + | |
157 | 221 | | |
158 | 222 | | |
159 | 223 | | |
160 | 224 | | |
161 | | - | |
| 225 | + | |
162 | 226 | | |
163 | 227 | | |
164 | 228 | | |
| |||
181 | 245 | | |
182 | 246 | | |
183 | 247 | | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
| 248 | + | |
190 | 249 | | |
191 | 250 | | |
192 | 251 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
39 | 63 | | |
40 | 64 | | |
41 | 65 | | |
| |||
116 | 140 | | |
117 | 141 | | |
118 | 142 | | |
119 | | - | |
| 143 | + | |
120 | 144 | | |
121 | 145 | | |
122 | 146 | | |
| |||
152 | 176 | | |
153 | 177 | | |
154 | 178 | | |
155 | | - | |
| 179 | + | |
156 | 180 | | |
157 | 181 | | |
158 | 182 | | |
| |||
162 | 186 | | |
163 | 187 | | |
164 | 188 | | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
| 189 | + | |
170 | 190 | | |
171 | 191 | | |
172 | 192 | | |
173 | 193 | | |
174 | 194 | | |
175 | 195 | | |
176 | | - | |
| 196 | + | |
177 | 197 | | |
178 | 198 | | |
179 | 199 | | |
| |||
190 | 210 | | |
191 | 211 | | |
192 | 212 | | |
193 | | - | |
| 213 | + | |
194 | 214 | | |
195 | 215 | | |
196 | 216 | | |
| |||
227 | 247 | | |
228 | 248 | | |
229 | 249 | | |
230 | | - | |
| 250 | + | |
231 | 251 | | |
232 | 252 | | |
233 | 253 | | |
234 | 254 | | |
235 | 255 | | |
236 | | - | |
| 256 | + | |
237 | 257 | | |
238 | 258 | | |
239 | 259 | | |
| |||
248 | 268 | | |
249 | 269 | | |
250 | 270 | | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
| 271 | + | |
257 | 272 | | |
258 | 273 | | |
259 | 274 | | |
260 | 275 | | |
261 | 276 | | |
262 | 277 | | |
263 | 278 | | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
| 279 | + | |
270 | 280 | | |
271 | 281 | | |
272 | 282 | | |
| |||
276 | 286 | | |
277 | 287 | | |
278 | 288 | | |
279 | | - | |
| 289 | + | |
280 | 290 | | |
281 | 291 | | |
282 | 292 | | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
287 | 297 | | |
288 | 298 | | |
289 | 299 | | |
| |||
0 commit comments