A single ledger for every agent wallet. Fast cash path, held escrow, and compensating refunds — so a failed job never leaves funds stranded.
Additive D1 indexes only. No columns dropped, no constraints changed, no features removed. Every hot path — ledger lists, escrow expire, velocity gates, streams, bonds, sagas, tickets — now hits a covering index instead of a table scan.
Time-ordered lists, from/to repo filters, success-only volume scans, idempotency key lookups, and optional trace_id correlation — all index-backed.
Cron finds held rows by expires_at without scanning open escrows. Dashboard lists by from_repo / to_repo + status stay O(log n).
Every pay hits velocity_events by repo_id + created_at. Safety event feeds per agent are ordered and ready for the dashboard.
Open streams and open sub-wallets resolve by status + expires_at. Parent-repo lists stay fast even when many ephemeral wallets exist.
Committed pays, open/matched bonds, and active sagas all carry expire indexes. Cron batches and agent dashboards no longer table-scan these tables.
Capability tickets by holder + status, webhook delivery history by user, API key lists by user, and session cleanup by expires_at — all indexed.
Indexes are pure additive IF NOT EXISTS.
Safe to re-run. The same SQL that powered the ledger still works — it just runs faster
when agents, crons, and dashboards hit the hottest paths at the same time.
The entire settlement surface lives inside a single Cloudflare Worker bound to the `a2a-ledger` database. No queues to a central bank. No human approval step.
Every request hits the same process that already holds the session, key, and safety state.
Balances, holds, streams, receipts and velocity events all live in one SQLite-compatible edge DB.
Daily budget, velocity windows, wallet lock and key suspend run before any debit is written.
Identity is the GitHub-style string. Keys rotate; the agent id does not.
Every settle, hold, stream meter or sub-wallet spend follows the same edge path. Nothing is deferred to a human or a distant region.
Session cookie or Authorization: Bearer key is resolved. Suspended keys are rejected before anything else runs.
Wallet lock, daily budget, velocity windows and policy-as-code (allow_to, deny_to, max_amount) are evaluated against the from_repo.
Optional Idempotency-Key is checked. Fixed-window rate limits on the key and on the repo protect the ledger from runaway loops.
Balance is debited and credited inside D1 in a single logical step. Escrow holds, stream meters and sub-wallet spends all reuse the same account table.
A signed receipt is stored. If the owner configured a webhook, the edge fires payment.success (or the matching event) with a short timeout.
Data model
Balances, holds, streams, sub-wallets, velocity events, policies and receipts share the same edge SQLite surface. No secondary store is required for settlement.
Every owner/repo has a single balance row. Debits and credits are atomic updates against this table.
Funds are locked with an expiry. Cron or explicit release/refund moves them. Unclaimed holds auto-expire.
Budget is held, then dripped as units are metered. Stop anytime and the remainder is refunded.
Parent funds a capped child wallet with its own TTL. Perfect for task-scoped spend.
Daily budget, velocity windows, lock flag and lock reason sit on the agent, not on the human.
Every successful settle can emit a verifiable receipt. Agents can later prove what was paid.
One runaway repo cannot burn another. Caps, velocity, locks and policy sit on the owner/repo itself. Switching humans does not reset them.
Spend ceilings reset each UTC day. Sliding windows bound both transaction count and dollar volume so bursts stay contained.
A spike or policy breach can freeze the whole agent or just one credential. The ledger keeps the identity; only the debit path is closed.
Allow lists, deny lists, max amount and required task prefixes are evaluated on every debit before the balance is touched.
Sudden spikes (transactions per second) trigger an automatic kill-switch: the key is suspended and the wallet is locked in the same edge pass.
Traditional rails
Wallets, KYC, processor cut, regional data centres and manual risk review all sit between two agents that only wanted to settle.
AgentPay edge
Cloudflare Worker + D1 means the authentication, safety gate, balance write and receipt all execute within a few milliseconds of the agent that called.
Beyond simple pay, the edge exposes hold, stream and ephemeral child wallets. All of them reuse the same accounts table and the same safety gate.
Lock funds with a TTL. Release when the work is done, refund if it fails, or let the hold expire on its own. No manual release required.
Hold a budget, then drip pay as units are metered. Stop at any moment and the remainder returns automatically. Built for live tasks.
Parent funds a capped child with its own TTL. Perfect for task-scoped spend so a runaway child cannot touch the main balance.
Autonomy
No human has to release a stuck hold or watch a budget. Scheduled jobs and outbound webhooks keep the ledger honest while agents sleep.
A scheduled Worker task sweeps expired holds and sub-wallets in batches. Funds return to the parent without any API call from the agent.
Owners can register one HTTPS endpoint. The edge POSTs signed events with a short timeout so a slow receiver never blocks settlement.
owner/repo is the only durable identity. Everything else — sessions, API keys, policies, limits — attaches to that string. Humans never become the account.
A user signs in and binds a default agent. From that moment the ledger treats owner/repo as the account holder.
Create, revoke or suspend credentials without touching the balance or the policy that already sits on the agent.
Allow lists, caps and task prefixes live on the repo. Switching which human is logged in does not reset them.
The real shift
When the ledger, the safety gate, the identity and the expiry all live at the edge, agents no longer need to pretend they are people. What remains is only the settle.
Now
Bind a repo. Send a POST. Agents settle — humans stay out of the way.
Join AgentPay│