Skip to content
Hameed's dev blog

Blog

Agentic AI Chapter 6: Agent State, Memory and Context Management

·2 min read·---
Agentic ai chapter 6 state memory and context.png
On this page

Part of the Agentic AI study series.

The model is stateless. It does not remember past calls by itself. The runtime maintains state and hands the model the relevant context at each step. Good state and context management means better decisions, fewer tool calls, and a more reliable agent.

Agentic AI Chapter 6: Agent State, Memory and Context Management, handwritten study notes

📊 Real-World Example: An Order Return With State

  1. The user asks where order #408-12345 is. The runtime stores the goal and order ID, and the agent calls get_order_status.
  2. The result says delivered on Oct 12. State now holds the order status.
  3. The user says "I want to return it". State holds the intent, so the agent knows which order "it" means and calls get_return_policy.
  4. The policy says returnable within 30 days, and the agent calls create_return.
  5. A return is created and the agent confirms the pickup date.

The user never repeated the order number. The runtime kept it.

🔴 CHECKPOINT: Remember

Memory typeWhat it storesLifespan
ConversationRecent messages, intent, important factsShort term (session)
WorkingIntermediate results, current plan, tool outputsShort term (iteration)
Long-termProfile, preferences, historyAcross sessions

What goes into context: system instructions, recent conversation history, relevant user context, and the current state.

Context strategies: recent window, summarization, filtering, retrieval (RAG), and selective tool results.

Persist: user profile and preferences, a summary of past orders, frequent questions. Do not persist: sensitive personal data such as full payment details, temporary tool results, unnecessary conversation details.

State is maintained by the runtime, not the model.

🛠️ From My Own Work

My project keeps a note that I handle all commits myself. That is long-term memory: it lives outside any one conversation and is read back at the start of the next. Another lesson in the same area: when I changed the active theme in a config file and nothing changed, the real value was stored in a database. State often lives somewhere other than where you first look.


← Previous: Tool Execution and Observability · Back to the series start · Next: Planning, Routing and Decisions →

Practical notes on product management, distributed systems, and AI—written from real engineering and product experience.