LangChain integration for PQSafe AgentPay — post-quantum safe payments for AI agents
Project description
langchain-pqsafe
Post-quantum safe payments for LangChain agents, powered by PQSafe AgentPay.
Built on @pqsafe/agent-pay — see github.com/PQSafe/pqsafe
Install
pip install langchain-pqsafe
5-line quick start
from langchain_pqsafe import PQSafePaymentTool
from langchain.agents import create_react_agent
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(model="gpt-4o")
agent = create_react_agent(llm, tools=[PQSafePaymentTool()])
That's it. The agent can now call pqsafe_pay whenever it needs to make a payment authorized by a SpendEnvelope.
How it works
- A human wallet owner issues a signed SpendEnvelope — a post-quantum (ML-DSA-65) token that specifies: agent ID, max amount, allowed recipients, currency, and validity window.
- The LangChain agent calls
pqsafe_paywith the envelope, recipient, amount, and memo. - PQSafe verifies the envelope server-side and routes the payment over the cheapest available rail (Airwallex, Wise, Stripe, USDC/Base, or x402).
- The tool returns
{txId, status, rail}.
Full example
import json
from langchain_pqsafe import PQSafePaymentTool
from langchain.agents import AgentExecutor, create_react_agent
from langchain_openai import ChatOpenAI
from langchain_core.prompts import PromptTemplate
# 1. Build the tool
payment_tool = PQSafePaymentTool()
# 2. Your signed envelope (issued by the wallet owner, stored securely)
signed_envelope = {
"envelopeJson": '{"version":1,"issuer":"pq1...","agent":"my-agent",...}',
"signature": "deadbeef...",
"dsaPublicKey": "cafebabe...",
}
envelope_json = json.dumps(signed_envelope)
# 3. Create the agent
llm = ChatOpenAI(model="gpt-4o", temperature=0)
prompt = PromptTemplate.from_template(
"You are a payment agent. Use pqsafe_pay to pay invoices.\n"
"Envelope: {envelope_json}\n\n{agent_scratchpad}"
)
agent = create_react_agent(llm, tools=[payment_tool], prompt=prompt)
executor = AgentExecutor(agent=agent, tools=[payment_tool], verbose=True)
# 4. Run
result = executor.invoke({
"envelope_json": envelope_json,
"input": "Renew Perplexity Pro at perplexity.ai — $20 USD for research-agent-v1",
})
print(result["output"])
Tool schema
| Parameter | Type | Required | Description |
|---|---|---|---|
envelope_json |
str |
Yes | SignedEnvelope serialized as JSON |
recipient |
str |
Yes | Recipient address (IBAN, crypto addr, etc.) |
amount |
float |
Yes | Amount in envelope's currency (> 0) |
memo |
str |
No | Human-readable reference |
Returns a string: Payment successful. txId=<id> status=<status> rail=<rail>
Links
- Documentation: docs.pqsafe.xyz
- Website: pqsafe.xyz
- GitHub: github.com/PQSafe/pqsafe
- npm SDK:
@pqsafe/agent-pay
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_pqsafe-0.1.0.tar.gz.
File metadata
- Download URL: langchain_pqsafe-0.1.0.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d415fbd5dc8e9a514bb61e01f2fff040613f9000bfb39ef0e21aa14ef385c8c
|
|
| MD5 |
14df009c845b6b6e956a1215dba962e6
|
|
| BLAKE2b-256 |
ae9b17653b554dba1d1b3e6021c90449bb2379125bc35cbdbade42b10ca120a2
|
File details
Details for the file langchain_pqsafe-0.1.0-py3-none-any.whl.
File metadata
- Download URL: langchain_pqsafe-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2da30989c78c67b708800c8f6fd21b1b0351029a295ce792b5733c2689fc1eea
|
|
| MD5 |
dd4d3ffa506b46f7137f40e5bc824039
|
|
| BLAKE2b-256 |
4bf4018edb307e1e07f5af52750b3f351cc64b3be79184865ab1255c9f7faa12
|