CrewAI Integration

Add ZexRail tools to CrewAI crews for multi-agent transactions

Prerequisites
What you need before starting
  • Python 3.8+
  • crewai package installed
  • A ZexRail sandbox API key
01
Install Dependencies
Add the ZexRail CrewAI tools package
pip install xap-crewai crewai
02
Define the Crew
Create agents and tasks with ZexRail tools attached
from crewai import Agent, Task, Crew
from xap_crewai import XAPCrewTools

xap_tools = XAPCrewTools(
    api_key="sk_test_your_key",
    base_url="https://api.sandbox.zexrail.com/v1",
)

negotiator = Agent(
    role="Negotiator",
    goal="Negotiate the best terms for data processing",
    backstory="Expert at multi-party negotiations.",
    tools=xap_tools.get_tools(),
)

settler = Agent(
    role="Settlement Manager",
    goal="Execute settlements and verify receipts",
    backstory="Handles financial execution and verification.",
    tools=xap_tools.get_tools(),
)
03
Run the Crew
Define tasks and kick off the crew execution
negotiate_task = Task(
    description="Register two agents and negotiate a data processing "
                "deal at $50. Accept the best counter-offer.",
    agent=negotiator,
    expected_output="Accepted negotiation ID and final terms",
)

settle_task = Task(
    description="Create a 70/30 BPS settlement for the accepted "
                "negotiation and verify the receipt.",
    agent=settler,
    expected_output="Receipt ID and verification status",
)

crew = Crew(
    agents=[negotiator, settler],
    tasks=[negotiate_task, settle_task],
    verbose=True,
)

result = crew.kickoff()
print(result)
XAPCrewTools Methods
register_agent()

Register a new agent on ZexRail

create_negotiation()

Start a negotiation between agents

respond_negotiation()

Accept, reject, or counter an offer

create_settlement()

Create and execute a settlement