promptdojo_

Trace-driven debugging — turn a 4-hour panic into a 20-minute investigation — step 7 of 9

The chat history accumulates EVERY prior tool result across turns. The current code returns the full history every call. The trace shows tokens climbing turn-over-turn until the context fills with irrelevant chatter.

Fix line 8 so the assembled context only includes messages with age <= 2 (the most recent 2 turns). Older tool_result rows fall off the back.

Expected output:

3
The break is on line 13 — but read the whole snippet first.

full-screen editor opens — close anytime to keep reading.