crewAIInc / crewAIInc/crewAI

[FEATURE]:Governance middleware hook for tool call authorization

Open
#5,888 140 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature-request
Dominant language
Python
Stars
58.8k
Forks
8.5k
Avg merge
1d 15h
Merged PRs (30d)
109

Description

Feature Area

Agent capabilities

Is your feature request related to a an existing bug? Please link it here.

N/A

Describe the solution you'd like

Problem

CrewAI agents execute tools autonomously during crew runs. In production deployments, teams need governance controls:

  • Which tools each agent is authorized to use (beyond just assigning tools)
  • Cost tracking per agent across a crew run
  • Audit trail for compliance (who called what, when, why)
  • Ability to block specific tool calls based on runtime context (e.g., data sensitivity, time of day, budget remaining)

Currently, the only way to enforce this is by wrapping each tool's _run method individually, which doesn't compose well across crews.

Proposal

Add an optional governance hook that runs before each tool execution:

from crewai import Crew

def on_tool_call(agent, tool_name, tool_input, context):
    """Called before every tool execution. Raise to block."""
    if tool_name == "customer_export" and agent.role != "Admin":
        raise ToolBlockedError("customer_export requires Admin role")
    return True  # allow

crew = Crew(
    agents=[researcher, writer],
    on_tool_call=on_tool_call  # optional hook
)



This keeps governance decoupled from tool implementation — add/remove governance by changing the crew config, not every tool.

Working Example
I've built a working CrewAI + governance integration that demonstrates this pattern:

https://github.com/agentguard-ai/tealtiger/tree/main/examples/crewai-governance

It shows:

Policy-based tool authorization (allow/deny per tool per agent)
Per-agent cost tracking with CostTracker
A blocked customer_export tool call with clear error message
Works offline with deterministic demo mode (no API keys needed)
Uses TealTiger (open-source, Apache 2.0) for the governance engine, but the hook pattern would work with any policy engine.

Why this matters
OWASP's Agentic Top 10 identifies tool misuse (ASI-02) and access control failures (ASI-03) as top risks. A standard governance hook would let the CrewAI community build reusable authorization patterns without modifying individual tools.

Happy to submit a PR if a governance hook pattern is welcome.

### Describe alternatives you've considered

1. Wrapping each tool's _run method with governance logic — works but requires modifying every tool individually and doesn't compose across crews.

2. Subclassing Agent to override tool execution — tightly couples governance to a specific agent, breaks when switching agent types.

3. Post-hoc log analysis — only detects violations after they happen, doesn't prevent unauthorized actions.

A crew-level hook is preferred because it's non-invasive, composable, and works across all agents/tools without modification.


### Additional context

Working example with full source code: https://github.com/agentguard-ai/tealtiger/tree/main/examples/crewai-governance

This demonstrates:
- PolicyBuilder with allow/deny rules per tool
- governed_tool_call() wrapper pattern
- Per-agent cost tracking
- Blocked customer_export tool with clear error

OWASP Agentic Top 10 identifies tool misuse (ASI-02) and access control failures (ASI-03) as top risks for agentic applications.

Happy to submit a PR implementing this if the pattern is welcome.


### Willingness to Contribute

Yes, I'd be happy to submit a pull request

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing Crew's tool execution path and the Agent tool execution entry point described in the issue; compare them with the per-tool _run wrapping approach. The feature is done when a crew-level hook can inspect each agent, tool, input, and context, allow or block execution, and support clear blocked-call errors across agents.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
ai, authorization, security
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.