Metadata-Version: 2.5
Name: ory-crewai
Version: 1.12.0
Summary: Ory Agent Security for CrewAI — per-tool authorization, activity logging, and identity propagation by wrapping tools. Built on ory-argus.
Author: Ory
License-Expression: Apache-2.0
Keywords: agent,ai,authorization,crewai,ory,permissions
Requires-Python: >=3.10
Requires-Dist: crewai>=0.80
Requires-Dist: ory-argus<2,>=1
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == 'dev'
Requires-Dist: ruff>=0.6; extra == 'dev'
Description-Content-Type: text/markdown

# ory-crewai

Ory Agent Security for [CrewAI](https://docs.crewai.com).

Wraps your CrewAI tools so every call is authorized against Ory Permissions, audited, and
tied to the user → agent identity — built on [`ory-argus`](https://pypi.org/project/ory-argus/).

```bash
pip install ory-crewai
```

```python
from crewai import Agent
from ory_crewai import guard_tools

agent = Agent(role="researcher", tools=guard_tools([search, send_email]))
```

In **enforce** mode a denied tool raises an error that CrewAI
surfaces to the LLM; the tool never runs. In **observe** mode (default) the tool runs and a
`permission.observe_deny` activity event is recorded.

## Sub-agents

A wrapped tool that runs another agent runs as a sub-agent with its own identity, so the
tool calls that agent makes inside it (through its own wrapped tools) are checked and
recorded as the sub-agent's. This applies to the tools you name in
`guard_tools(tools, subagent_tools={"research_crew"})` and to CrewAI's delegation tools
(`Delegate work to coworker`, `Ask question to coworker`), which are typed by the coworker's
role. CrewAI creates the delegation tools itself when `allow_delegation` is set, so they are
covered only when you pass them to `guard_tools`; otherwise a coworker's tool calls are
attributed to the delegating agent.

## MCP tools

CrewAI MCP tools (`MCPNativeTool` and `MCPToolWrapper`) are checked as `McpServer:<server>`
and `McpTool:<server>:<tool>` instead of plain tools. Tools you pass through `guard_tools`
are identified there. Tools that `Agent(mcps=[...])` resolves when the agent runs never pass
through `guard_tools`, so register Ory's MCP tool hooks (CrewAI 1.x) once per process:

```python
from crewai.mcp import MCPServerStdio
from ory_crewai import register_ory_mcp_hooks

unregister = register_ory_mcp_hooks()   # global before/after tool-call hooks
agent = Agent(
    role="researcher",
    tools=guard_tools([search]),
    mcps=[MCPServerStdio(command="npx", args=["-y", "@playwright/mcp"]), "https://mcp.example.com/mcp"],
)
```

The hooks gate only MCP tools that `guard_tools` has not wrapped, so no call is checked twice;
other tools pass through untouched. In enforce mode a denied call is blocked before it runs and
the model receives the denial. Each call reports the AMP slug the server was requested by, the server's raw tool name, and
hashed fingerprints of the URL host or launched package, so Agent Security matches the server to
its catalog. CrewAI derives its own server name from the URL path or the launch command and
arguments, which can hold paths and keys, so a server without a slug is reported as `unknown`
and identified only by its fingerprints. Fingerprints are hashes; no URL, command, or argument
is sent.

For activity across paths that bypass the wrapped tools, also register the event listener:

```python
from ory_crewai import ory_event_listener
listener = ory_event_listener()  # records ToolUsage activity
```

Credentials come from the shared `~/.config/ory-agent-plugins/config.json`.
