5-minute quick start
1.Install
pip install venzx crewai2.Set your keys
Create a VENZX key in your dashboard. The example uses an OpenAI model, so it needs that key too.
export VENZX_API_KEY="pai-..." export OPENAI_API_KEY="sk-..."3.Save crew.py
Save this as crew.py. """CrewAI + VENZX: check every tool call before the tool runs. The integration point is CrewAI's tool-call hooks. A ``before_tool_call`` hook runs for every tool any agent in any crew is about to use; returning ``False`` from it stops the tool. The hook asks VENZX: allow -> the tool runs block -> the tool does not run needs_review -> the tool does not run; it is held for a person (or, with APPROVAL_WAIT_SECONDS set, wait for them and then run) CrewAI tells the agent only "blocked by hook", so an ``after_tool_call`` hook replaces that with the reason VENZX gave, and the agent can act on it. Tested with crewai 1.15.41. Run it: pip install venzx crewai export VENZX_API_KEY="pai-..." OPENAI_API_KEY="sk-..." python crew.py """ from __future__ import annotations import os import threading from crewai import Agent, Crew, Task from crewai.hooks import ( ToolCallHookContext, register_after_tool_call_hook, register_before_tool_call_hook, ) from crewai.tools import tool from venzx import ApprovalRequired, Blocked, Guard, Policy, Venzx # What these agents may do. Sent with every check, so it applies even if the # account's own policy is empty. POLICY = ( Policy() .allow_tools("lookup_order", "refund") # anything else is blocked .require_approval("refund") # a person must say yes ) # Stand-in for your systems, so you can see what actually ran. ACTIONS: list = [] @tool("lookup_order") def lookup_order(order_id: str) -> str: """Look up the status of an order.""" ACTIONS.append(("lookup_order", order_id)) return f"Order {order_id}: delivered, total $40.00" @tool("refund") def refund(order_id: str, amount: float) -> str: """Refund an order.""" ACTIONS.append(("refund", order_id, amount)) return f"Refunded ${amount:.2f} on order {order_id}" @tool("delete_customer") def delete_customer(customer_id: str) -> str: """Delete a customer and all their data.""" ACTIONS.append(("delete_customer", customer_id)) return f"Deleted customer {customer_id}" # ── the VENZX check (identical in every framework example) ─────────────── # Seconds to wait for a person when an action is held. 0 (the default) does # not wait: the model is told the action is held and carries on. APPROVAL_WAIT_SECONDS = float(os.environ.get("APPROVAL_WAIT_SECONDS", "0")) def venzx_refusal(guard: Guard, name: str, args: dict, wait_seconds: float = APPROVAL_WAIT_SECONDS) -> str | None: """Ask VENZX about one tool call, before it runs. Returns None if the tool may run. Otherwise returns the sentence to give the model in place of the tool's result. Never raises: anything that goes wrong is a refusal, so a tool cannot run unchecked.""" try: guard.tool_call(name, args) return None # allowed except ApprovalRequired as e: approval_id = e.result.approval_id # held for a person except Blocked as e: return f"BLOCKED: {e.result.reason}. It has NOT run." except Exception as e: # noqa: BLE001 return f"BLOCKED: the action could not be checked ({e}). It has NOT run." status = "pending" if wait_seconds > 0: try: status = guard.client.wait_for_approval( approval_id, timeout=wait_seconds).get("status", "pending") # Reading "approved" is not permission. Claiming it is, and the # claim names this exact call, so it cannot be spent on another. guard.client.consume_approval( approval_id, action={"name": name, "args": dict(args)}) return None # a person said yes except Exception: # noqa: BLE001 pass # rejected, expired or still pending if status == "rejected": return f"REJECTED: a person declined '{name}'. It has NOT run." return (f"HELD: '{name}' needs a person to approve it " f"(approval id {approval_id}). It has NOT run.") # ── end of the VENZX check ─────────────────────────────────────────────── def install_venzx_hooks(guard: Guard) -> None: """Register the two hooks. Call once, before any crew runs.""" last = threading.local() # the before-hook's refusal, for the after-hook def before(context: ToolCallHookContext) -> bool | None: # CrewAI carries on if a hook raises, which would run the tool # unchecked. venzx_refusal never raises: every failure is a refusal. last.refusal = venzx_refusal(guard, context.tool_name, dict(context.tool_input or {})) return None if last.refusal is None else False # False stops the tool def after(context: ToolCallHookContext) -> str | None: refusal, last.refusal = getattr(last, "refusal", None), None return refusal # None leaves the tool's own result alone register_before_tool_call_hook(before) register_after_tool_call_hook(after) def build_crew(llm=None, guard: Guard | None = None) -> Crew: """A one-agent crew. ``llm`` is optional: leave it out for CrewAI's default.""" install_venzx_hooks(guard or Guard(Venzx(), policy=POLICY)) kwargs = {"llm": llm} if llm is not None else {} support = Agent( role="Support agent", goal="Resolve the customer's request using the tools", backstory="You work the support desk for an online shop.", tools=[lookup_order, refund, delete_customer], **kwargs, ) task = Task( description=("Order A-1001 arrived broken. Look it up, refund it in full, " "then delete customer C-77."), expected_output="A short summary of what was done and what was not.", agent=support, ) return Crew(agents=[support], tasks=[task]) def main() -> None: result = build_crew().kickoff() print(result) print("\nWhat actually ran:", ACTIONS) if __name__ == "__main__": main()4.Run it
python crew.pyThe example is a support agent with three tools. Its policy lets lookup_order run, holds refund for a person, and has no entry for delete_customer.
The crew’s final answer varies from run to run. The last line is what matters: it lists what actually ran, and it should hold lookup_order only.
The refund did not run. It is waiting as an approval email at the address on your VENZX account. delete_customer did not run and never will under this policy.
5.Approve the refund
Open the approval email and press Approve. By default the example does not wait for you: it tells the model the refund is held and moves on. To have the tool call wait for your decision and then run, set a wait before you start it:
APPROVAL_WAIT_SECONDS=600 python crew.py
How it plugs in
The integration point is register_before_tool_call_hook / register_after_tool_call_hook, which CrewAI provides for exactly this.
CrewAI runs every registered before_tool_call hook just before a tool executes, with the tool’s name and input. A hook that returns False stops the tool. The example’s hook asks VENZX and returns False unless the answer is allow.
On its own that tells the agent only “Tool execution blocked by hook”. CrewAI also runs after_tool_call hooks on a blocked call and lets them replace the result, so a second hook swaps in the reason VENZX gave.
When a call is refused. The agent’s Observation for that step is the reason, for example that the tool is held for a person, with the approval id. The crew carries on.
The check itself
venzx_refusal in the file above is the same in every framework example. It returns nothing when the tool may run, and otherwise the sentence to give the model:
- Allowed: the tool runs.
- Blocked: the tool does not run, and the model is told why.
- Held for a person: the tool does not run. With
APPROVAL_WAIT_SECONDSset, it waits for the decision and then claims the approval for that exact tool and those exact arguments before running. An approval cannot be spent on a different call. - Anything goes wrong, including VENZX being unreachable: the tool does not run.
The policy at the top of the file travels with every check. Change it there, or delete it to use the policy saved on your account. See Policy and the human-approval gate.
What this does not cover
- The hooks are process-wide. Once installed they cover every agent and every crew in the process, so install them once, before the first kickoff.
- CrewAI carries on if a hook raises an exception, which would run the tool unchecked. The check in the example never raises: any error, including VENZX being unreachable, is returned as a refusal. Keep that property if you change it.
- Only tools that CrewAI executes are checked. Code that calls a tool function directly bypasses it.
VENZX answers before your tool runs and never sees it execute. The general limits are in What VENZX does NOT do.
Other frameworks
LangGraph · OpenAI Agents SDK · MCP · SDK docs
The example, its pinned requirements.txt and its test are in examples/crewai/ of the SDK repository.