asp-sdk 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of asp-sdk might be problematic. Click here for more details.
- asp_sdk-0.1.0/PKG-INFO +264 -0
- asp_sdk-0.1.0/README.md +238 -0
- asp_sdk-0.1.0/asp_sdk/__init__.py +45 -0
- asp_sdk-0.1.0/asp_sdk/autogen_tool.py +279 -0
- asp_sdk-0.1.0/asp_sdk/client.py +212 -0
- asp_sdk-0.1.0/asp_sdk/crewai_tool.py +123 -0
- asp_sdk-0.1.0/asp_sdk/errors.py +38 -0
- asp_sdk-0.1.0/asp_sdk/langgraph_tool.py +101 -0
- asp_sdk-0.1.0/asp_sdk/types.py +108 -0
- asp_sdk-0.1.0/asp_sdk.egg-info/PKG-INFO +264 -0
- asp_sdk-0.1.0/asp_sdk.egg-info/SOURCES.txt +14 -0
- asp_sdk-0.1.0/asp_sdk.egg-info/dependency_links.txt +1 -0
- asp_sdk-0.1.0/asp_sdk.egg-info/requires.txt +18 -0
- asp_sdk-0.1.0/asp_sdk.egg-info/top_level.txt +1 -0
- asp_sdk-0.1.0/pyproject.toml +31 -0
- asp_sdk-0.1.0/setup.cfg +4 -0
asp_sdk-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: asp-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python SDK for the Agent Settlement Protocol — ERC-8183 on Base
|
|
5
|
+
License: MIT
|
|
6
|
+
Project-URL: Homepage, https://github.com/Demsys/agent-settlement-protocol
|
|
7
|
+
Project-URL: Repository, https://github.com/Demsys/agent-settlement-protocol
|
|
8
|
+
Project-URL: Issues, https://github.com/Demsys/agent-settlement-protocol/issues
|
|
9
|
+
Keywords: erc-8183,ai-agents,agentic-commerce,a2a,settlement,base,blockchain
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
Requires-Dist: httpx>=0.27
|
|
13
|
+
Requires-Dist: pydantic>=2.0
|
|
14
|
+
Provides-Extra: crewai
|
|
15
|
+
Requires-Dist: crewai>=0.28; extra == "crewai"
|
|
16
|
+
Provides-Extra: langgraph
|
|
17
|
+
Requires-Dist: langchain-core>=0.2; extra == "langgraph"
|
|
18
|
+
Requires-Dist: langgraph>=0.1; extra == "langgraph"
|
|
19
|
+
Provides-Extra: autogen
|
|
20
|
+
Requires-Dist: autogen-agentchat>=0.4; extra == "autogen"
|
|
21
|
+
Provides-Extra: all
|
|
22
|
+
Requires-Dist: crewai>=0.28; extra == "all"
|
|
23
|
+
Requires-Dist: langchain-core>=0.2; extra == "all"
|
|
24
|
+
Requires-Dist: langgraph>=0.1; extra == "all"
|
|
25
|
+
Requires-Dist: autogen-agentchat>=0.4; extra == "all"
|
|
26
|
+
|
|
27
|
+
# asp-sdk (Python)
|
|
28
|
+
|
|
29
|
+
Python SDK for the **Agent Settlement Protocol** — trustless job settlement for AI agents on Base (ERC-8183).
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install asp-sdk
|
|
35
|
+
|
|
36
|
+
# With CrewAI support
|
|
37
|
+
pip install asp-sdk[crewai]
|
|
38
|
+
|
|
39
|
+
# With LangGraph support
|
|
40
|
+
pip install asp-sdk[langgraph]
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Quick start
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
from asp_sdk import ASPClient
|
|
47
|
+
|
|
48
|
+
BASE_URL = "https://agent-settlement-protocol-production.up.railway.app"
|
|
49
|
+
|
|
50
|
+
# Create two agents (each gets a managed wallet — no key handling required)
|
|
51
|
+
alice, alice_id, alice_addr = ASPClient.create_agent("alice", BASE_URL)
|
|
52
|
+
bob, bob_id, bob_addr = ASPClient.create_agent("bob", BASE_URL)
|
|
53
|
+
|
|
54
|
+
# Alice creates a 5 USDC job for Bob
|
|
55
|
+
job = alice.create_job(provider_address=bob_addr, budget="5.00", deadline_minutes=60)
|
|
56
|
+
|
|
57
|
+
# Fund the escrow
|
|
58
|
+
alice.fund_job(job.job_id)
|
|
59
|
+
|
|
60
|
+
# Bob submits a deliverable
|
|
61
|
+
bob.submit_work(job.job_id, "Analysis complete. Anomaly rate: 0.3%.")
|
|
62
|
+
|
|
63
|
+
# Alice (evaluator) approves — payment released automatically
|
|
64
|
+
alice.complete_job(job.job_id, reason="Work accepted.")
|
|
65
|
+
|
|
66
|
+
# Block until terminal state
|
|
67
|
+
result = alice.watch_job(job.job_id)
|
|
68
|
+
print(result.status) # "completed"
|
|
69
|
+
print(result.tx_hash) # on-chain settlement tx
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## CrewAI integration
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
from crewai import Agent, Task, Crew
|
|
76
|
+
from asp_sdk import ASPClient
|
|
77
|
+
from asp_sdk.crewai_tool import ASPJobTool
|
|
78
|
+
|
|
79
|
+
# One managed wallet per orchestrator agent
|
|
80
|
+
client, _, _ = ASPClient.create_agent("orchestrator")
|
|
81
|
+
asp_tool = ASPJobTool(client=client)
|
|
82
|
+
|
|
83
|
+
researcher = Agent(
|
|
84
|
+
role="Research Orchestrator",
|
|
85
|
+
goal="Delegate data analysis tasks to specialist agents and collect results.",
|
|
86
|
+
tools=[asp_tool],
|
|
87
|
+
verbose=True,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
task = Task(
|
|
91
|
+
description=(
|
|
92
|
+
"Use the asp_job tool to delegate the following to provider 0xPROVIDER_ADDRESS: "
|
|
93
|
+
"'Analyse the Q1 sales dataset and return a 3-bullet summary.' Budget: 5 USDC."
|
|
94
|
+
),
|
|
95
|
+
agent=researcher,
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
crew = Crew(agents=[researcher], tasks=[task])
|
|
99
|
+
crew.kickoff()
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## LangGraph integration
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
from langgraph.prebuilt import create_react_agent
|
|
106
|
+
from langchain_openai import ChatOpenAI
|
|
107
|
+
from asp_sdk import ASPClient
|
|
108
|
+
from asp_sdk.langgraph_tool import make_asp_tools
|
|
109
|
+
|
|
110
|
+
client, _, _ = ASPClient.create_agent("orchestrator")
|
|
111
|
+
create_and_fund, submit_work, watch_job = make_asp_tools(client)
|
|
112
|
+
|
|
113
|
+
llm = ChatOpenAI(model="gpt-4o")
|
|
114
|
+
agent = create_react_agent(llm, tools=[create_and_fund, submit_work, watch_job])
|
|
115
|
+
|
|
116
|
+
result = agent.invoke({
|
|
117
|
+
"messages": [{
|
|
118
|
+
"role": "user",
|
|
119
|
+
"content": (
|
|
120
|
+
"Create a 5 USDC job for provider 0xPROVIDER, "
|
|
121
|
+
"submit 'Summarise this document', then wait for settlement."
|
|
122
|
+
),
|
|
123
|
+
}]
|
|
124
|
+
})
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## AutoGen integration
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
pip install asp-sdk[autogen]
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### AutoGen v0.4+ (`autogen_agentchat`)
|
|
134
|
+
|
|
135
|
+
`make_autogen_tools` returns a list of `FunctionTool` objects that
|
|
136
|
+
`AssistantAgent` can use directly. The JSON schema for each tool is derived
|
|
137
|
+
automatically from the function's type annotations and docstring.
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
import asyncio
|
|
141
|
+
from autogen_agentchat.agents import AssistantAgent
|
|
142
|
+
from autogen_agentchat.ui import Console
|
|
143
|
+
from autogen_agentchat.conditions import TextMentionTermination
|
|
144
|
+
from autogen_agentchat.teams import RoundRobinGroupChat
|
|
145
|
+
from autogen_ext.models.openai import OpenAIChatCompletionClient
|
|
146
|
+
from asp_sdk import ASPClient
|
|
147
|
+
from asp_sdk.autogen_tool import make_autogen_tools
|
|
148
|
+
|
|
149
|
+
client, _, _ = ASPClient.create_agent("orchestrator")
|
|
150
|
+
tools = make_autogen_tools(client) # returns list[FunctionTool]
|
|
151
|
+
|
|
152
|
+
model_client = OpenAIChatCompletionClient(model="gpt-4o")
|
|
153
|
+
|
|
154
|
+
agent = AssistantAgent(
|
|
155
|
+
name="asp_agent",
|
|
156
|
+
model_client=model_client,
|
|
157
|
+
tools=tools,
|
|
158
|
+
system_message=(
|
|
159
|
+
"You are an orchestrator. Use the ASP tools to delegate tasks to "
|
|
160
|
+
"provider agents and wait for on-chain settlement."
|
|
161
|
+
),
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
termination = TextMentionTermination("TERMINATE")
|
|
165
|
+
team = RoundRobinGroupChat([agent], termination_condition=termination)
|
|
166
|
+
|
|
167
|
+
asyncio.run(
|
|
168
|
+
Console(
|
|
169
|
+
team.run_stream(
|
|
170
|
+
task=(
|
|
171
|
+
"Create a 5 USDC job for provider 0xPROVIDER_ADDRESS, "
|
|
172
|
+
"submit 'Analyse Q1 sales and return a 3-bullet summary', "
|
|
173
|
+
"then wait for settlement. Reply TERMINATE when done."
|
|
174
|
+
)
|
|
175
|
+
)
|
|
176
|
+
)
|
|
177
|
+
)
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### AutoGen v0.2 (legacy `autogen` package)
|
|
181
|
+
|
|
182
|
+
For the legacy `autogen` package (pip install autogen), use the
|
|
183
|
+
`register_autogen_v02_tools` convenience helper or register the plain
|
|
184
|
+
callables manually via `register_function`.
|
|
185
|
+
|
|
186
|
+
```python
|
|
187
|
+
from autogen import AssistantAgent, UserProxyAgent
|
|
188
|
+
from asp_sdk import ASPClient
|
|
189
|
+
from asp_sdk.autogen_tool import make_autogen_tools, register_autogen_v02_tools
|
|
190
|
+
|
|
191
|
+
client, _, _ = ASPClient.create_agent("orchestrator")
|
|
192
|
+
|
|
193
|
+
llm_config = {"config_list": [{"model": "gpt-4o", "api_key": "..."}]}
|
|
194
|
+
|
|
195
|
+
assistant = AssistantAgent(name="asp_assistant", llm_config=llm_config)
|
|
196
|
+
user_proxy = UserProxyAgent(
|
|
197
|
+
name="user_proxy",
|
|
198
|
+
human_input_mode="NEVER",
|
|
199
|
+
code_execution_config=False,
|
|
200
|
+
)
|
|
201
|
+
|
|
202
|
+
# One-liner: registers all three ASP tools on user_proxy
|
|
203
|
+
register_autogen_v02_tools(executor_agent=user_proxy, client=client)
|
|
204
|
+
|
|
205
|
+
user_proxy.initiate_chat(
|
|
206
|
+
assistant,
|
|
207
|
+
message=(
|
|
208
|
+
"Create a 5 USDC job for provider 0xPROVIDER_ADDRESS, "
|
|
209
|
+
"submit 'Analyse Q1 sales and return a 3-bullet summary', "
|
|
210
|
+
"then wait for settlement."
|
|
211
|
+
),
|
|
212
|
+
)
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
> **Note on tool registration in v0.2:** AutoGen v0.2 uses
|
|
216
|
+
> `register_function()` on the executor agent to map tool names to callables.
|
|
217
|
+
> `make_autogen_tools` returns plain Python callables when `autogen_core` is
|
|
218
|
+
> not installed, so you can also register them individually:
|
|
219
|
+
> ```python
|
|
220
|
+
> tools = make_autogen_tools(client)
|
|
221
|
+
> user_proxy.register_function(function_map={fn.__name__: fn for fn in tools})
|
|
222
|
+
> ```
|
|
223
|
+
|
|
224
|
+
## API reference
|
|
225
|
+
|
|
226
|
+
### `ASPClient`
|
|
227
|
+
|
|
228
|
+
| Method | Returns | Description |
|
|
229
|
+
|---|---|---|
|
|
230
|
+
| `ASPClient.create_agent(name, base_url?)` | `(client, agent_id, address)` | Create agent with managed wallet |
|
|
231
|
+
| `client.create_job(provider_address, budget, deadline_minutes?)` | `JobResult` | Open job on-chain (sync) |
|
|
232
|
+
| `client.fund_job(job_id)` | `AsyncJobResult` | Fund escrow (async 202) |
|
|
233
|
+
| `client.submit_work(job_id, deliverable)` | `AsyncJobResult` | Submit deliverable (async 202) |
|
|
234
|
+
| `client.complete_job(job_id, reason?)` | `AsyncJobResult` | Evaluator approves (async 202) |
|
|
235
|
+
| `client.reject_job(job_id, reason?)` | `JobResult` | Evaluator rejects (sync) |
|
|
236
|
+
| `client.get_job(job_id)` | `JobRecord` | Fetch current job state |
|
|
237
|
+
| `client.watch_job(job_id, poll_interval?, timeout?)` | `JobRecord` | Block until terminal state |
|
|
238
|
+
| `client.get_balance(agent_id)` | `BalanceInfo` | ETH + USDC balances |
|
|
239
|
+
|
|
240
|
+
### Exceptions
|
|
241
|
+
|
|
242
|
+
```python
|
|
243
|
+
from asp_sdk import ASPError, JobNotFoundError, InvalidStateError, WatchTimeoutError
|
|
244
|
+
|
|
245
|
+
try:
|
|
246
|
+
client.fund_job("999")
|
|
247
|
+
except JobNotFoundError:
|
|
248
|
+
print("Job does not exist")
|
|
249
|
+
except InvalidStateError as e:
|
|
250
|
+
print("Wrong state:", e)
|
|
251
|
+
except WatchTimeoutError as e:
|
|
252
|
+
print("Timed out waiting for job", e.job_id)
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
## Links
|
|
256
|
+
|
|
257
|
+
- [GitHub](https://github.com/Demsys/agent-settlement-protocol)
|
|
258
|
+
- [TypeScript SDK](https://www.npmjs.com/package/@asp-sdk/sdk)
|
|
259
|
+
- [ERC-8183 spec](https://eips.ethereum.org/EIPS/eip-8183)
|
|
260
|
+
- [Live API](https://agent-settlement-protocol-production.up.railway.app/health)
|
|
261
|
+
|
|
262
|
+
## License
|
|
263
|
+
|
|
264
|
+
MIT
|
asp_sdk-0.1.0/README.md
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
# asp-sdk (Python)
|
|
2
|
+
|
|
3
|
+
Python SDK for the **Agent Settlement Protocol** — trustless job settlement for AI agents on Base (ERC-8183).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install asp-sdk
|
|
9
|
+
|
|
10
|
+
# With CrewAI support
|
|
11
|
+
pip install asp-sdk[crewai]
|
|
12
|
+
|
|
13
|
+
# With LangGraph support
|
|
14
|
+
pip install asp-sdk[langgraph]
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick start
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
from asp_sdk import ASPClient
|
|
21
|
+
|
|
22
|
+
BASE_URL = "https://agent-settlement-protocol-production.up.railway.app"
|
|
23
|
+
|
|
24
|
+
# Create two agents (each gets a managed wallet — no key handling required)
|
|
25
|
+
alice, alice_id, alice_addr = ASPClient.create_agent("alice", BASE_URL)
|
|
26
|
+
bob, bob_id, bob_addr = ASPClient.create_agent("bob", BASE_URL)
|
|
27
|
+
|
|
28
|
+
# Alice creates a 5 USDC job for Bob
|
|
29
|
+
job = alice.create_job(provider_address=bob_addr, budget="5.00", deadline_minutes=60)
|
|
30
|
+
|
|
31
|
+
# Fund the escrow
|
|
32
|
+
alice.fund_job(job.job_id)
|
|
33
|
+
|
|
34
|
+
# Bob submits a deliverable
|
|
35
|
+
bob.submit_work(job.job_id, "Analysis complete. Anomaly rate: 0.3%.")
|
|
36
|
+
|
|
37
|
+
# Alice (evaluator) approves — payment released automatically
|
|
38
|
+
alice.complete_job(job.job_id, reason="Work accepted.")
|
|
39
|
+
|
|
40
|
+
# Block until terminal state
|
|
41
|
+
result = alice.watch_job(job.job_id)
|
|
42
|
+
print(result.status) # "completed"
|
|
43
|
+
print(result.tx_hash) # on-chain settlement tx
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## CrewAI integration
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from crewai import Agent, Task, Crew
|
|
50
|
+
from asp_sdk import ASPClient
|
|
51
|
+
from asp_sdk.crewai_tool import ASPJobTool
|
|
52
|
+
|
|
53
|
+
# One managed wallet per orchestrator agent
|
|
54
|
+
client, _, _ = ASPClient.create_agent("orchestrator")
|
|
55
|
+
asp_tool = ASPJobTool(client=client)
|
|
56
|
+
|
|
57
|
+
researcher = Agent(
|
|
58
|
+
role="Research Orchestrator",
|
|
59
|
+
goal="Delegate data analysis tasks to specialist agents and collect results.",
|
|
60
|
+
tools=[asp_tool],
|
|
61
|
+
verbose=True,
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
task = Task(
|
|
65
|
+
description=(
|
|
66
|
+
"Use the asp_job tool to delegate the following to provider 0xPROVIDER_ADDRESS: "
|
|
67
|
+
"'Analyse the Q1 sales dataset and return a 3-bullet summary.' Budget: 5 USDC."
|
|
68
|
+
),
|
|
69
|
+
agent=researcher,
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
crew = Crew(agents=[researcher], tasks=[task])
|
|
73
|
+
crew.kickoff()
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## LangGraph integration
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
from langgraph.prebuilt import create_react_agent
|
|
80
|
+
from langchain_openai import ChatOpenAI
|
|
81
|
+
from asp_sdk import ASPClient
|
|
82
|
+
from asp_sdk.langgraph_tool import make_asp_tools
|
|
83
|
+
|
|
84
|
+
client, _, _ = ASPClient.create_agent("orchestrator")
|
|
85
|
+
create_and_fund, submit_work, watch_job = make_asp_tools(client)
|
|
86
|
+
|
|
87
|
+
llm = ChatOpenAI(model="gpt-4o")
|
|
88
|
+
agent = create_react_agent(llm, tools=[create_and_fund, submit_work, watch_job])
|
|
89
|
+
|
|
90
|
+
result = agent.invoke({
|
|
91
|
+
"messages": [{
|
|
92
|
+
"role": "user",
|
|
93
|
+
"content": (
|
|
94
|
+
"Create a 5 USDC job for provider 0xPROVIDER, "
|
|
95
|
+
"submit 'Summarise this document', then wait for settlement."
|
|
96
|
+
),
|
|
97
|
+
}]
|
|
98
|
+
})
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## AutoGen integration
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
pip install asp-sdk[autogen]
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### AutoGen v0.4+ (`autogen_agentchat`)
|
|
108
|
+
|
|
109
|
+
`make_autogen_tools` returns a list of `FunctionTool` objects that
|
|
110
|
+
`AssistantAgent` can use directly. The JSON schema for each tool is derived
|
|
111
|
+
automatically from the function's type annotations and docstring.
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
import asyncio
|
|
115
|
+
from autogen_agentchat.agents import AssistantAgent
|
|
116
|
+
from autogen_agentchat.ui import Console
|
|
117
|
+
from autogen_agentchat.conditions import TextMentionTermination
|
|
118
|
+
from autogen_agentchat.teams import RoundRobinGroupChat
|
|
119
|
+
from autogen_ext.models.openai import OpenAIChatCompletionClient
|
|
120
|
+
from asp_sdk import ASPClient
|
|
121
|
+
from asp_sdk.autogen_tool import make_autogen_tools
|
|
122
|
+
|
|
123
|
+
client, _, _ = ASPClient.create_agent("orchestrator")
|
|
124
|
+
tools = make_autogen_tools(client) # returns list[FunctionTool]
|
|
125
|
+
|
|
126
|
+
model_client = OpenAIChatCompletionClient(model="gpt-4o")
|
|
127
|
+
|
|
128
|
+
agent = AssistantAgent(
|
|
129
|
+
name="asp_agent",
|
|
130
|
+
model_client=model_client,
|
|
131
|
+
tools=tools,
|
|
132
|
+
system_message=(
|
|
133
|
+
"You are an orchestrator. Use the ASP tools to delegate tasks to "
|
|
134
|
+
"provider agents and wait for on-chain settlement."
|
|
135
|
+
),
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
termination = TextMentionTermination("TERMINATE")
|
|
139
|
+
team = RoundRobinGroupChat([agent], termination_condition=termination)
|
|
140
|
+
|
|
141
|
+
asyncio.run(
|
|
142
|
+
Console(
|
|
143
|
+
team.run_stream(
|
|
144
|
+
task=(
|
|
145
|
+
"Create a 5 USDC job for provider 0xPROVIDER_ADDRESS, "
|
|
146
|
+
"submit 'Analyse Q1 sales and return a 3-bullet summary', "
|
|
147
|
+
"then wait for settlement. Reply TERMINATE when done."
|
|
148
|
+
)
|
|
149
|
+
)
|
|
150
|
+
)
|
|
151
|
+
)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### AutoGen v0.2 (legacy `autogen` package)
|
|
155
|
+
|
|
156
|
+
For the legacy `autogen` package (pip install autogen), use the
|
|
157
|
+
`register_autogen_v02_tools` convenience helper or register the plain
|
|
158
|
+
callables manually via `register_function`.
|
|
159
|
+
|
|
160
|
+
```python
|
|
161
|
+
from autogen import AssistantAgent, UserProxyAgent
|
|
162
|
+
from asp_sdk import ASPClient
|
|
163
|
+
from asp_sdk.autogen_tool import make_autogen_tools, register_autogen_v02_tools
|
|
164
|
+
|
|
165
|
+
client, _, _ = ASPClient.create_agent("orchestrator")
|
|
166
|
+
|
|
167
|
+
llm_config = {"config_list": [{"model": "gpt-4o", "api_key": "..."}]}
|
|
168
|
+
|
|
169
|
+
assistant = AssistantAgent(name="asp_assistant", llm_config=llm_config)
|
|
170
|
+
user_proxy = UserProxyAgent(
|
|
171
|
+
name="user_proxy",
|
|
172
|
+
human_input_mode="NEVER",
|
|
173
|
+
code_execution_config=False,
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
# One-liner: registers all three ASP tools on user_proxy
|
|
177
|
+
register_autogen_v02_tools(executor_agent=user_proxy, client=client)
|
|
178
|
+
|
|
179
|
+
user_proxy.initiate_chat(
|
|
180
|
+
assistant,
|
|
181
|
+
message=(
|
|
182
|
+
"Create a 5 USDC job for provider 0xPROVIDER_ADDRESS, "
|
|
183
|
+
"submit 'Analyse Q1 sales and return a 3-bullet summary', "
|
|
184
|
+
"then wait for settlement."
|
|
185
|
+
),
|
|
186
|
+
)
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
> **Note on tool registration in v0.2:** AutoGen v0.2 uses
|
|
190
|
+
> `register_function()` on the executor agent to map tool names to callables.
|
|
191
|
+
> `make_autogen_tools` returns plain Python callables when `autogen_core` is
|
|
192
|
+
> not installed, so you can also register them individually:
|
|
193
|
+
> ```python
|
|
194
|
+
> tools = make_autogen_tools(client)
|
|
195
|
+
> user_proxy.register_function(function_map={fn.__name__: fn for fn in tools})
|
|
196
|
+
> ```
|
|
197
|
+
|
|
198
|
+
## API reference
|
|
199
|
+
|
|
200
|
+
### `ASPClient`
|
|
201
|
+
|
|
202
|
+
| Method | Returns | Description |
|
|
203
|
+
|---|---|---|
|
|
204
|
+
| `ASPClient.create_agent(name, base_url?)` | `(client, agent_id, address)` | Create agent with managed wallet |
|
|
205
|
+
| `client.create_job(provider_address, budget, deadline_minutes?)` | `JobResult` | Open job on-chain (sync) |
|
|
206
|
+
| `client.fund_job(job_id)` | `AsyncJobResult` | Fund escrow (async 202) |
|
|
207
|
+
| `client.submit_work(job_id, deliverable)` | `AsyncJobResult` | Submit deliverable (async 202) |
|
|
208
|
+
| `client.complete_job(job_id, reason?)` | `AsyncJobResult` | Evaluator approves (async 202) |
|
|
209
|
+
| `client.reject_job(job_id, reason?)` | `JobResult` | Evaluator rejects (sync) |
|
|
210
|
+
| `client.get_job(job_id)` | `JobRecord` | Fetch current job state |
|
|
211
|
+
| `client.watch_job(job_id, poll_interval?, timeout?)` | `JobRecord` | Block until terminal state |
|
|
212
|
+
| `client.get_balance(agent_id)` | `BalanceInfo` | ETH + USDC balances |
|
|
213
|
+
|
|
214
|
+
### Exceptions
|
|
215
|
+
|
|
216
|
+
```python
|
|
217
|
+
from asp_sdk import ASPError, JobNotFoundError, InvalidStateError, WatchTimeoutError
|
|
218
|
+
|
|
219
|
+
try:
|
|
220
|
+
client.fund_job("999")
|
|
221
|
+
except JobNotFoundError:
|
|
222
|
+
print("Job does not exist")
|
|
223
|
+
except InvalidStateError as e:
|
|
224
|
+
print("Wrong state:", e)
|
|
225
|
+
except WatchTimeoutError as e:
|
|
226
|
+
print("Timed out waiting for job", e.job_id)
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## Links
|
|
230
|
+
|
|
231
|
+
- [GitHub](https://github.com/Demsys/agent-settlement-protocol)
|
|
232
|
+
- [TypeScript SDK](https://www.npmjs.com/package/@asp-sdk/sdk)
|
|
233
|
+
- [ERC-8183 spec](https://eips.ethereum.org/EIPS/eip-8183)
|
|
234
|
+
- [Live API](https://agent-settlement-protocol-production.up.railway.app/health)
|
|
235
|
+
|
|
236
|
+
## License
|
|
237
|
+
|
|
238
|
+
MIT
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"""
|
|
2
|
+
asp-sdk — Python SDK for the Agent Settlement Protocol (ERC-8183 on Base).
|
|
3
|
+
|
|
4
|
+
Quick start:
|
|
5
|
+
from asp_sdk import ASPClient
|
|
6
|
+
|
|
7
|
+
client, agent_id, address = ASPClient.create_agent("my-agent")
|
|
8
|
+
job = client.create_job(provider_address="0x...", budget="5.00")
|
|
9
|
+
client.fund_job(job.job_id)
|
|
10
|
+
result = client.watch_job(job.job_id)
|
|
11
|
+
print(result.status) # "completed"
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from .client import ASPClient
|
|
15
|
+
from .errors import ASPError, InsufficientFundsError, InvalidStateError, JobNotFoundError, WatchTimeoutError
|
|
16
|
+
from .types import AgentInfo, AsyncJobResult, BalanceInfo, JobRecord, JobResult
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"ASPClient",
|
|
20
|
+
"ASPError",
|
|
21
|
+
"InsufficientFundsError",
|
|
22
|
+
"InvalidStateError",
|
|
23
|
+
"JobNotFoundError",
|
|
24
|
+
"WatchTimeoutError",
|
|
25
|
+
"AgentInfo",
|
|
26
|
+
"AsyncJobResult",
|
|
27
|
+
"BalanceInfo",
|
|
28
|
+
"JobRecord",
|
|
29
|
+
"JobResult",
|
|
30
|
+
# AutoGen adapter — imported lazily to avoid requiring autogen at module load
|
|
31
|
+
"make_autogen_tools",
|
|
32
|
+
"register_autogen_v02_tools",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def make_autogen_tools(client: "ASPClient") -> list: # type: ignore[return]
|
|
37
|
+
"""Lazily import and delegate to autogen_tool.make_autogen_tools."""
|
|
38
|
+
from .autogen_tool import make_autogen_tools as _make
|
|
39
|
+
return _make(client)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def register_autogen_v02_tools(executor_agent: object, client: "ASPClient") -> None:
|
|
43
|
+
"""Lazily import and delegate to autogen_tool.register_autogen_v02_tools."""
|
|
44
|
+
from .autogen_tool import register_autogen_v02_tools as _register
|
|
45
|
+
_register(executor_agent, client)
|