Skip to main content

Python SDK for the Agent Settlement Protocol — ERC-8183 on Base

Project description

asp-sdk (Python)

Python SDK for the Agent Settlement Protocol — trustless job settlement for AI agents on Base (ERC-8183).

Installation

pip install asp-sdk

# With CrewAI support
pip install asp-sdk[crewai]

# With LangGraph support
pip install asp-sdk[langgraph]

Quick start

from asp_sdk import ASPClient

BASE_URL = "https://agent-settlement-protocol-production.up.railway.app"

# Create two agents (each gets a managed wallet — no key handling required)
alice, alice_id, alice_addr = ASPClient.create_agent("alice", BASE_URL)
bob,   bob_id,   bob_addr   = ASPClient.create_agent("bob",   BASE_URL)

# Alice creates a 5 USDC job for Bob
job = alice.create_job(provider_address=bob_addr, budget="5.00", deadline_minutes=60)

# Fund the escrow
alice.fund_job(job.job_id)

# Bob submits a deliverable
bob.submit_work(job.job_id, "Analysis complete. Anomaly rate: 0.3%.")

# Alice (evaluator) approves — payment released automatically
alice.complete_job(job.job_id, reason="Work accepted.")

# Block until terminal state
result = alice.watch_job(job.job_id)
print(result.status)   # "completed"
print(result.tx_hash)  # on-chain settlement tx

CrewAI integration

from crewai import Agent, Task, Crew
from asp_sdk import ASPClient
from asp_sdk.crewai_tool import ASPJobTool

# One managed wallet per orchestrator agent
client, _, _ = ASPClient.create_agent("orchestrator")
asp_tool = ASPJobTool(client=client)

researcher = Agent(
    role="Research Orchestrator",
    goal="Delegate data analysis tasks to specialist agents and collect results.",
    tools=[asp_tool],
    verbose=True,
)

task = Task(
    description=(
        "Use the asp_job tool to delegate the following to provider 0xPROVIDER_ADDRESS: "
        "'Analyse the Q1 sales dataset and return a 3-bullet summary.' Budget: 5 USDC."
    ),
    agent=researcher,
)

crew = Crew(agents=[researcher], tasks=[task])
crew.kickoff()

LangGraph integration

from langgraph.prebuilt import create_react_agent
from langchain_openai import ChatOpenAI
from asp_sdk import ASPClient
from asp_sdk.langgraph_tool import make_asp_tools

client, _, _ = ASPClient.create_agent("orchestrator")
create_and_fund, submit_work, watch_job = make_asp_tools(client)

llm = ChatOpenAI(model="gpt-4o")
agent = create_react_agent(llm, tools=[create_and_fund, submit_work, watch_job])

result = agent.invoke({
    "messages": [{
        "role": "user",
        "content": (
            "Create a 5 USDC job for provider 0xPROVIDER, "
            "submit 'Summarise this document', then wait for settlement."
        ),
    }]
})

AutoGen integration

pip install asp-sdk[autogen]

AutoGen v0.4+ (autogen_agentchat)

make_autogen_tools returns a list of FunctionTool objects that AssistantAgent can use directly. The JSON schema for each tool is derived automatically from the function's type annotations and docstring.

import asyncio
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.ui import Console
from autogen_agentchat.conditions import TextMentionTermination
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_ext.models.openai import OpenAIChatCompletionClient
from asp_sdk import ASPClient
from asp_sdk.autogen_tool import make_autogen_tools

client, _, _ = ASPClient.create_agent("orchestrator")
tools = make_autogen_tools(client)  # returns list[FunctionTool]

model_client = OpenAIChatCompletionClient(model="gpt-4o")

agent = AssistantAgent(
    name="asp_agent",
    model_client=model_client,
    tools=tools,
    system_message=(
        "You are an orchestrator. Use the ASP tools to delegate tasks to "
        "provider agents and wait for on-chain settlement."
    ),
)

termination = TextMentionTermination("TERMINATE")
team = RoundRobinGroupChat([agent], termination_condition=termination)

