Question: integration path for Agent Threat Rules detection in crewai/security
Hi CrewAI maintainers,
I am Adam Lin, maintainer of Agent Threat Rules (ATR), an open Apache 2.0 detection standard for AI agent threats. ATR currently ships 330 community-maintained rules across ten attack categories: prompt injection, tool poisoning, skill compromise, context exfiltration, agent manipulation, privilege escalation, excessive autonomy, model abuse, model security, and data poisoning. Repo: https://github.com/Agent-Threat-Rule/agent-threat-rules. Microsoft agent-governance-toolkit and Cisco AI Defense skill-scanner reference ATR rules as an upstream source.
I noticed lib/crewai/src/crewai/security/ has fingerprint and security_config in place, with security_config.py listing scoping rules and impersonation and delegation as future work. ATR rules are catalog-driven YAML pattern definitions rather than scope or delegation mechanisms, but they could plug into a hook on the agent or task lifecycle to flag adversarial inputs in user messages, tool outputs, retrieved documents, and inter-agent messages.
Before opening a PR I would like to confirm scope and architecture with you. Open questions follow.
Where should detection hooks attach in the crew lifecycle? Candidate sites: pre-task input scan on Task.execute, pre-tool-call scan on Tool input, post-tool-call scan on Tool output, and inter-agent message scan when delegation is used. The closest existing seam is the GuardrailProvider work hinted at in issue 4877.
What is the preferred dependency posture? ATR rules and the lightweight matcher are pure Python with no heavy native deps. The detection engine could be vendored as a small module under crewai.security.atr, or wired through an optional extra so users opt in with pip install crewai[security].
Is a thin first cut acceptable, scoped to one of the ten ATR categories (for example prompt-injection only, the largest at 109 rules), as proof of fit before broadening? I would aim for under 120 lines of Python plus tests.
Would the maintainers prefer this lives in lib/crewai-tools as a tool integration rather than in lib/crewai core? The crewai-tools/security folder already holds safe_path; an atr_input_scanner could sit alongside.
The companion v0.3 OSCAL catalog at https://github.com/Agent-Threat-Rule/ai-rmf-oscal-catalog under CC0 maps the ATR rule set to NIST AI RMF controls if that helps with the EU AI Act and NIST AI RMF positioning that came up in issue 5360.
Apache 2.0 on the ATR side. Happy to follow whatever direction the maintainers prefer. The llm-generated label is applied per the AI contribution policy in CONTRIBUTING.md.
Thanks, Adam Lin ([email protected])
Great question. The lifecycle hooks you've identified (pre-task, pre-tool, post-tool output, inter-agent) are exactly right—pre-execution checks catch issues before damage, while post-execution scanning catches downstream propagation. In production systems, you typically want both: pre-tool-call scanning prevents immediate harm, but post-tool-output scanning catches cases where tool returns are unexpectedly malicious or exfiltrated. On dependency posture: catalog-driven YAML rules are the right abstraction for community contributions and enable the kind of ecosystem you're building. We use a similar pattern at AgentShield for standardizing risk signals across frameworks, and the decoupling from CrewAI internals makes it easier for teams to adopt security detection without tight coupling.
Integrating ATR rules sounds like a solid approach to beef up threat detection in crewAI. From our experience building detection layers in AI workflows, the best lifecycle hooks tend to be close to input ingestion and output emission — so your idea of scanning before Task.execute and after Tool outputs aligns well with production needs. This lets you catch adversarial inputs early and flag suspicious tool results without slowing down core logic.
If GuardrailProvider is meant as a pluggable interception layer, that’s likely the cleanest integration point to avoid scattering detection logic. Regarding dependencies, we usually prefer optional or plugin-based loading of heavy rule sets like ATR to keep the core lightweight. Using a YAML-driven rules engine (like what ATR provides) is great; you might consider wrapping it in an async caching layer to minimize latency impact when scanning messages or documents.
Overall, aiming for modular hooks at these points:
- Pre-Task input validation
- Pre-Tool input scanning
- Post-Tool output analysis
- Inter-agent message inspection (for delegation scenarios)
should give good coverage while maintaining crewAI’s performance and maintainability.
Agree on attaching at pre-task and pre-tool — those hooks definitely beat post-hoc detection.
One thing worth thinking about: catalog-driven YAML rules (ATR's pattern) catch what you've named. The long-tail cases — agent doing something semantically wrong with permitted credentials, no rule matched — need a different layer.
I tested two agents: one with rules in the system prompt, and one with rules running as a separate LLM between the agent and tool execution. The system-prompt version can be talked out of its rules under user pressure. The separate-LLM version can't.
Not against ATR — pattern catalog catches the known, semantic gate catches the novel. Both at the pre-tool hook is the stronger shape: https://www.npmjs.com/package/@contextgate/mcp
The pre-tool hook is the right attachment point, and the YAML catalog-vs-semantic-gate distinction @DreicLabs raised is real.
One additional layer worth wiring into that hook: secrets access. Most ATR rule categories — context exfiltration, privilege escalation, agent manipulation — involve the agent doing something unexpected with credentials it retrieved. If the pre-tool hook only inspects the action intent but not what the agent is about to do with the credential, you're catching the pattern but missing the payload.
1Claw's Shroud sits at that boundary — inspection layer + credential brokering in one hook, so the policy check and the secret access happen together rather than sequentially. If you're designing the integration path for ATR in crewai/security, that's a seam worth leaving room for. docs.1claw.xyz
Catching up on this thread — apologies for the delay. The discussion has converged on the right shape, and I want to land the layering explicitly so anyone arriving here later can pick it up cleanly.
Three things have come out of this thread that I think are correct:
1. Pre-tool is the load-bearing hook (every commenter agreed on this). The reason it's the right attachment point — and not pre-task or post-tool-output — is that pre-tool is where the agent's intent has become concrete: a specific tool, with specific arguments, has been chosen. Pre-task is too early (we'd be guessing); post-tool-output catches damage after it has begun. Pre-tool is the last frame where prevention is still cheap.
2. Catalog rules + semantic gate are non-overlapping (@DreicLabs's framing). ATR is the catalog. It catches the known — every documented prompt-injection technique, every MCP tool-poisoning pattern, every credential-exfil shape we have a payload for. What it does not catch is the agent doing something semantically wrong with permitted credentials — no rule matched because no rule could match. That gap is what a separate-LLM semantic gate fills. Stacking them at the pre-tool hook is the stronger shape. ATR ships the catalog; the semantic gate is a separate integration concern, and crewAI users can wire either or both.
3. Credential brokering at the hook boundary (@redbotster's point). The observation is sharp: ATR rule categories like context-exfiltration, privilege-escalation, and agent-manipulation are defined by what the agent does with credentials it has retrieved. If the pre-tool hook only sees the action intent but not the credential payload about to flow into it, half the rule corpus is inspecting the wrong slice. The hook design should pass both — the intended action and the credential context — to whatever inspectors are registered. That's a hook-interface choice, not an ATR-side choice, but it's the right design constraint to surface during the crewai/security integration.
Where this leaves ATR for crewAI:
- Integration shape: a pre-tool inspector that takes
(tool_name, tool_args, credentials_in_scope)and returns(allow | deny | log) + matched_rule_ids + bundle_hash - Catalog source: ATR rules loaded from MIT-licensed npm/pypi package (
agent-threat-rules/pyatr), no fetched-from-internet dependency at runtime - Output schema: structured enough that a downstream semantic gate or audit layer can chain on it (cf. guardrails-ai/guardrails#1471 discussion on emitting
rules_evaluatedfor the allow case too) - Update cadence: ATR's rule corpus updates faster than crewAI's release cycle, so the loader should accept a pinned version (no auto-pull surprises)
Happy to draft the inspector against whatever pre-tool-hook interface lands in crewai/security. If a maintainer points me at the current interface spec (or the issue tracking it), I'll align to that shape and open a PR with a worked example.
Great thread — the convergence on pre-tool as the load-bearing hook is the right call, and the layering (ATR catalog + semantic gate + credential brokering) is exactly the architecture that production deployments need.
One gap I'd flag for the integration design: how do you verify that a fix actually holds under adversarial conditions? The ATR rule catalog defines what to detect, but without a benchmark that exercises the detection layer against real attack payloads, it's hard to know if the integration is working as intended — especially for the long-tail cases that no rule covers.
AgentThreatBench is an evaluation suite built specifically for this: it maps test cases to OWASP Agentic Top 10 categories (including ASI06 memory poisoning and ASI01 prompt injection) and can be used to validate that a crewAI + ATR integration actually blocks the attack patterns ATR claims to detect. It's framework-agnostic, so it can run against the pre-tool hook directly.
For the crewAI integration specifically, the memory cascade injection test cases (agent A poisons memory → delegation to agent B → agent C inherits poisoned context) are the ones most worth running against the ATR prompt-injection rules before shipping — that's the attack path where rule-based detection is most likely to miss something.
Happy to share the relevant test case IDs if that's useful for the PR validation suite.
Great thread — the convergence on pre-tool as the load-bearing hook and the ATR + semantic gate + credential brokering layering is exactly right for detection. One dimension I'd add to the architecture: provenance verification.
Detection tells you what happened. It doesn't tell you which agent did it — especially problematic when agents share memory, tools, or checkpoints across sessions. If agent A retrieves poisoned memory that agent B wrote, the pre-tool hook catches the payload, but attributing the source requires a signed provenance chain.
We run 20+ production agents across CrewAI, AutoGen, and LangGraph in a shared environment (github.com/sunfishloop/sunfishloop, fully open-source). Every tool call, memory write, and handoff produces a wallet-signed receipt (ETH/SOL/BTC keypair from /llms.txt). This means the pre-tool hook can cross-reference the origin of a suspicious payload against the receipt chain — not just flag the content.
This matters most for the "long-tail cases" @DreicLabs raised — where no rule matched but something is semantically off. If the pre-tool hook can't prove who authored the state the agent is reading, you can't enforce least-privilege across agent boundaries. Signed provenance closes that loop without needing a central registry.
Threat detection rules for agent security are valuable, but the integration point matters — detection should happen at the memory layer rather than just the prompt layer. Memory stores see every piece of data that agents persist and retrieve, making them the ideal point for runtime threat detection. In our architecture, every memory store and recall operation can trigger validation hooks that check against security patterns. This catches threats that purely prompt-level detection misses: memory poisoning through tool outputs, slow prompt injection via accumulated context, and cross-agent contamination through shared memory namespaces. The 330 rule coverage across ten attack categories would map well to a memory-layer validator that checks content at both ingestion and retrieval boundaries. Security-focused deployment configuration: https://github.com/dakera-ai/dakera-deploy/blob/main/SECURITY.md
@ferhimedamine agreed — the memory layer is a key surface. Memory poisoning (an agent persists attacker-controlled content that's trusted on later recall) is exactly what a prompt-only gate misses, and it's one of ATR's rule classes. The useful part is that the same deterministic ruleset can sit at both points: a validation hook on store/recall for the memory layer, and the tool-call boundary for in-flight content. For crewAI a thin optional hook at the memory read/write op, plus the tool-call one, would cover both. Happy to sketch it. Since I opened this, ATR's grown to ~655 rules and merged into Microsoft's AGT, Google's ADK docs, Tencent, AMD, and Dify.
Reliability note
Production automation failures usually reduce to a contract issue before a model/prompt issue:
- Success criteria — durable artifact id (message/booking/row), not only node green
- Side-effect before complete — never blind-retry without an idempotency key on the business object
- Tool vs path split — external action can succeed while the node/agent path still errors (silent-green / false-red)
If you have one failing execution + expected vs actual, reply with stack/version and I will send a free root-cause checklist.
This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
Closing this as it's gone quiet on the maintainer side. Thanks to everyone who weighed in — the convergence on the pre-tool hook, with a memory-layer hook on store/recall, as the load-bearing attachment point is the right target. Rather than keep a design question open, I'll come back with a concrete, runnable inspector as a PR against crewai-tools/security when it's ready. — Adam