Skip to main content

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

  1. 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.
  2. The LangChain agent calls pqsafe_pay with the envelope, recipient, amount, and memo.
  3. PQSafe verifies the envelope server-side and routes the payment over the cheapest available rail (Airwallex, Wise, Stripe, USDC/Base, or x402).
  4. 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_pqsafe-0.1.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_pqsafe-0.1.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

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

Hashes for langchain_pqsafe-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1d415fbd5dc8e9a514bb61e01f2fff040613f9000bfb39ef0e21aa14ef385c8c
MD5 14df009c845b6b6e956a1215dba962e6
BLAKE2b-256 ae9b17653b554dba1d1b3e6021c90449bb2379125bc35cbdbade42b10ca120a2

See more details on using hashes here.

File details

Details for the file langchain_pqsafe-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_pqsafe-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2da30989c78c67b708800c8f6fd21b1b0351029a295ce792b5733c2689fc1eea
MD5 dd4d3ffa506b46f7137f40e5bc824039
BLAKE2b-256 4bf4018edb307e1e07f5af52750b3f351cc64b3be79184865ab1255c9f7faa12

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page