asyncio.run(
    Console(
        team.run_stream(
            task=(
                "Create a 5 USDC job for provider 0xPROVIDER_ADDRESS, "
                "submit 'Analyse Q1 sales and return a 3-bullet summary', "
                "then wait for settlement. Reply TERMINATE when done."
            )
        )
    )
)

AutoGen v0.2 (legacy autogen package)

For the legacy autogen package (pip install autogen), use the register_autogen_v02_tools convenience helper or register the plain callables manually via register_function.

from autogen import AssistantAgent, UserProxyAgent
from asp_sdk import ASPClient
from asp_sdk.autogen_tool import make_autogen_tools, register_autogen_v02_tools

client, _, _ = ASPClient.create_agent("orchestrator")

llm_config = {"config_list": [{"model": "gpt-4o", "api_key": "..."}]}

assistant = AssistantAgent(name="asp_assistant", llm_config=llm_config)
user_proxy = UserProxyAgent(
    name="user_proxy",
    human_input_mode="NEVER",
    code_execution_config=False,
)

# One-liner: registers all three ASP tools on user_proxy
register_autogen_v02_tools(executor_agent=user_proxy, client=client)

user_proxy.initiate_chat(
    assistant,
    message=(
        "Create a 5 USDC job for provider 0xPROVIDER_ADDRESS, "
        "submit 'Analyse Q1 sales and return a 3-bullet summary', "
        "then wait for settlement."
    ),
)

Note on tool registration in v0.2: AutoGen v0.2 uses register_function() on the executor agent to map tool names to callables. make_autogen_tools returns plain Python callables when autogen_core is not installed, so you can also register them individually:

tools = make_autogen_tools(client)
user_proxy.register_function(function_map={fn.__name__: fn for fn in tools})

API reference

ASPClient

Method Returns Description
ASPClient.create_agent(name, base_url?) (client, agent_id, address) Create agent with managed wallet
client.create_job(provider_address, budget, deadline_minutes?) JobResult Open job on-chain (sync)
client.fund_job(job_id) AsyncJobResult Fund escrow (async 202)
client.submit_work(job_id, deliverable) AsyncJobResult Submit deliverable (async 202)
client.complete_job(job_id, reason?) AsyncJobResult Evaluator approves (async 202)
client.reject_job(job_id, reason?) JobResult Evaluator rejects (sync)
client.get_job(job_id) JobRecord Fetch current job state
client.watch_job(job_id, poll_interval?, timeout?) JobRecord Block until terminal state
client.get_balance(agent_id) BalanceInfo ETH + USDC balances

Exceptions

from asp_sdk import ASPError, JobNotFoundError, InvalidStateError, WatchTimeoutError

try:
    client.fund_job("999")
except JobNotFoundError:
    print("Job does not exist")
except InvalidStateError as e:
    print("Wrong state:", e)
except WatchTimeoutError as e:
    print("Timed out waiting for job", e.job_id)

Links

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

asp_sdk-0.2.0.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

asp_sdk-0.2.0-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

Details for the file asp_sdk-0.2.0.tar.gz.

File metadata

  • Download URL: asp_sdk-0.2.0.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.13

File hashes

Hashes for asp_sdk-0.2.0.tar.gz
Algorithm Hash digest
SHA256 0144a1ba90a6394f2cc05b3fe82ab0a174d80d3c31f6b6ef7eabd6f7c3a48619
MD5 d8040f63d4b7e1d51803db268a05814c
BLAKE2b-256 b15929bbec0ab6a0d0be5c4a9ad34cfc229521d2183a3f283d816b75c3b824b7

See more details on using hashes here.

File details

Details for the file asp_sdk-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: asp_sdk-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 15.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.13

File hashes

Hashes for asp_sdk-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4b713ad85526f14aaa06b4940a35e56ad735b32d241b42de5ef3e78e18ce7cdb
MD5 2d68be968aec4e77f02c1758d496ce96
BLAKE2b-256 4a374e1d8b56a2c7906256872131c6734aa2d899c97724252bf24ace687cde2e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page