Skip to content

Commit a0cca8d

Browse files
ASND-111: add langchain-ampersend integartion
1 parent babda3e commit a0cca8d

File tree

15 files changed

+1054
-6
lines changed

15 files changed

+1054
-6
lines changed

.github/workflows/python-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
run: uv python install 3.13
3737

3838
- name: Install deps
39-
run: uv sync --frozen --group dev
39+
run: uv sync --frozen --all-packages --group dev
4040

4141
- name: Lint
4242
run: uv run -- ruff check --output-format=github python
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Python langchain-ampersend Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "py-langchain-ampersend-v*.*.*"
7+
- "py-langchain-ampersend-v*.*.*a*"
8+
- "py-langchain-ampersend-v*.*.*b*"
9+
- "py-langchain-ampersend-v*.*.*rc*"
10+
11+
permissions:
12+
contents: read
13+
id-token: write # Required for PyPI trusted publishing
14+
15+
jobs:
16+
verify-version:
17+
name: "py-langchain-ampersend: verify version"
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v5
23+
24+
- name: Setup uv
25+
uses: astral-sh/setup-uv@v6
26+
27+
- name: Install Python 3.13
28+
run: uv python install 3.13
29+
30+
- name: Extract version from tag
31+
id: tag
32+
run: |
33+
TAG=${GITHUB_REF#refs/tags/py-langchain-ampersend-v}
34+
echo "version=$TAG" >> $GITHUB_OUTPUT
35+
echo "Tagged version: $TAG"
36+
37+
- name: Read pyproject.toml version
38+
id: package
39+
run: |
40+
VERSION=$(uv run python -c "import tomllib; print(tomllib.load(open('python/langchain-ampersend/pyproject.toml', 'rb'))['project']['version'])")
41+
echo "version=$VERSION" >> $GITHUB_OUTPUT
42+
echo "Package version: $VERSION"
43+
44+
- name: Compare versions
45+
run: |
46+
if [ "${{ steps.tag.outputs.version }}" != "${{ steps.package.outputs.version }}" ]; then
47+
echo "ERROR: Tag version (${{ steps.tag.outputs.version }}) does not match pyproject.toml version (${{ steps.package.outputs.version }})"
48+
exit 1
49+
fi
50+
echo "✓ Versions match: ${{ steps.tag.outputs.version }}"
51+
52+
publish:
53+
name: "py-langchain-ampersend: publish to PyPI"
54+
runs-on: ubuntu-latest
55+
needs: verify-version
56+
environment:
57+
name: pypi
58+
url: https://pypi.org/p/langchain-ampersend
59+
60+
steps:
61+
- name: Checkout
62+
uses: actions/checkout@v5
63+
64+
- name: Setup uv
65+
uses: astral-sh/setup-uv@v6
66+
67+
- name: Install Python 3.13
68+
run: uv python install 3.13
69+
70+
- name: Build package
71+
run: uv build --package langchain-ampersend
72+
73+
- name: Publish to PyPI
74+
uses: pypa/gh-action-pypi-publish@release/v1
75+
with:
76+
packages-dir: dist/

CLAUDE.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ support buyer (client) and seller (server) roles with flexible payment authoriza
1717
uv python install 3.13
1818

1919
# Install dependencies including dev tools
20-
uv sync --frozen --group dev
20+
uv sync --frozen --all-packages --group dev
2121
```
2222

2323
### TypeScript Setup
@@ -119,6 +119,7 @@ This is a multi-language monorepo with both workspace at the repository root:
119119
**Python** (uv workspace):
120120

121121
- `python/ampersend-sdk/`: Python SDK with A2A protocol integration
122+
- `python/langchain-ampersend/`: LangChain integration for A2A with x402 payments
122123
- Configured via `pyproject.toml`
123124

124125
**TypeScript** (pnpm workspace):

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ Supports both buyer (client) and seller (server) roles with flexible payment ver
88
## 📦 Language Support
99

1010
- **Python** - A2A protocol integration with wallet implementations and payment middleware
11-
- [Python SDK Documentation](./python/README.md)
11+
- [Python SDK Documentation](./python/ampersend-sdk/README.md)
12+
- [LangChain Integration](./python/langchain-ampersend/README.md)
1213

1314
- **TypeScript** - MCP protocol integration with client, proxy, and server implementations
1415
- [TypeScript SDK Documentation](./typescript/README.md)
@@ -22,7 +23,7 @@ Supports both buyer (client) and seller (server) roles with flexible payment ver
2223
uv python install 3.13
2324

2425
# Install dependencies
25-
uv sync --frozen --group dev
26+
uv sync --frozen --all-packages --group dev
2627
```
2728

2829
**[Full Python documentation](./python/README.md)**
@@ -71,10 +72,11 @@ patterns. See [x402 specification](https://github.com/coinbase/x402).
7172
```
7273
ampersend-sdk/
7374
├── python/
74-
│ └── ampersend-sdk/ # Python SDK package
75+
│ ├── ampersend-sdk/ # Python SDK package
76+
│ └── langchain-ampersend/ # LangChain integration
7577
└── typescript/
7678
└── packages/
77-
└── ampersend-sdk/ # TypeScript SDK package
79+
└── ampersend-sdk/ # TypeScript SDK package
7880
```
7981

8082
## 🔧 Prerequisites

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ disable_error_code = ["no-untyped-def", "arg-type", "index", "type-arg"]
3535
[tool.pytest.ini_options]
3636
testpaths = [
3737
"python/ampersend-sdk/tests",
38+
"python/langchain-ampersend/tests",
3839
]
3940
asyncio_mode = "auto"
4041
asyncio_default_fixture_loop_scope = "function"
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# langchain-ampersend
2+
3+
LangChain integration for Ampersend x402 payments. Call remote A2A agents with automatic payment handling.
4+
5+
## Installation
6+
7+
```bash
8+
pip install langchain-ampersend
9+
```
10+
11+
## Usage
12+
13+
```python
14+
from langchain_ampersend import (
15+
A2AToolkit,
16+
AmpersendTreasurer,
17+
ApiClient,
18+
ApiClientOptions,
19+
SmartAccountWallet,
20+
)
21+
from langchain.agents import create_agent
22+
from langchain_openai import ChatOpenAI
23+
24+
# Setup Ampersend API client
25+
api_client = ApiClient(ApiClientOptions(
26+
base_url="https://api.ampersend.ai",
27+
session_key_private_key="0x...", # Your session key
28+
))
29+
30+
# Setup wallet (smart account)
31+
wallet = SmartAccountWallet(
32+
owner_private_key="0x...",
33+
smart_account_address="0x...",
34+
)
35+
36+
# Create treasurer
37+
treasurer = AmpersendTreasurer(api_client=api_client, wallet=wallet)
38+
39+
# Create toolkit for a remote agent
40+
toolkit = A2AToolkit(
41+
remote_agent_url="https://agent.example.com",
42+
treasurer=treasurer,
43+
)
44+
45+
# Initialize (discovers the agent)
46+
await toolkit.initialize()
47+
48+
# Use with LangGraph
49+
llm = ChatOpenAI(model="gpt-4")
50+
agent = create_agent(llm, toolkit.get_tools())
51+
52+
# Run
53+
result = await agent.ainvoke({"messages": [("user", "Query some data")]})
54+
```
55+
56+
## Tools
57+
58+
The toolkit provides two tools:
59+
60+
- `a2a_get_agent_details` - Get the capabilities and skills of the remote agent
61+
- `a2a_send_message` - Send a message to the remote agent (payments handled automatically)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[project]
2+
name = "langchain-ampersend"
3+
version = "0.0.1"
4+
description = "LangChain integration for Ampersend x402 payments"
5+
readme = "README.md"
6+
requires-python = ">=3.13"
7+
dependencies = [
8+
"langchain-core>=0.3.0",
9+
"ampersend-sdk",
10+
"httpx>=0.27.0",
11+
]
12+
13+
[build-system]
14+
requires = ["uv_build>=0.8.22,<0.9.0"]
15+
build-backend = "uv_build"
16+
17+
[dependency-groups]
18+
test = [
19+
"pytest>=8.0.0",
20+
"pytest-asyncio>=0.24.0",
21+
]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""LangChain integration for Ampersend x402 payments."""
2+
3+
# Re-export common items from ampersend-sdk for convenience
4+
from ampersend_sdk.ampersend import AmpersendTreasurer, ApiClient, ApiClientOptions
5+
from ampersend_sdk.x402.treasurer import X402Treasurer
6+
from ampersend_sdk.x402.wallets.smart_account import SmartAccountWallet
7+
8+
from .a2a import A2AToolkit
9+
10+
__all__ = [
11+
"A2AToolkit",
12+
"X402Treasurer",
13+
"AmpersendTreasurer",
14+
"ApiClient",
15+
"ApiClientOptions",
16+
"SmartAccountWallet",
17+
]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""A2A toolkit for LangChain."""
2+
3+
from .toolkit import A2AToolkit
4+
5+
__all__ = ["A2AToolkit"]

0 commit comments

Comments
 (0)