langchain-foliant
Listed in LangChain's integration directory (langchain-ai/docs#6306). Works against the Foliant reference node and, through foliant-protocol[chain], the contracts on Avalanche Fuji.
Foliant for LangChain: a payment tool for agents that pay x402 endpoints, and a middleware that enforces the agent's spending budget on every paid tool call. Built for the supervisor / subagents pattern: the supervisor holds the crew's budget, each subagent gets a delegated cap, and every spend is checked against every level.
pip install langchain-foliant # pulls in foliant-protocol, the reference implementation
What it does
FoliantPaymentTool— calls an HTTP endpoint that charges per request over x402. On a 402 it opens a payment channel to, or joins the pool of, the provider, then signs one off-chain update per call. Thousands of calls settle in one on-chain transaction. If the agent's policy does not allow the payment the tool returnsBUDGET REFUSED: …to the model rather than raising.FoliantBudgetMiddleware— wraps tool calls; before a paid call it checks that the agent can still pay (policy headroom plus unspent balance in open channels or pools) and returns a clear tool message, or stops the run, if not.FoliantCrew— maps a supervisor and its subagents onto a Foliant budget tree.worker(name, policy, fund=…)delegates a child account with a policy no wider than the supervisor's and returns the tool and middleware for that subagent;revoke(name)expires the worker and recalls its balance with the supervisor's key alone.
The wire format is unchanged x402 (X-PAYMENT, X-PAYMENT-RESPONSE, the 402 accepts body), so this sits beside langchain-x402 and per-call wallets rather than replacing them.
Example
import httpx
from foliant import Agent, KeyPair, Ledger, Policy
from langchain.agents import create_agent
from langchain_foliant import FoliantCrew
ledger = Ledger() # the reference in-memory ledger; contracts on Base/Avalanche are the next phase
http = httpx.Client()
supervisor = Agent(ledger, KeyPair(), KeyPair(),
Policy(per_tx_max=500, per_window_max=150, window_secs=3600))
crew = FoliantCrew(supervisor, http)
worker_policy = Policy(per_tx_max=100, per_window_max=100, window_secs=3600)
research = crew.worker("research", worker_policy, fund=1_000)
writer = crew.worker("writer", worker_policy, fund=1_000)
research_agent = create_agent("openai:gpt-5.5", tools=[research.tool], middleware=[research.middleware])
writer_agent = create_agent("openai:gpt-5.5", tools=[writer.tool], middleware=[writer.middleware])
# Each worker may commit up to 100 in the hour; the crew as a whole stops at 150,
# so the third worker's deposit is refused even though its own cap has room.
# crew.committed() -> {"research": 100, "writer": 50, "crew": 150}
# crew.revoke("writer") -> expires the writer's policy and recalls its unspent balance.
Refund and settlement semantics
Deposits into a channel or pool are the committed value the policy sees; per-call updates are bounded by the deposit. The provider settles at its own cadence with one transaction per channel or per pool. A payer recovers its unspent deposit by closing a channel or exiting a pool unilaterally after the timeout; a provider that goes silent cannot hold a payer's funds. Receipts are provider-signed, one per call, and are available on the tool as tool.receipts.
Status
The tool and middleware run against the Foliant Python reference implementation (an in-process ledger) today, which is what the tests exercise. Solidity contracts and a registered x402 scheme on Base and Avalanche are the next phase; the tool's interface does not change when they land.
Tests
pip install -e ".[test]"
pytest
Includes LangChain's standard tool tests (langchain-tests) and behaviour tests for payment, refusal, middleware inside create_agent, and the crew.
Licence
Apache-2.0. Copyright 2026 Machine Quotient Ltd.
Metadata
Release files for langchain-foliant 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| langchain_foliant-0.1.3.tar.gz | 7.6 kB | Without provenance | Details for langchain_foliant-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| langchain_foliant-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for langchain_foliant-0.1.3-py3-none-any.whl |
Total release size: 16.4 kB
Release files / langchain_foliant-0.1.3.tar.gz
| Download URL | langchain_foliant-0.1.3.tar.gz |
|---|---|
| Size | 7.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c325238f31ac20e012fb7c524ef61cabf71a1a44be238cdaafdf71ad9687669f
|
|
BLAKE2b-256 checksum How to use checksums |
5cd558a49796f5e4a68eceb33dd3fbc1beff83925f9304e22c04d606667b8035
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.7
|
Release files / langchain_foliant-0.1.3-py3-none-any.whl
| Download URL | langchain_foliant-0.1.3-py3-none-any.whl |
|---|---|
| Size | 8.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a58676647a13f22f6943cdccadd1fd793de83eed7d5934e94063186f5bdd0d26
|
|
BLAKE2b-256 checksum How to use checksums |
ead998bc20683a1c548643c483ef5d9b29f793dd43401f034407196e8ca487d4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.7
|
Security for langchain-foliant 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.