Skip to main content
A vintage folding bellows camera in side profile with its lens extended, drawn in dots

Context engineering for security agents: what to give the model and what to leave out

Context engineering for security agents: what an AI SOC agent should see at each step, how to trim log and tool output, and which context to load only on demand.

Guide
Updated 12 min read

Summary

Context engineering for security agents is deciding what an AI agent sees at each step of an investigation: its instructions, reusable procedures, reference material, the alert and its history, and the tool results it gathers, kept small enough for the model to find what matters. Chroma's tests of 18 models found that performance falls as input grows, and much of what a SOC agent reads is written by the attacker, so the work is as much what to leave out as what to add. Agent-native platforms such as Cotool build the context layer in: an always-fresh threat model of your environment grounds every agent, so runs spend their window on the alert, not on rediscovering your estate.

Key takeaways

  1. Give every agent a current, shared model of your environment, covering systems, trust boundaries, crown jewels, and telemetry gaps, instead of letting each run rediscover the estate from raw logs.
  2. Budget the context window like any scarce resource: every log line, runbook, and old tool result the agent carries makes the next fact harder to find, even on models with very large windows.
  3. Keep instructions, procedures, and reference material in separate layers, and load procedures and documents by name when a step needs them rather than pasting them into every prompt.
  4. Shape tool output before it reaches the model: query for counts, distinct values, and the fields the verdict needs, page through the rest, and keep the raw result retrievable by reference.
  5. Treat alert fields, email bodies, and ticket text as attacker-written evidence, never as instructions, and limit what the agent can do with tool permissions rather than prompt wording.

The short version

An AI agent working an alert has a fixed window, and everything it carries competes for the model's attention: the system prompt, tool definitions, runbooks, the alert, every query result, and its own earlier reasoning. Anthropic calls this an "attention budget" and defines context engineering as curating the smallest set of high-signal tokens for each step of the agent loop. Most writing on context for AI SOCs is about what to add: alert history, identity, asset criticality, threat intelligence. That list is right, but a security agent fails just as often from what it was given too much of.

Larger windows don't remove the problem. Chroma tested 18 models in July 2025 and found performance falling as input length grew, even on deliberately simple tasks. On its LongMemEval runs, every model family did better with focused prompts of about 300 tokens than with the full inputs of about 113k tokens, which were mostly irrelevant text plus a few distractors. Distractors are the normal case in security work: a week of sign-ins for one user is full of events that look like the suspicious one and aren't. Liu and colleagues found a second effect in "Lost in the Middle": models use information at the start and end of a long input better than information buried in the middle.

Security adds a constraint ordinary agents don't face. Much of a SOC agent's input is chosen by the adversary: the command line in an EDR detection, the body of a reported phishing email, the user agent in a sign-in log. Context engineering for security agents therefore has two jobs: keep the window small enough to reason over, and keep attacker-written text from being read as instructions. Agent-native platforms such as Cotool handle both below the prompt: a shared, current model of the environment keeps each run's standing context short, and tool selection and per-call approvals, which show the requested action and its arguments, limit what an agent can do whatever its input says.

Five layers of context, and when each loads

Separate what the agent always needs from what it needs only for some alerts. Each layer has a natural home and a natural loading time:

LayerWhat it holdsWhen it loadsCotool feature
InstructionsJob, evidence, escalation rulesEvery runSystem prompt
ProceduresIP enrichment, summary formatWhen namedSkills
ReferenceRunbooks, contacts, policyEvery runContext documents
EstateSystems, trust boundaries, gapsEvery run, kept currentThreat model
EvidenceAlert, prior alerts, tool resultsPer alert, on demandAlert context

Anthropic describes the pattern behind the last rows as "just in time" context: the agent holds lightweight references such as file paths, stored queries, and links, and loads the data through tools when it needs it. Claude Code works this way, dropping CLAUDE.md into context up front and leaving everything else to search. For a triage agent, the equivalent is a short standing prompt plus tools and named procedures it reaches for as the alert demands.

