Commit f0bbcde
committed
fix: prevent duplicate tool calls with full conversation history dedup (#154)
Three changes to eliminate wasted AI credits from duplicate tool call loops:
1. validateToolCall() now scans ALL previous tool calls in conversation
history, not just the most recent one. Catches non-consecutive
duplicates (e.g. upsert_event → other tool → upsert_event again).
2. Break out of tool call foreach when conversation is complete.
Multi-handler safe: only breaks when ALL configured handlers fired.
3. Stronger duplicate rejection message that explicitly tells the AI
not to call skip_item as a follow-up to a rejected duplicate.
Impact: ~2,554 jobs (30% of agent_skipped) followed a pattern where
the AI called upsert_event, got blocked on retry, then called skip_item
with a verbose duplicate explanation. Each burned ~36k tokens for zero
value (~93M tokens total waste).1 parent d8bc06c commit f0bbcde
2 files changed
Lines changed: 25 additions & 26 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
330 | 330 | | |
331 | 331 | | |
332 | 332 | | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
333 | 342 | | |
334 | 343 | | |
335 | 344 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
282 | 282 | | |
283 | 283 | | |
284 | 284 | | |
285 | | - | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
286 | 292 | | |
287 | 293 | | |
288 | 294 | | |
| |||
297 | 303 | | |
298 | 304 | | |
299 | 305 | | |
300 | | - | |
| 306 | + | |
301 | 307 | | |
302 | 308 | | |
303 | 309 | | |
| |||
316 | 322 | | |
317 | 323 | | |
318 | 324 | | |
319 | | - | |
320 | | - | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
342 | 332 | | |
343 | 333 | | |
344 | 334 | | |
| |||
418 | 408 | | |
419 | 409 | | |
420 | 410 | | |
421 | | - | |
| 411 | + | |
422 | 412 | | |
423 | 413 | | |
424 | 414 | | |
| |||
0 commit comments