feat(hooks): add provider-based pre-tool-call guardrails#5422
Open
uchibeke wants to merge 1 commit intocrewAIInc:mainfrom
Open
feat(hooks): add provider-based pre-tool-call guardrails#5422uchibeke wants to merge 1 commit intocrewAIInc:mainfrom
uchibeke wants to merge 1 commit intocrewAIInc:mainfrom
Conversation
64282b8 to
47dda4b
Compare
Author
|
Hey @lorenzejay, lmk if this aligns with what you'd like to see. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds an optional provider-based guardrail seam on top of CrewAI's existing
before_tool_callhook flow.It keeps the core design intentionally small:
GuardrailProvidercontractAllowlistGuardrailProviderThis closes #4877 and follows the same architectural direction as the provider-based approach proposed in bytedance/deer-flow#1240, while staying consistent with CrewAI's current hook model and runtime behavior.
What Changed
GuardrailRequest,GuardrailDecision, andGuardrailProviderenable_guardrail(...)anddisable_guardrail(...)AllowlistGuardrailProviderfail_closed=True|Falsebehavior when provider evaluation errorsWhy This Shape
The issue thread correctly identified a missing production seam: CrewAI can run
before_tool_callhooks, but it does not currently expose a reusable provider contract for pre-tool-call authorization.This PR addresses that gap without overreaching:
allow/denyThat makes the feature usable today while leaving room for richer future decisions such as
escalateor signed receipts if CrewAI later adds first-class runtime support for them.External Provider Story
CrewAI stays vendor-neutral here.
The built-in allowlist provider covers the simplest production need, but external providers can enforce richer policy models through the same seam. The docs include an external OAP example with APort to show that the interface can support:
CrewAI core still only receives an
allowordenyverdict. Capability logic, limits, assurance rules, and policy-pack evaluation remain outside the framework in the provider.Non-Goals
This PR does not add:
suspend/resolve(decision_id, outcome)flowsallow | deny | escalatetri-state decisionsThose are valid future extensions, but they do not fit cleanly into CrewAI's current boolean
before_tool_callcontract without broader runtime changes.Docs
Updated:
docs/en/learn/tool-hooks.mdxdocs/ar/learn/tool-hooks.mdxdocs/ko/learn/tool-hooks.mdxdocs/pt-BR/learn/tool-hooks.mdxThe docs keep the core examples minimal and runnable, while also showing that an external provider can enforce more than simple tool-name allowlists.
Testing
Ran locally:
Result:
12 passedSyntax check:
Docs flow validated with the published APort bootstrap/runtime path:
APORT_NONINTERACTIVE=1 uvx --from aport-agent-guardrails aport setup --framework=crewai --integration-mode=nativeOAPGuardrailProvider(framework="crewai")registers throughenable_guardrail(...)Note:
uv runrepo lint/type suite on this machine because the existing workspace dependency resolution forlancedb==0.30.0is still failing on macOS x86_64 outside this diff.Linked Issue / Context
Issue Thread Coverage
before_tool_callis currently boolean.suspend + resolve(decision_id)modelallow/deny.GuardrailRequestcarriesagent_role,task_description, andcrew_id, but no explicit charter field yet.GuardrailDecisionyet.fail_closedbehavior is present; typed tri-state/callback/evidence are deferred.escalationfield to decisions