Mandate · Guide
Gate CrewAI tools
Use provenanceauth-crewai to add approvals to the tools your CrewAI agents use. Each call is authorized and verified on its exact arguments, after CrewAI validates them against the tool's schema, then the tool runs with those arguments.
Before you begin: install the package, and export the sandbox account key.
export PROVENANCE_API=https://sandbox-api.provenanceauth.com
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5
This package isn't on PyPI yet. Until then, every request in these docs runs over HTTP against the sandbox.
With access to the private Provenance repository, which your Provenance contact grants, install from it:
git clone https://github.com/michaelnbane-jpg/provenance.git provenance
pip install ./provenance/python/sdk ./provenance/python/crewai-provenanceAvailability: the package is available to beta customers. It supports crewai 1.x.
1. Gate a tool
authorize_tool takes a tool built with @tool, or your own BaseTool subclass, and returns a gated copy:
import os
from crewai import Agent, Crew, Task
from crewai.tools import tool
from provenanceauth_crewai import authorize_tool
from provenanceauth import Provenance
prov = Provenance(os.environ["PROVENANCE_KEY"], base_url=os.environ["PROVENANCE_API"])
@tool("pay_invoice")
def pay_invoice(invoice: str, amount: float, payee: str) -> str:
"""Pay a supplier invoice."""
return f"paid {invoice}"
clerk = Agent(
role="Billing clerk",
goal="Pay supplier invoices",
backstory="Pays approved invoices for the finance team.",
tools=[authorize_tool(
pay_invoice,
client=prov,
device_id="dev_00000000000000000000000000000001",
describe=lambda a: f"Pay invoice {a['invoice']}: ${a['amount']} to {a['payee']}",
)],
)
The gated copy is an instance of the tool's own class, so isinstance checks, fields and methods stay the same. Without describe, the action description is the tool name and the canonical JSON of its arguments.
2. Read the outcome
| Outcome | What happens |
|---|---|
| Verified | The tool runs with the arguments that were verified |
| Denied | The tool returns a sentence instead, such as "The person declined this action.", and the agent reads it as the observation |
| Waiting for approval | The tool waits for the person, up to timeout_ (default 2 minutes), then runs or returns the sentence |
If the person hasn't answered when the wait ends, the agent reads "Waiting for approval (appr_…)", and the next call with the same arguments reuses the token that opened the approval. The agent session is CrewAI's run id for the kickoff when the release exposes one, or one id per gated tool; pass agent_session_id to set it.
CrewAI's before_tool_call hooks block a call with a fixed message, so the package gates the tool itself, where the agent can read why a call didn't run.
3. Pass the rest of the options
contextfunction- Facts for your policy, read at verify.
payloadfunction- The payload bound into the token. Default: the tool name and its whole input.
run_idstring- An agent-team run to bind each call to.
mandate_tokenstring- A grant to authorize under.
agent_idstring- The registered agent making the calls.
timeout_msnumber- How long to wait for the person.
0answers at once.
Errors you might see
| Symptom | Cause | Fix |
|---|---|---|
TypeError: is already gated | The tool was passed to authorize_ twice | Gate the original tool once. |
| The agent reads "Waiting for approval" | The person hadn't answered within timeout_ | Raise timeout_, or run the task again after they approve. |