Skip to content

Commit 7e17376

Browse files
author
up2itnow0822
committed
feat(tools): add AgentPay x402 payment tools for ADK agents
Adds AgentPay tools that enable ADK agents to make autonomous HTTP payments using the x402 protocol (HTTP 402 Payment Required). Tools added: - fetch_paid_api: Fetch a URL, auto-paying any x402 402 challenge - get_wallet_info: Return wallet address, USDC balance, spend limits - check_spend_limit: Pre-check payment against on-chain spend limits - send_payment: Send USDC directly within autonomous spend policy Implementation wraps the agentpay-mcp MCP server via stdio subprocess (standard MCP transport). No custodian; non-custodial smart contract wallet on Base. Spend limits enforced on-chain before any signing. Standalone package: npm: https://www.npmjs.com/package/agentpay-mcp (patent pending) sdk: https://www.npmjs.com/package/agentwallet-sdk See contributing/tools/agentpay/README.md for setup and usage.
1 parent 0d10dd9 commit 7e17376

7 files changed

Lines changed: 1031 additions & 0 deletions

File tree

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# AgentPay x402 Payment Tools for Google ADK
2+
3+
Enable Google ADK agents to make autonomous HTTP payments using the
4+
[x402 payment protocol](https://www.x402.org/) — HTTP 402 Payment Required,
5+
handled automatically.
6+
7+
Powered by [agentpay-mcp](https://www.npmjs.com/package/agentpay-mcp) and
8+
[agentwallet-sdk](https://www.npmjs.com/package/agentwallet-sdk) (patent pending).
9+
10+
## What is x402?
11+
12+
x402 is an open protocol that revives HTTP's original `402 Payment Required`
13+
status code. When an agent hits a paid API endpoint, the server returns a 402
14+
with payment details. The agent's wallet pays automatically and retries the
15+
request — no manual intervention, no API keys for every service.
16+
17+
## What is AgentPay?
18+
19+
AgentPay is a non-custodial smart contract wallet system for AI agents. Wallet
20+
ownership is represented by an NFT — your agent controls funds without a
21+
custodian. On-chain **spend limits** cap per-transaction and daily totals,
22+
protecting against runaway agent behavior.
23+
24+
- **Chain:** Base (live), multi-chain coming
25+
- **Protocol:** x402 / HTTP 402
26+
- **NPM:** [`agentpay-mcp`](https://www.npmjs.com/package/agentpay-mcp) v4.0.0
27+
- **SDK:** [`agentwallet-sdk`](https://www.npmjs.com/package/agentwallet-sdk) v6.0.4
28+
- **Status:** Patent pending
29+
30+
## Installation
31+
32+
```bash
33+
# Python ADK package
34+
pip install google-adk-community
35+
36+
# AgentPay MCP server (requires Node.js ≥ 18)
37+
npm install -g agentpay-mcp
38+
```
39+
40+
## Setup
41+
42+
```bash
43+
# Your AgentPay wallet private key (non-custodial)
44+
export AGENTPAY_PRIVATE_KEY="0x..."
45+
46+
# Optional: custom RPC endpoint (defaults to Base mainnet)
47+
export AGENTPAY_RPC_URL="https://mainnet.base.org"
48+
```
49+
50+
Get a wallet at [agentpay.xyz](https://agentpay.xyz) or via the
51+
`agentwallet-sdk` CLI.
52+
53+
## Usage
54+
55+
```python
56+
from google.adk.agents import Agent
57+
from google.adk_community.tools.agentpay import (
58+
fetch_paid_api,
59+
get_wallet_info,
60+
check_spend_limit,
61+
send_payment,
62+
)
63+
64+
agent = Agent(
65+
model="gemini-2.0-flash",
66+
name="payment_agent",
67+
description="An agent that can pay for API access autonomously using x402",
68+
tools=[fetch_paid_api, get_wallet_info, check_spend_limit, send_payment],
69+
)
70+
71+
# The agent can now call paid APIs, check its wallet, and send payments
72+
response = agent.run(
73+
"Fetch the latest market data from https://api.example.com/market"
74+
" and check my remaining daily spend limit."
75+
)
76+
```
77+
78+
## Available Tools
79+
80+
| Tool | Description |
81+
|------|-------------|
82+
| `fetch_paid_api` | Make an HTTP request; auto-pay x402 challenge if needed and retry |
83+
| `get_wallet_info` | Return wallet address, USDC balance, spend limits, and remaining allowance |
84+
| `check_spend_limit` | Pre-check whether a payment amount is within on-chain spend limits |
85+
| `send_payment` | Send USDC directly to an address within autonomous spend policy |
86+
87+
## How `fetch_paid_api` Works
88+
89+
```
90+
Agent calls fetch_paid_api(url="https://paid-api.example.com/data")
91+
92+
├─ agentpay-mcp sends GET /data
93+
│ Server returns HTTP 402 + payment details
94+
95+
├─ agentpay-mcp pays on-chain (Base, USDC)
96+
│ On-chain spend limit checked before signing
97+
98+
└─ agentpay-mcp retries GET /data with payment proof
99+
Server returns 200 + data → returned to agent
100+
```
101+
102+
## Security Model
103+
104+
- **Non-custodial** — private key stays in your environment; no third party holds funds
105+
- **On-chain spend limits** — per-transaction and daily caps enforced by smart contract
106+
- **NFT ownership** — wallet controlled by NFT; rotate ownership without moving funds
107+
- **Audit trail** — every payment recorded on-chain
108+
109+
## Links
110+
111+
- [AgentPay NPM](https://www.npmjs.com/package/agentpay-mcp)
112+
- [agentwallet-sdk NPM](https://www.npmjs.com/package/agentwallet-sdk)
113+
- [x402 Protocol](https://www.x402.org/)
114+
- [ADK Integrations](https://google.github.io/adk-docs/integrations/)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""AgentPay x402 payment tools for Google ADK.
16+
17+
Enables ADK agents to make autonomous HTTP payments using the x402 protocol
18+
(HTTP 402 Payment Required) via the agentpay-mcp MCP server.
19+
20+
See: https://www.npmjs.com/package/agentpay-mcp
21+
"""
22+
23+
from .agentpay_tools import check_spend_limit
24+
from .agentpay_tools import fetch_paid_api
25+
from .agentpay_tools import get_wallet_info
26+
from .agentpay_tools import send_payment
27+
28+
__all__ = [
29+
"fetch_paid_api",
30+
"get_wallet_info",
31+
"check_spend_limit",
32+
"send_payment",
33+
]

0 commit comments

Comments
 (0)