Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ markers = [
dev = [
"ruff>=0.13.2",
"mypy>=1.8.0",
"marimo>=0.11.31",
]
12 changes: 12 additions & 0 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ a2a_app = to_a2a(agent, host="localhost", port=8001)
# uvicorn module:a2a_app --host 0.0.0.0 --port 8001
```

## Using Marimo notebooks
Marimo notebooks provide an interactive python development environment that lets you create and share interactive
notebooks with your team. It's a great place to experiment with the x402-enabled agent using the Python SDK.

Start up a marimo workspace editor
```bash
uv run marimo edit
```

The Marimo app will open a new browser tab where you can create a new notebook, view helpful resources, and
browse existing notebooks in the workspace.

## Core Concepts

### X402Treasurer
Expand Down
138 changes: 138 additions & 0 deletions python/notebooks/example_notebook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import marimo

__generated_with = "0.18.4"
app = marimo.App(width="medium")


@app.cell(hide_code=True)
def _(mo):
mo.md(r"""
**PREQUISITE**:

Get configs and keys from the ampersend dashboard and set them to local environment variables, so this notebook can access them
- `AMPERSEND_STAGING_SESSION_KEY`
- `AMPERSEND_STAGING_SMART_ACCOUNT_ADDRESS`
- `AMPERSEND_STAGING_SESSION_KEY_PK`
""")
return


@app.cell(hide_code=True)
def _(mo):
mo.md(r"""
# Imports
""")
return


@app.cell
def _():
import marimo as mo
import os
return mo, os


@app.cell
def _():
from ampersend_sdk.a2a.client import X402RemoteA2aAgent
from ampersend_sdk.ampersend import AmpersendTreasurer, ApiClient, ApiClientOptions
from ampersend_sdk.x402.wallets.smart_account import SmartAccountWallet
from ampersend_sdk.smart_account import SmartAccountConfig
return (
AmpersendTreasurer,
ApiClient,
ApiClientOptions,
SmartAccountConfig,
SmartAccountWallet,
X402RemoteA2aAgent,
)


@app.cell(hide_code=True)
def _(mo):
mo.md(r"""
# Configure & instantiate
""")
return


@app.cell
def _(os):
session_key = os.environ.get("AMPERSEND_STAGING_SESSION_KEY")
smart_account_address = os.environ.get("AMPERSEND_STAGING_SMART_ACCOUNT_ADDRESS")
session_key_private_key = os.environ.get("AMPERSEND_STAGING_SESSION_KEY_PK")
return session_key, session_key_private_key, smart_account_address


@app.cell
def _(
SmartAccountConfig,
SmartAccountWallet,
session_key,
smart_account_address,
):
# Create Smart Account wallet
wallet = SmartAccountWallet(
config=SmartAccountConfig(
session_key=session_key, # From staging dashboard
smart_account_address=smart_account_address, # From staging dashboard
)
)
return (wallet,)


@app.cell
def _(
AmpersendTreasurer,
ApiClient,
ApiClientOptions,
session_key_private_key,
wallet,
):
# Create Ampersend treasurer (with spend limits & monitoring)
treasurer = AmpersendTreasurer(
api_client=ApiClient(
options=ApiClientOptions(
base_url="https://api.staging.ampersend.ai",
session_key_private_key=session_key_private_key
)
),
wallet=wallet
)
return (treasurer,)


@app.cell
def _(X402RemoteA2aAgent, treasurer):
# Create agent pointing to staging service (testnet, rate-limited)
agent = X402RemoteA2aAgent(
treasurer=treasurer,
name="my_agent",
agent_card="https://subgraph-a2a.x402.staging.thegraph.com/.well-known/agent-card.json"
)
return (agent,)


@app.cell(hide_code=True)
def _(mo):
mo.md(r"""
# Use agent
(payments handled automatically with spend limits)
""")
return


@app.cell
async def _(agent):
async for result in agent.run_async("Query Uniswap V3 pools on Base Sepolia"):
print(result)
return


@app.cell
def _():
return


if __name__ == "__main__":
app.run()
Loading
Loading