Long conversations: trim, delete, summarize
Notebook· 03.03· 120–150 min· Lesson 29 of 129
The notebook opens in your lab, in a new tab. If your server is stopped, it starts first (a few seconds).
By the end you can
- Measure how many tokens a thread sends to the model on every turn, and why that number matters.
- Trim with
trim_messages, either transiently (only what the model sees) or permanently (the saved state). - Delete messages with
RemoveMessagewithout breaking tool-call pairs. - Summarize old history with
SummarizationMiddleware(trigger,keep,token_counter). - Compare the three strategies by tokens sent and by what the agent still remembers.
Before you start
Lesson 03.02 (checkpointers).
Python in this lesson
Python guideNew hereAny
