from crewai import Agent, Task, Crew, Process
from agntor import Agntor, guard, redact
client = Agntor(api_key="agntor_live_xxx", agent_id="crew-orchestrator", chain="base")
# Define agents
researcher = Agent(
role="Senior Research Analyst",
goal="Uncover actionable market insights",
backstory="20 years of quantitative research experience",
verbose=True,
)
writer = Agent(
role="Report Writer",
goal="Turn research into clear, actionable reports",
backstory="Former Wall Street analyst turned technical writer",
verbose=True,
)
async def run_trusted_crew(topic: str):
# 1. Guard the input
g = guard(topic)
if g.classification == "block":
return {"error": "Topic blocked", "violations": g.violation_types}
# 2. Create escrow for the whole crew job
escrow = await client.escrow.create(
agent_id="crew-orchestrator",
amount=100_000_000, # 100 USDC
task_description=f"Research crew: {topic}",
)
task_id = escrow.get("task", {}).get("id") or escrow.get("taskId")
# 3. Define tasks
research_task = Task(
description=f"Research: {topic}. Provide data-backed findings.",
agent=researcher,
expected_output="Detailed research findings with data points",
)
report_task = Task(
description="Write a concise executive report from the research findings.",
agent=writer,
expected_output="Executive summary report",
)
# 4. Run the crew
crew = Crew(
agents=[researcher, writer],
tasks=[research_task, report_task],
process=Process.sequential,
verbose=True,
)
try:
raw_result = crew.kickoff()
# 5. Redact any PII/secrets from the final output
safe = redact(str(raw_result))
# 6. Settle escrow
if task_id:
await client.settle.release(task_id, reason="Crew completed successfully")
# 7. Log to audit trail
await client.audit.log(
agent_id="crew-orchestrator",
action="task_completed",
details={
"topic": topic,
"agents_used": 2,
"redacted_items": len(safe.findings),
},
)
return {"output": safe.redacted, "settled": True}
except Exception as e:
if task_id:
await client.settle.dispute(task_id, reason=str(e))
return {"error": str(e), "settled": False}