> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xenarch.com/llms.txt
> Use this file to discover all available pages before exploring further.

# CrewAI Agent

> CrewAI agent example — a research crew that pays for x402-gated content with USDC micropayments on Base using Xenarch payment tools.

A CrewAI crew with a specialized Research Agent role that handles Xenarch payments autonomously.

## Setup

```bash theme={null}
pip install xenarch[agent,crewai] crewai>=0.80.0 python-dotenv
```

Create `.env`:

```bash theme={null}
XENARCH_PRIVATE_KEY=0xYOUR_PRIVATE_KEY
OPENAI_API_KEY=sk-...
```

## Code

```python main.py theme={null}
"""CrewAI crew with Xenarch payment tools."""

from dotenv import load_dotenv
from crewai import Agent, Crew, Task

from xenarch.tools.crewai import check_gate, get_history, pay

load_dotenv()

researcher = Agent(
    role="Research Agent",
    goal="Access and summarize gated web content by paying for it when needed",
    backstory=(
        "You are a research agent that can pay for gated content using "
        "Xenarch micropayments. When you encounter a payment gate, you "
        "check the price, pay with USDC on Base, and use the access token "
        "to retrieve the content."
    ),
    tools=[check_gate, pay, get_history],
    verbose=True,
)

task = Task(
    description=(
        "Check if https://gate.xenarch.dev/hello-world/ has a Xenarch payment gate. "
        "If it does, pay for access and report what you found."
    ),
    expected_output="A summary of the gate status and any payment made.",
    agent=researcher,
)

crew = Crew(agents=[researcher], tasks=[task], verbose=True)

if __name__ == "__main__":
    result = crew.kickoff()
    print(result)
```

## Run

```bash theme={null}
python main.py
```
