π° Originally published on Securityelites β AI Red Team Education β the canonical, fully-updated version of this article.
π€ AI AGENTS FOR BEGINNERS Β FREE
How AI Agents Work β Day 2 of 5 Β Β·Β 40% complete
I once watched an AI agent fail at a task it had completed perfectly just twenty minutes earlier. The goal was the same. The tools were the same. Even the model was the same. So what went wrong?
The problem turned out to be surprisingly simple: the conversation had become so long that the agentβs context window was filling up. Somewhere along the way, the information about what it had already done was pushed out. The agent wasnβt deliberately ignoring its previous work β it had effectively forgotten it. It started repeating steps that were already finished.
That experience made one thing very clear to me: if you want to understand why AI agents sometimes behave brilliantly and sometimes seem to lose the plot, you need to understand memory.
Memory is what helps an agent keep track of a long-running task, remember useful information, and maintain some sense of continuity. But thereβs another side to it that doesnβt get nearly enough attention: memory can also become an attack surface. If an attacker can influence what an agent remembers, retrieves, or trusts, the consequences can be much more serious than a simple wrong answer.
And then thereβs MCP β the Model Context Protocol. MCP changed the conversation around agent memory and tool use by giving AI systems a standard way to connect with external data and tools instead of keeping everything trapped inside a single conversation window.
In this lesson, weβre going inside the agent loop. Weβll look at the different types of memory, how agents decide which tools to use, how they break complex goals into smaller steps, and what MCP actually does under the hood. No marketing language β just the architecture and the ideas you need to understand how modern AI agents really work.
π― What Youβll Understand After Day 2
The three types of agent memory and when each is used
Why context window limits are the single biggest constraint on agent reliability
How agents select and execute tools β and what happens when tools fail
What MCP is, why it matters, and what it replaced
How modern agents plan β chain-of-thought, tree-of-thought, and ReAct
β± 24 min read Β· 3 exercises Β· Browser needed π Before You Start:
- Completed Day 1: What Is an AI Agent?
- Remember: the four-phase loop, the five agent types, the autonomy-risk relationship
How AI Agents Work β Day 2 of 5
- The Three Types of Agent Memory
- The Context Window β The Agentβs Working Memory Limit
- How Tools Work β Selection, Execution, and Failure
- What MCP Actually Is β And What It Changed
- How Agents Plan β Chain-of-Thought, ReAct, and Tree-of-Thought
- Putting It Together β A Full Agent Architecture
- Questions and Answers
Day 1 established what an agent is and why the loop matters. Today goes inside the loop β the mechanisms that make it work, the constraints that make it fail, and the protocol that made 2026βs agent boom possible. The DNS lookup tool on SecurityElites illustrates the tool selection concept neatly: an agent given a domain investigation task would call that tool as one action in its loop β perceive the domain, plan a lookup, execute the tool call, observe the result. Today youβll understand exactly how that decision to call a specific tool gets made.
The Three Types of Agent Memory
Memory is what allows an agent to maintain coherence across a task longer than a single exchange. Without memory, every loop iteration would start from scratch. With memory, the agent can track what itβs done, what it found, what went wrong, and what it still needs to do. There are three distinct types of memory in agent systems, and understanding the difference between them is essential for understanding why agents behave the way they do.
Type 1 β In-Context Memory. This is the agentβs working memory β everything currently in the conversation window. The original instruction, every tool call made so far, every result received, every observation noted. In-context memory is fast, immediately accessible, and directly influences every planning decision. Itβs also strictly limited by the modelβs context window. When the context fills up, older information gets pushed out. This is why long tasks can cause agents to βforgetβ earlier steps β the records of those steps have been pushed out of the working memory.
My rule for in-context memory: itβs reliable for tasks that complete in under thirty to forty loop iterations for current frontier models. For longer tasks, you need external memory.
Type 2 β External Memory. Storage outside the conversation window that the agent can explicitly read from and write to. This might be a database, a vector store (for semantic search over past information), a file system, or a key-value store. The agent reads external memory by making a tool call: βretrieve notes about this project,β βsearch the knowledge base for previous findings,β βread the saved state from yesterdayβs session.β External memory removes the context window constraint β an agent can maintain coherent state across tasks that take days or weeks if itβs properly writing and reading external memory at each loop iteration.
π Read the complete guide on Securityelites β AI Red Team Education
This article continues with deeper technical detail, screenshots, code samples, and an interactive lab walk-through. Read the full article on Securityelites β AI Red Team Education β
This article was originally written and published by the Securityelites β AI Red Team Education team. For more cybersecurity tutorials, ethical hacking guides, and CTF walk-throughs, visit Securityelites β AI Red Team Education.

Top comments (0)