CrewAI
Make a CrewAI tool run only after a person approves, inside your own tool or with a before_tool_call hook for tools you did not write.
A CrewAI agent acts through tools, so the approval goes where a tool is about to act. There are two places for it: inside a tool you wrote, or in a before_tool_call hook for a tool you didn’t. Either way the request lands in your VariantGate inbox, a person approves or denies it from a phone, an email link or Slack, and the tool runs only on a yes.
1. Install the client
pip install https://variantgate.com/sdk/variantgate-latest.tar.gzIt has no dependencies beyond the standard library and works on Python 3.9 or newer. Make an agent key under Agents in your workspace and put it in VARIANTGATE_KEY. The client reads it from there.
2. Ask inside your own tool
require_approval asks, waits for the answer, runs the block only on a yes, and records afterwards whether the refund worked.
from crewai.tools import tool
from variantgate import ApprovalClient, NotApprovedError
approvals = ApprovalClient("support-crew") # reads VARIANTGATE_KEY
@tool("refund_order")
def refund_order(order_id: str, amount_eur: str) -> str:
"""Refund an order to the customer's original payment method."""
summary = f"Refund €{amount_eur} for order {order_id}"
try:
with approvals.require_approval(
"payment.refund",
summary,
amount=amount_eur,
currency="EUR",
details={"order": order_id},
timeout=900,
) as approved:
refund_id = shop.refund(order_id, amount_eur)
approved.note = f"refund {refund_id}"
except NotApprovedError as no:
return f"Not refunded. {no}"
return f"Refunded €{amount_eur} for order {order_id}."- Anything but an explicit approval raises
NotApprovedErrorand skips the block: denied, expired, a paused workspace, or a request still open whentimeoutruns out, which is then withdrawn so nobody approves it later. - The tool returns a sentence on a no instead of raising, so the agent can report what happened rather than look for another way round.
- If a person lowers the amount or rewords the request, the block does not run and the record says so. The agent is told what was approved and can ask again for that.
- State the amount, and a rule such as “always allow
payment.refundup to €20” approves the small ones at once.
3. Or gate a tool you didn’t write
For tools from crewai_tools, an MCP server or another package, register a hook. CrewAI calls it before every matching tool call, and a False return blocks the call.
from crewai.hooks import before_tool_call
from variantgate import VariantGateError
@before_tool_call(tools=["send_email"])
def ask_before_email(context) -> bool | None:
"""Gate a tool you did not write. Returning False blocks the call."""
args = context.tool_input
try:
approvals.wait_for_approval(
"email.send",
f"Email {args['to']}: {args['subject']}",
details={"to": args["to"], "subject": args["subject"]},
timeout=900,
)
except VariantGateError:
return False # denied, expired, changed or unreachable: do not send
return NoneThe hook catches every VariantGateError, so a request the API could not take blocks the call too. Two things it cannot do: the agent sees that the tool was blocked but not why, and the record shows the approval without saying whether the email went out. When either matters, wrap the tool in one of your own and use the first approach.
4. Run the crew
from crewai import Agent, Crew, Task
support = Agent(
role="Support agent",
goal="Resolve customer problems with orders",
backstory="You handle refunds for a small online shop.",
tools=[refund_order, send_email], # send_email: any tool, such as one from crewai_tools
)
task = Task(
description="Order 1182 arrived broken. Refund the €49 and email the customer.",
expected_output="What was done, and what was not.",
agent=support,
)
print(Crew(agents=[support], tasks=[task]).kickoff())Each tool call waits while a person decides, up to the timeout. For decisions that may take hours, run the crew from a job that can wait, or split the work so the step after approval starts from a signed webhook.
CrewAI’s own human input
human_input=True on a task, and context.request_human_input in a hook, ask whoever is at the terminal running the crew. That suits a crew you run by hand. VariantGate suits a crew that runs on a schedule or in a service: the decision reaches someone who is not watching the logs, rules answer the routine calls, and the answer is kept on the record.