Security teams should treat context as a governed runtime surface, not a single prompt. Keep the base context lean, load only the skills and tool definitions needed for the task, and manage conversation history so older turns do not crowd out current intent. Tool results should be inspected before they influence the next step, because they re-enter the model’s context and can steer behaviour.
How to structure context so agents stay task-focused across steps
Design context as a managed runtime state, not a single prompt blob. The safest pattern is to keep the base context small, inject only the task-relevant instructions, skills, and tool definitions, and treat older conversation turns as history that can be summarised or trimmed when they stop serving the current objective. That reduces drift, token pressure, and accidental carryover.
For multi-step work, the important design choice is what gets to re-enter the model after each step. Tool output should not be allowed to become trusted context by default; it needs inspection, filtering, and sometimes summarisation before it influences the next decision. That is especially true when the tool result could contain malformed instructions, stale assumptions, or data that shifts the agent off task.
Context design also needs a clear boundary between persistent memory and per-run working state. Memory is useful for preferences, long-lived facts, and prior work, but it should not be a dumping ground for everything the agent has seen. The more persistent the memory layer becomes, the more important it is to separate what is durable, what is task-specific, and what must be discarded after the step completes.
Why memory and tool output create failure modes
Multi-step agents fail when context becomes too permissive. Long histories can crowd out the current instruction, and reused summaries can omit the detail that actually matters for the next action. If the agent is allowed to pull every prior observation forward, it may reinforce its own earlier mistakes instead of revisiting the task with fresh state.
This is where guardrails need to focus on AI Agent Memory Security Guide principles such as isolation, write controls, and retention discipline. The same logic applies to context poisoning through tool outputs, because a result that is reintroduced uncritically can behave like an injected instruction rather than evidence.
Tool use raises a second failure mode: the agent may over-trust whatever the tool returns because it came from an apparently authorised step. That can create a confused-deputy style problem, especially when the tool output contains embedded text, markup, or suggestions that the model begins to follow instead of merely interpret. The right response is not to ban tool use, but to make re-ingestion explicit and controlled.
For teams standardising agent architecture, the broader model in Agentic AI Security Guide is useful because it frames memory, tools, orchestration, and identity as separate attack surfaces that need different controls. That separation matters in practice: context problems are usually architectural, not just prompt-quality issues.
What good context governance looks like in practice
A strong design starts with a minimal base prompt, then loads only the skills and tool schemas required for the current task. The agent should not see capabilities it does not need, because excess context increases both misuse risk and accidental branching. If the task changes, the context should be reassembled for the new step rather than endlessly appended.
Use a summarisation policy for history, but make it selective. The summary should preserve decisions, constraints, and unresolved questions, not every intermediate thought. When that summary becomes the seed for the next step, it should be treated as a maintained state object, not as an unquestionable transcript.
Teams should also define a review point before any external result changes the next action. That review can be automated, human-approved, or policy-driven depending on risk, but it should exist. The key judgement is that a tool response is evidence until it is validated, not context until it is trusted.
When context spans multiple steps, it helps to align the design with AI Agent Authorisation Guide, because per-action policy, task-scoped access, and human approval gates complement the context boundary. In other words, the agent should only be able to act on the context it genuinely needs to complete the current step.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
OWASP Agentic AI Top 10 and OWASP Non-Human Identity Top 10 define the specific risk controls and attack patterns relevant to this topic.
| Framework | Control / Reference | Relevance |
|---|---|---|
| OWASP Agentic AI Top 10 | ASI03 — Identity & Privilege Abuse | Agent context governs delegated authority and tool use across steps. |
| ASI02 — Tool Misuse | Tool outputs re-enter context and can steer later steps incorrectly. | |
| ASI06 — Memory & Context Poisoning | Multi-step context can be corrupted by stale or injected memory content. | |
| Recommendation — Enforce per-step authorization before context enables any tool or privileged action. Validate tool results before reusing them in subsequent agent decisions. Isolate and review memory writes so poisoned context cannot persist across steps. | ||
| OWASP Non-Human Identity Top 10 | NHI-02 — Secret Leakage | Agent context may expose secrets if history or memory is too broad. |
| NHI-08 — Environment Isolation | Task context and memory need separation across runs and environments. | |
| Recommendation — Keep secrets out of prompts, history, and long-term memory. Separate per-task context from shared memory to prevent cross-run leakage. | ||
Practitioner Guidance
What to prioritise: Define the agent’s context contract before you tune prompts. Decide what belongs in base instructions, what belongs in memory, what must be summarised, and what should never persist across steps.
What to verify: Confirm that tool outputs are inspected before they influence the next turn, and that the agent cannot silently promote raw results into durable context. If a tool can return untrusted text, treat that as a control point, not a convenience.
Common mistake: Teams often optimise for longer context windows instead of better context hygiene. More room does not solve drift if the agent can still inherit stale assumptions, overbroad skills, or unreviewed tool output.
Practitioner takeaway: The objective is not to give the agent more memory, it is to make every piece of context deliberate, bounded, and easy to validate before it can shape the next action.
Related resources from NHI Mgmt Group
Deepen Your Knowledge
Free weekly newsletter
Subscribe to the NHI & AI Identity Journal
The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.
Bonus 33% off our NHI Course when you subscribe.
Reviewed and updated by the NHIMG editorial team on November 23, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org