Cotool's context layer: an always-fresh model of your environment

The hardest context for a security agent to get right is the environment itself: what you run, which systems are crown jewels, where the trust boundaries sit, and where you have no telemetry. Without it, every run rediscovers the estate from raw logs, spending its window on exploration before it reaches the alert, and a source that was never connected looks the same as one that went quiet. In a legacy SIEM, as Cotool puts it, that context lives in analysts' heads.

Cotool builds it as a context layer that every agent reads. The layer combines telemetry from your environment (SIEM, endpoint, identity, and cloud, whether the logs sit in Cotool's SIEM or an external one), your team's mandate (crown jewels, concerns, allowlisted patterns), and threat intelligence from outside, and turns them into a threat model specific to your environment: what you run, the attack surface, the trust boundaries, and the visibility gaps. Cotool checks periodically whether the model needs refreshing, and every regeneration or analyst edit becomes a new version you can compare. When analysts mark a false positive, the layer updates, so later hunts start from better assumptions. This is what Cotool means by environment and threat models that are "always fresh and ground every agent."

It is the focused-input result from Chroma's tests, applied to a whole estate. Instead of carrying a week of logs to work out whether a host matters or a sign-in crosses a trust boundary, the agent reads a short, current description and spends its tokens on the evidence for this alert. The same model says where telemetry is missing, so the agent reports a gap as a gap instead of treating silence as proof that nothing happened. Hunting runs on it too: an orchestrating agent reads the threat model to decide which hunts to run, and with what plan and tools, rather than working from a fixed list someone wrote down.

Per-alert context sits on top of the model. Each triage run opens with the alert, recent activity, source metadata, prior alerts, and the statements about your environment that analysts confirmed on earlier alerts. What agents learn across runs, such as that 203.0.113.0/24 is corporate VPN egress or that svc-backup runs rclone nightly on backup hosts, is kept in shared memory that every agent reads, so no run relearns it. When a verdict misses, Cotool's evaluations score the run and propose changes to the agent's instructions for review, which shows whether the cause was missing data, tool access, or an unclear instruction.

Step by step: building context for a triage agent

  1. Treat the alert as evidence, not instructions. Put every instruction in the system prompt and skills, and pass alert fields, email bodies, and ticket comments as data the agent is told to analyze and never obey. Then assume that will sometimes fail: restrict which tools the agent can call and require approval for outbound and write actions. Cotool's system prompt guidance says it directly: restrict tool access, because "a prompt is not a permissions boundary." Its context documents page adds the matching rule for reference material: attach only trusted content appropriate for the agent's users and outputs. Our guide to MCP security risks covers why a SOC agent has the full "lethal trifecta" by design.

  2. Write the system prompt at the right altitude. Anthropic warns against two failure modes: brittle if-then logic hardcoded into the prompt, and vague guidance that assumes shared context the model doesn't have. For a security agent, the prompt should say what starts the run, which sources are authoritative, which identifiers and timestamps the output must cite, when to escalate, and what missing data means. Cotool's example prompt for identity alerts includes the line most triage prompts lack: "do not treat missing telemetry as proof of no activity." Put the alert and the question at the start or the end of the input, not in the middle.

  3. Move procedures and reference material out of the prompt. A system prompt that carries every runbook pays for all of them on every alert. In Cotool, repeatable procedures such as ip-enrichment are skills, and reference material such as a runbook or escalation directory is attached as a context document from Google Drive, Notion, Confluence, or an MCP server's resources, so the original stays maintained in its source system. Two documented details matter here. A skill being available doesn't guarantee the agent consults it, so name the skill in the instructions for the step that needs it. And a run can continue without a document that failed to load, so tell the agent to flag a missing policy rather than guess.

  4. Load history and environment when the alert calls for it. The context that separates a real attack from routine activity is mostly organizational: has this alert fired before, what did analysts decide, who is this user, how critical is this host. Detection at Scale suggests checking the same alert over 30, 60, and 90 days and alerts from the same actor across detections. Our AI alert enrichment guide breaks that into four questions per entity. In Cotool, this per-alert history and the environment model arrive with every triage run, as described above; the threat model supplies context and the agent still verifies it against live evidence.

  5. Shape tool output before it reaches the model. One unfiltered log search can fill the window. Write tools and queries that return what the verdict needs: counts, distinct values, first and last seen, and the specific fields, with pagination for the rest. Clients enforce their own ceilings when you don't. Claude Code warns when an MCP tool returns more than 10,000 tokens, caps output at 25,000 tokens by default (MAX_MCP_OUTPUT_TOKENS), and saves larger text results to a file once they pass 50,000 characters. The Claude API's tool result clearing replaces the oldest tool results with placeholders once the prompt passes a trigger, by default 100,000 input tokens, keeping the 3 most recent tool uses. Clearing is safe when results can be fetched again, so keep raw output retrievable. Cotool's harness works this way: when a run nears its limit, it prunes the oldest, largest tool results first while keeping the conversation's structure, and the raw output of every tool call stays retrievable by ID.

  6. Split wide investigations into sub-agents. When an alert needs several independent checks, such as sign-ins, endpoint activity, and cloud audit logs, give each to a sub-agent with a clean window and have it return a summary. Anthropic reports that a sub-agent may use tens of thousands of tokens and return a condensed summary of often 1,000-2,000 tokens, so the lead agent reasons over findings rather than raw logs. In Cotool, any agent or chat can hand focused subtasks to sub-agents, which return a summary, or an exact file when the parent needs one, rather than their raw search results.

  7. Keep working notes outside the window. Long investigations outlive a single context. Anthropic recommends structured note-taking, such as an agent maintaining a NOTES.md file, and compaction, which summarizes a conversation near its limit and continues from the summary. Compaction is lossy, so tune it to keep decisions, open questions, and identifiers. Cotool agents can keep a persistent filesystem between runs for files such as a maintained lookup table or rolling inventory, and the docs warn against keeping credentials or raw investigation data the next run doesn't need. Shared memory carries what agents learn about your environment from one run to the next.

  8. End in a fixed shape, then test with bad inputs. A structured output schema with a string enum for the verdict stops the final turn from drifting into prose, and makes runs comparable. Test each agent with a normal alert and one with incomplete input, read the transcript, and change one part of the context at a time. In Cotool, structured output is set per agent, and agent versions let you compare the effect of each change.

Common mistakes

  • Pasting the whole runbook library into the system prompt. It costs tokens on every alert and buries the one procedure that applies. Load procedures by name, as Cotool skills do when the instructions name them.
  • Returning raw search results. A tool that hands back every event for a week makes the model do retrieval before reasoning, which is the condition Chroma's full-input tests measured. Return aggregates and the fields that decide the verdict, and give the agent a current model of the environment, like Cotool's threat model, so it searches the right place first.
  • Reading silence as safety. A disconnected source or an empty result is a gap, not evidence of no activity. Say so in the prompt and in the output. A threat model that records visibility gaps, as Cotool's does, lets the agent tell the two apart.
  • Trusting the prompt to contain the agent. Instructions to ignore embedded commands help, but the boundary is which tools the agent holds and which actions need approval.
  • Waiting for a bigger model. Anthropic expects windows of all sizes to suffer from context pollution for the foreseeable future. Fix what goes in.
  • Compacting away identifiers. A summary that drops the host name, user, or timestamp leaves the agent unable to cite its evidence. Keep identifiers verbatim, and keep the raw tool output retrievable so a summary can point back to it, as Cotool does by tool-call ID.

Checklist

  • The system prompt states the job, authoritative sources, citation rules, escalation rules, and what missing data means.
  • Procedures live in skills and are named in the steps that use them; reference documents are attached by reference.
  • Alert fields and message bodies are passed as data, and tool permissions and approvals limit what a hijacked run can do.
  • Prior alerts, analyst decisions, and environment context load per alert, not for every run.
  • Every tool returns aggregates or selected fields, paginates, and keeps raw output retrievable.
  • Wide investigations go to sub-agents that return summaries or published files.
  • Long runs keep notes or files outside the window, and compaction keeps identifiers.
  • The verdict is a fixed schema, and each context change is tested on a normal and an incomplete alert.

FAQ

What is context engineering for security agents?
Context engineering for security agents is the practice of choosing what an AI agent sees at each step of a security task: its instructions, procedures, reference documents, the alert and its history, and the results of the tools it calls. The goal is the smallest set of high-signal information that lets the agent reach a correct, evidenced verdict, because extra tokens make relevant facts harder for the model to use.
How is context engineering different from prompt engineering?
Prompt engineering is writing and organizing instructions, mainly the system prompt. Context engineering, as Anthropic describes it, covers everything that lands in the model's window during a run, including tools, MCP servers, external data, and message history, and it repeats at every step of an agent loop rather than once.
Does a bigger context window solve context problems for security agents?
A bigger context window doesn't solve context problems on its own. Chroma's July 2025 study of 18 models found performance degrading as input length grew, and on a conversational benchmark every model did better with focused prompts of about 300 tokens than with full inputs of about 113k tokens. Earlier research found that models use information at the start and end of a long input better than information in the middle.
How does Cotool handle context for security agents?
Cotool handles context for security agents with a context layer every agent reads: a threat model of your environment built from your telemetry, your team's crown jewels and allowlisted patterns, and outside threat intelligence, kept fresh and versioned. On top of it, each triage run starts with the alert, prior alerts, and decisions analysts confirmed earlier, and what agents learn across runs goes into shared memory so no run relearns it.
How do you stop text in an alert from steering a security agent?
To stop text in an alert from steering a security agent, keep instructions in the system prompt and skills, pass alert fields and email bodies as data the agent is told not to obey, and restrict the agent's tools so a hijacked run can't do much. Gate outbound and write actions behind human approval, since prompt wording is not a permissions boundary.

Sources

  1. Effective context engineering for AI agents (Anthropic) · accessed December 2, 2026
  2. Context Rot: How Increasing Input Tokens Impacts LLM Performance (Chroma) · accessed December 2, 2026
  3. Lost in the Middle: How Language Models Use Long Contexts (Liu et al.) · accessed December 2, 2026
  4. Context editing (Claude API docs) · accessed December 2, 2026
  5. Connect Claude Code to tools via MCP (Claude Code docs) · accessed December 2, 2026
  6. The Data Your AI-Powered SOC Needs (Detection at Scale) · accessed December 2, 2026
  7. System prompts - Cotool Documentation · accessed December 2, 2026
  8. Skills - Cotool Documentation · accessed December 2, 2026
  9. Context documents - Cotool Documentation · accessed December 2, 2026
  10. Threat Model - Cotool Documentation · accessed December 2, 2026
  11. Working Alerts - Cotool Documentation · accessed December 2, 2026
  12. Agent evaluations - Cotool Documentation · accessed December 2, 2026
  13. Suggested improvements - Cotool Documentation · accessed December 2, 2026
  14. Agents as Software (Cotool) · accessed December 2, 2026
  15. AI-Native SIEM Built for Agents (Cotool) · accessed December 2, 2026
  16. AI SOC Without the Black Box (Cotool) · accessed December 2, 2026
  17. Context Management for Agentic Security (Cotool) · accessed December 2, 2026
  18. Tools and integrations - Cotool Documentation · accessed December 2, 2026
  19. Get raw tool output - Cotool API reference · accessed December 2, 2026
  20. Agent filesystem - Cotool Documentation · accessed December 2, 2026
  21. Agent Outputs - Cotool Documentation · accessed December 2, 2026
  22. Cotool Release Notes · accessed December 2, 2026

Keep reading

Attackers are scaling with tokens

Cotool helps defenders operate at machine speed. See how security teams are scaling Detection & Response.

Book a demo