Crew-level spending budgets and one-transaction settlement for agents paying over x402 — proposing a langchain-foliant tool

We’re building Foliant, an open protocol (Apache-2.0, no token) for AI agent crews that pay for tools, data and inference over x402. Two things it adds that langchain-x402 and per-call wallets don’t:

  • A budget for the crew, not a wallet per agent. A supervisor holds the crew’s budget and delegates a cap to each subagent (the caps can differ); every spend is checked against the subagent’s cap and every ancestor’s, so a subagent can never exceed its limit and the crew can never exceed the supervisor’s, even after the supervisor tightens it. The supervisor revokes a subagent and recalls its balance with its own key, no human in the loop.
  • One settlement per crew session. Subagents pay per call through a shared pool; the provider settles the whole crew in one transaction; any subagent can exit alone if the provider goes silent.

It maps onto the subagents (supervisor) pattern directly: the supervisor is the budget holder, subagents are the workers. The wire format is unchanged x402, so it sits beside langchain-x402 rather than replacing it, on the chains people already use (Base, Avalanche first).

Status: Python reference implementation with 34 tests and a two-minute demo (https://foliant.network, GitHub - gazoy/concord: Reference implementation of the Foliant agent-payments layer: policy-bounded agent accounts, payment channels and pools, x402-compatible metering. · GitHub); Solidity contracts and an x402 scheme proposal are the next phase.

We’d like to publish this as a langchain-foliant package exposing a payment tool and a budget middleware, and list it through the integration-listing issue. Before we do, two questions for anyone running supervised multi-agent setups that pay for external calls:

  1. How do you bound spend today — a shared key, a wallet per agent, or an off-chain policy service? What breaks?
  2. Would the natural surface be a tool the subagent calls to pay, a middleware on the supervisor that enforces budgets on every tool call, or both?

Happy to share the demo or a draft of the package with anyone who wants to try it.

Read through concord, mostly the contracts. Worth spelling out for people setting caps: the cap is checked when a subagent opens a channel or deposits into a pool, against the whole deposit, not per call. After that it’s off-chain updates against escrow. So recall only takes the subagent’s free balance, and if you revoke it by rotating its signer, the old key can still sign updates to that payee up to the full deposit until the close finishes, at least timeoutSecs after beginClose. That’s on purpose so the provider keeps what it’s owed, but the subagent picks timeoutSecs when it opens, up to 30 days.

So in practice the per agent limit is deposit size and channel timeout. On your second question I’d do both, but let the supervisor middleware own those two values and give the subagent a pay tool that can’t set them.

The cap also bounds how much, not who. payTo in a 402 comes from whatever server the agent is calling, so a subagent reading untrusted pages can be talked into opening a channel to anyone within its cap. You already have allow lists with the subset check in _within, I’d make them the default for any subagent that reads outside content.

The independent exit is the bit I’m curious about. If one subagent pulls out because the provider went quiet, does it only take its own share of the pool, or does the rest of the crew have to pause payments while that settles?

@gazoy one case i’d add next to capitaharlock’s exit question: the pay call where the payment lands but the response is lost. if channel updates are cumulative with a nonce, resending the same signed update is harmless. the risk is a subagent that treats the timeout as a failure and signs a fresh increment for the same call, and both spends still fit under the cap, so the budget check won’t flag it. what fixed this in my harness was minting the idempotency key before the first attempt, so a retry reuses it whatever args the model regenerates. but it only dedupes where the key is stored, and for an external charge the provider side has to honor it. does x402 give you a field to carry a key the provider will dedupe on, or would foliant track it on the pool side?