"""CrewAI crew with the Xenarch payment tool."""
import os
import sys
from decimal import Decimal
from crewai import Agent, Crew, Task
from xenarch.tools import XenarchBudgetPolicy, XenarchCrewaiPay
pay = XenarchCrewaiPay(
private_key=os.environ["XENARCH_PRIVATE_KEY"],
budget_policy=XenarchBudgetPolicy(
max_per_call=Decimal("0.05"),
max_per_session=Decimal("0.50"),
),
)
researcher = Agent(
role="Research Agent",
goal="Read and summarize web pages, paying for them when required",
backstory=(
"You fetch pages with the xenarch_pay tool. It pays in USDC on Base "
"when a page answers HTTP 402, and returns the page content."
),
tools=[pay],
verbose=True,
)
url = sys.argv[1] if len(sys.argv) > 1 else "https://example.com/premium-article"
task = Task(
description=f"Fetch {url} with the xenarch_pay tool and summarize it.",
expected_output="A short summary, plus the amount paid and transaction hash if a payment was made.",
agent=researcher,
)
crew = Crew(agents=[researcher], tasks=[task], verbose=True)
if __name__ == "__main__":
print(crew.kickoff())