SignorCrypto note · AI
Context Engineering for AI Agents: A Practical Guide
How to curate tools, memory and runtime data for more reliable agent workflows

Context engineering is the practice of selecting and maintaining the information an AI agent receives while it works: instructions, tools, examples, retrieved data, conversation state and durable notes. The goal is not to fill a larger context window. It is to give the model the smallest high-signal set of information needed for the next decision, then update it as the task evolves.
For teams moving from chatbots to tool-using agents, this is a systems problem. Better prompts help, but reliability also depends on retrieval, memory, tool design, permissions, observability and human review.
What context engineering means
Prompt engineering asks how to write instructions. Context engineering asks: what configuration of context is most likely to produce the desired behaviour at this step? Anthropic defines context as the tokens included when an LLM samples a response, including system instructions, tools, external data and message history.
A useful principle is: keep stable rules stable, retrieve changing facts just in time, and persist only information worth recovering later.
Why more context is not always better
A long context window does not guarantee that an agent will use every detail correctly. Anthropic’s guidance describes a performance gradient often called context rot: as context grows, retrieval and long-range reasoning can become less precise.
Typical failures include instruction dilution, stale evidence, ambiguous tools and state loss when a long-running workflow reaches a new context window. Do not respond by adding instructions at random. Measure failures and change the context assembly: what was missing, misleading, too old or unnecessarily verbose?
The core layers of an agent’s context
Stable instructions and examples
State the role, authority, output contract and escalation rules in direct language. Keep policy separate from background information. Rules that must never be ambiguous belong in deterministic code or a tool policy, not only in prose. Use a small set of canonical examples for nuanced formats or review thresholds.
Tools as boundaries
A tool’s name, description, schema, error behaviour and output shape teach the model what it can do. Anthropic recommends tools with a distinct purpose, clear parameters and token-efficient responses.
Prefer a few narrow tools over one vague “do everything” function or many overlapping functions. Return only the fields needed for the next decision, with filtering or pagination for large results. Keep credentials and irreversible side effects behind the tool boundary.
Runtime retrieval
Pre-loading an entire knowledge base is convenient but often inefficient. A just-in-time strategy keeps lightweight references—document ids, file paths, queries or URLs—and loads relevant content only when the agent reaches that decision point.
This supports progressive disclosure: inspect a directory, filter records, open a relevant section and request more only when needed. The trade-off is latency and the need for good search tools and metadata. For company knowledge, store ownership, effective dates, scope and source status alongside content.
Working memory and durable state
Conversation history is working memory, not necessarily a durable record. Long-running agents need compaction, structured notes, external state for large files and logs, and checkpoints that survive a timeout or sandbox failure.
OpenAI’s April 2026 Agents SDK update adds configurable memory, sandbox-aware orchestration, filesystem tools and snapshotting/rehydration patterns for long-running work. The implementation is provider-specific; the architectural lesson is general: the harness should manage durable execution, while the model receives the slice of state relevant to its next step.
Governance and observability
Context can contain confidential documents, personal data, hidden instructions and tool results. Treat retrieval as a permissioned operation. Enforce access outside the model, minimise data passed into each step, and record which sources and tools influenced an output.
OpenTelemetry’s GenAI semantic conventions standardise recording of model calls and token usage, plus prompt, completion and tool content when explicitly enabled. Its May 2026 walkthrough notes that content capture is sensitive and not enabled by default in the example. Decide what to capture, where it may be stored and how long it should be retained.
For a broader practical starting point, the SignorCrypto Toolkit can complement this architecture checklist.
A practical company-agent pattern
Consider an internal agent answering: “What is the approved process for a delayed supplier shipment, and what should I do next?”
A bounded context assembly could:
- Load the stable role, audience and authority boundaries.
- Retrieve the current policy by owner, status and effective date.
- Retrieve only the shipment fields needed for the decision.
- Expose narrow tools: search policy, read shipment, draft notification and request approval.
- Produce a structured recommendation with source references and an uncertainty field.
- Validate the output and require human approval before sending a message or changing a record.
- Save the decision, evidence and unresolved question as durable task state.
The model is not asked to memorise the company. It is given an organised path to company knowledge and a bounded set of actions. If the policy is missing, conflicting or expired, the correct behaviour is escalation—not confident invention.
Context engineering vs. RAG
Retrieval-augmented generation (RAG) is one technique for supplying external information. Context engineering is the larger discipline that decides what belongs in context, when it should be retrieved, how it should be compressed, which tools can change the world and how the result is monitored.
| Question | RAG alone | Context engineering |
|---|---|---|
| Main focus | Retrieve relevant text | Curate the state for the next decision |
| Includes tools and permissions? | Not necessarily | Yes |
| Handles long-running state? | Only if designed around it | Explicitly |
| Main test | Was the right passage retrieved? | Did the agent use evidence and take a bounded action? |
A strong RAG component can still fail when the agent has stale instructions, ambiguous tools or excessive permissions. Choose retrieval methods by task, not by fashion.
Build-and-evaluate checklist
- Define one verifiable task and its acceptable outcome.
- Write the agent’s authority in one sentence.
- Separate stable instructions from changing business knowledge.
- Give every tool one clear purpose and a strict schema.
- Decide what is retrieved up front and what is loaded just in time.
- Define compaction, notes, checkpoints and recovery before testing long runs.
- Attach source references and freshness metadata to important answers.
- Log model, tool, latency, token and approval events with privacy controls.
- Test missing, stale, conflicting and adversarial context.
- Compare the agent with a simpler baseline before expanding autonomy.
NIST’s AI Agent Standards Initiative, updated in August 2026, identifies interoperable protocols, agent authentication and identity infrastructure, and security evaluations as active areas of standards work. Context quality is only one part of production readiness: identity and authority also need explicit design.
FAQ
Is context engineering just better prompt writing?
No. It also covers retrieval, tool schemas, examples, memory, state management, permissions and observability across the agent loop.
Should an agent receive the whole company knowledge base?
Usually not. Start with the smallest relevant, current and permission-checked set of information, then retrieve more when required.
What should an agent remember?
Persist information that will change a future decision: confirmed facts, decisions, constraints, source references, open questions and next actions. Avoid saving unverified speculation by default.
How do we know whether it helped?
Use representative tasks with verifiable outcomes. Track success, correction rate, source use, tool errors, latency, tokens, cost and escalation against a baseline.
Sources
- Anthropic: Effective context engineering for AI agents
- OpenAI: The next evolution of the Agents SDK
- NIST: AI Agent Standards Initiative
- OpenTelemetry: Inside the LLM Call—GenAI Observability
- Anthropic: Writing effective tools for AI agents
If your team needs an AI assistant that connects company knowledge to governed tools and workflows, explore Botchi.