CrewAI Example
Full working example: examples/crewai-demo
Setup
bash
cd examples/crewai-demo
pip install -r requirements.txt
# Create .env with your keys (see .env.example)
python run_demo.pyWhat it demonstrates
web_searchandarxiv_search— ALLOW (execute immediately)delete_research_data— REQUIRE_HUMAN_REVIEW (pauses, polls for human approval)
Configure
python
import gavrun
gavrun.configure(
api_key=os.environ["GAVRUN_API_KEY"],
agent_name="research_crew",
agent_manager_url="https://api.gavrun.ai",
environment="prod",
mode="enforce",
)Manual guard in a CrewAI tool
python
from crewai.tools import BaseTool
from gavrun.models import PreflightRequest
class WebSearchTool(BaseTool):
name = "web_search"
description = "Search the web."
def _run(self, query: str) -> str:
client = gavrun.get_client()
payload = PreflightRequest(
tenant_id=client.config.tenant_id,
agent_id=client.config.agent_id,
request_id=client.new_request_id(),
prompt=f"Search the web for: {query!r}",
plan_summary="Research crew web search",
tools=["web_search"],
models=["gpt-4o-mini"],
max_tokens=2000,
environment=client.config.environment,
sdk_version=client.config.sdk_version,
)
return client.guard_execution(
payload=payload,
on_allow=lambda _: _do_web_search(query),
)Approval flow
python
result = client.guard(
action="delete_research_data",
execute=lambda: archive_and_delete(query),
tools=["delete_research_data"],
prompt=f"Delete research data for '{query}'",
max_tokens=300,
)
if result.requires_human_review:
approval_id = result.decision.get("approval_id")
print(f"Approve at: https://agentmanager.gavrun.ai/approvals")
while True:
status = client.get_approval_status(approval_id=approval_id)
if status["status"] == "approved":
archive_and_delete(query)
break
elif status["status"] == "denied":
print("Denied by reviewer.")
break
time.sleep(3)