feat: @x402/mnemopay — economic memory for AI agent payments#1904
feat: @x402/mnemopay — economic memory for AI agent payments#1904t49qnsx7qt-kpanks wants to merge 1 commit intox402-foundation:mainfrom
Conversation
AI agents using x402 today are stateless — they pay and forget. This package layers MnemoPay's economic memory on top of x402 payment flows so agents remember costs, track endpoint reliability, and build reputation from real payment outcomes. - withMnemoPay() wraps any x402-enabled fetch with memory operations - Before each request: recall() checks past payment experiences - On success: settle() reinforces the positive memory (+reputation) - On failure: refund() docks the memory (-reputation) - recallEndpointInsight() surfaces cost history and success rates - Full test suite with 14 tests covering all payment flow paths - Follows existing x402 package structure (tsup, vitest, eslint) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
🟡 Heimdall Review Status
|
|
@t49qnsx7qt-kpanks is attempting to deploy a commit to the Coinbase Team on Vercel. A member of the Team first needs to authorize it. |
|
Hey team! Added a live interactive demo to the PR description: try it here. It shows the feedback loop in action — an agent hiring freelancers, learning from settlements and refunds, and consistently picking the best value by round 7-8. The core idea: |
|
One pattern we're exploring for agent-to-agent payment contexts: if the payer agent is operating through a managed custody layer (rather than controlling its own signing key), the PAYMENT-SIGNATURE header is technically signed by the custodian infrastructure, not the agent's x402 identity. This creates an attribution gap where the payment is valid on-chain but the agent's reputation history in ERC-8004 doesn't accrue correctly. |
Summary
AI agents using x402 today are stateless — they pay the 402, get the resource, and immediately forget. They never learn which endpoints are cheap, which are reliable, or which alternatives exist. This PR adds @x402/mnemopay, a middleware package that gives x402 agents economic memory via MnemoPay.
What it does
withMnemoPay()wraps any x402-enabled fetch function and adds four memory operations around each payment:recall()charge()settle()→ +reputationrefund()→ -reputationOver time, agents build a knowledge base of endpoint costs, reliability rates, and alternatives — turning every payment into a learning event.
Why this matters
The x402 protocol is uniquely positioned for AI-native commerce. But stateless payments leave value on the table. An agent that remembers its payment history can:
Usage
Package details
typescript/packages/http/mnemopay/@mnemopay/sdkis a peer dependency — no new runtime deps in x402 coreMnemoPayAgentinterface so users can bring their own implementationTest plan
withMnemoPay()passes through non-402 responses unchangedrecall()is called before each request with the endpoint URLsettle()is called on successful paymentsrefund()is called on failed paymentstsupand follows the existing dual CJS/ESM export pattern@x402/fetchand@x402/axioswrapped functions🤖 Generated with Claude Code
Live Demo
Try it now: https://t49qnsx7qt-kpanks.github.io/mnemopay-demo/
The Feedback Loop in 30 Seconds
How it works
5-line integration