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 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
this step needs the editor
on desktop today; in the app (coming soon). save your spot and we'll bring you back here when you're ready.