What your agent actually sees: the six parts of its context

Before an AI agent answers, it reads a single block of text called its context. Six things go into it: its instructions, the descriptions of its tools, saved memory, the chat so far, documents it found, and results returned by tools. To the model, all of it is just text, so whatever you put there can shape, leak or confuse the answer.

Everyday analogy

A new employee's desk on their first morning: the job description, the list of systems they can log into, notes from the last person, the email thread, files from the shared drive and printouts from the database. If the desk contains the wrong files or a password on a sticky note, things go wrong.

Example

A support agent answers a refund question. Its instructions say refunds over $200 need approval; its memory still holds a customer's old address; RAG finds two versions of the refund policy (5–7 days and 30 days); and the order tool returns the full card number. Each of these can cause a wrong or unsafe reply.

SET UP BEFOREHANDADDED WHEN SOMEONE ASKS1. Instructionssystem prompt2. Toolstool descriptions3. Memorysaved facts4. The chatchat so far5. Found documentsRAG results6. Tool resultsdata from toolsContext windowall of it is just textto the model
Before an agent answers, six kinds of text are packed into its context window.
PartWhat it isWhat to check
1. InstructionsThe system prompt: role, rules, toneNever put passwords or API keys in it; it goes in with every message
2. ToolsEvery tool's name and descriptionOnly give tools the job needs; remove risky ones like "export all"
3. MemoryFacts saved from earlier chatsExpire old or wrong facts; decide what is kept and for how long
4. The chatThe conversation so farWhen the window fills, the oldest messages drop out; summarise long chats
5. Found documentsPassages retrieved by RAGRemove outdated versions so the agent doesn't see conflicting answers
6. Tool resultsData returned by tools and APIsReturn only the fields needed; mask card numbers and personal data

Security tip: because documents and tool results are also just text, hidden instructions inside them can try to hijack the agent (prompt injection). Treat everything the agent reads from outside as data, not as orders.

Try it yourself

About 15 min

Audit an agent's context

  1. Imagine a customer-support agent for an online shop.
  2. List what goes into each of the six parts of its context.
  3. For each part, write one risk and one fix (e.g. tool results: mask card numbers).

What you should see: A short checklist that would make a real agent safer and more accurate.

Use any free AI chatbot (ChatGPT, Claude, Gemini or Copilot). Never paste private or confidential information.

Build it for real · guided projectBuild a document Q&A assistant (RAG, no code)About 60 min · No coding needed · step by step
Test what you learned

Take a quick quiz, or look up any word in the glossary.