
Agents in 60 lines of python : Part 4
Conversation = Messages Array Lesson 4 of 9 — A Tour of Agents The entire AI agent stack in 60 lines of Python. Last lesson's agent could loop — call a tool, check the result, call again. But ask it what you said two messages ago. It has no idea. Every call started fresh. The fix is one line of code. The problem In Lesson 3, the messages array lived inside the function. Every call created a new one. When the function returned, the array was gone. No history. No memory. This is why ChatGPT remembers your conversation — and why "New Chat" forgets. Same mechanism. One array. The fix: make it global Move the messages array outside the function. That's it. Now every call to agent() reads and writes to the same list. The conversation persists across calls. The LLM sees the full history every time it thinks. The code conversation = [ { " role " : " system " , " content " : " You have tools: add(a,b) and upper(text). Use them when needed. " }, ] One list. Initialized once with a system prompt.
Continue reading on Dev.to Python
Opens in a new tab

![[Learning notes and hw] getting started with R-cnn: Manually implementing Intersection over Union (IoU)](/_next/image?url=https%3A%2F%2Fmedia2.dev.to%2Fdynamic%2Fimage%2Fwidth%3D800%252Cheight%3D%252Cfit%3Dscale-down%252Cgravity%3Dauto%252Cformat%3Dauto%2Fhttps%253A%252F%252Fdev-to-uploads.s3.amazonaws.com%252Fuploads%252Farticles%252Favit2emoxc0g68e5ltqj.jpg&w=1200&q=75)
