learning-it by example

Back to the video

Context Engineering: What to Keep From Chat History

I cut my chat to the last three turns and the model forgot all five facts.

Video #39 ยท AI agents and MCP

Steps in the video

  1. 0:00 I cut the chat and it forgot everything
  2. 0:26 The idea
  3. 1:03 Setup
  4. 1:21 A chat with five facts
  5. 1:48 Four strategies
  6. 2:13 The summary
  7. 2:26 Five questions
  8. 3:28 What this does not show
  9. 4:00 Mistakes to avoid
  10. 4:22 My take and next steps
  11. 4:47 Recap

Files

  • chat.py (30 lines)
  • compare.py (24 lines)
  • strategies.py (35 lines)

Download the code (zip)

Tested with

Python 3.12.15 | ollama==0.6.3

What this does not show

A made-up ten turn chat, one run, one small local model, five questions I wrote, scored by whether the reply contains a word. The summary is capped at 80 tokens and I did not check whether the cap or the model dropped the two facts. Ten turns is tiny, so this says nothing about long chats. Timings are from one laptop.

Sources

Learning IT by Example.