ag-ui-protocol / ag-ui-protocol/ag-ui
Community Integration: AgentPay x402 — Payment middleware for AG-UI agents
- Lenguaje dominante
- Python
- Estrellas
- 15.9k
- Forks
- 1.4k
- Merge medio
- 1 d 17 h
- PR fusionados (30 d)
- 163
Descripción
## New Community Integration Submission
**Integration:** `agentpay-x402`
**Category:** Payment Middleware
**Status:** Community
---
### What is it?
A drop-in middleware for AG-UI that automatically handles HTTP 402 Payment Required responses during agent tool calls — settling on Base L2 via [AgentPay](https://x402-agent-pay.com) and streaming 4 payment lifecycle events into the AG-UI event stream.
**Repository:** https://github.com/shawnhvac/ag-ui-agentpay-x402
**PyPI:** `pip install ag-ui-agentpay-x402` _(pending PyPI publish)_
---
### Why it fits AG-UI
AG-UI handles the agent ↔ UI interaction layer brilliantly. The missing piece: when agents call **paid external APIs** (data, AI inference, scraping, enrichment), there's no payment primitive in the event stream. The frontend has no visibility into payments happening mid-run.
`agentpay-x402` closes that gap — no changes needed to existing agent code.
---
### How it works
```python
from ag_ui_agentpay import add_agentpay_middleware
# One line — that's it
payment = add_agentpay_middleware(app, cap_usdc=5.00, chain="base")
@app.post("/agent")
async def agent_endpoint(request: Request):
async def stream():
async for event in payment.wrap(my_agent.run(body), thread_id, run_id):
yield {"data": json.dumps(event)}
return EventSourceResponse(stream())
```
---
### Payment Event Types
Four new events flow into the AG-UI stream:
| Event | When | Frontend shows |
|-------|------|----------------|
| `PAYMENT_REQUIRED` | Agent hits a paid API | Amount + service name |
| `PAYMENT_PROCESSING` | Settling on Base L2 | Spinner |
| `PAYMENT_CONFIRMED` | Confirmed, agent resumes | TX hash + remaining budget |
| `PAYMENT_FAILED` | Budget exceeded / error | Error + prompt |
---
### Features
- ✅ **Drop-in** — wraps any AG-UI `AsyncGenerator`, no agent changes
- ✅ **Budget guardrails** — per-run USDC cap, auto-blocks on exceed
- ✅ **Base L2 settlement** — ~2s finality, zero platform fee
- ✅ **Multi-chain** — Base, Solana, XRPL
- ✅ **ClawCredit compatible** — agents without wallets can use credit lines
- ✅ **FastAPI helpers** — `/agentpay/budget` and `/agentpay/status` endpoints
- ✅ **Full test suite** included
---
### Compatible with any AG-UI framework
Works with LangGraph, CrewAI, Google ADK, Mastra, PydanticAI, and any other AG-UI-compatible agent backend — middleware is framework-agnostic.
---
### x402 Service Directory
Any service returning HTTP 402 with a valid x402 header works automatically. Browse at [x402scan.com](https://x402scan.com).
---
Happy to add a TypeScript implementation and demo app for the AG-UI Dojo if that would help with inclusion. Let me know what else would be useful!
Guía de contribución
Evaluación
Este issue todavía no se ha evaluado.