langchain-agentpayment 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- langchain_agentpayment-0.1.0/PKG-INFO +89 -0
- langchain_agentpayment-0.1.0/README.md +60 -0
- langchain_agentpayment-0.1.0/langchain_agentpayment/__init__.py +23 -0
- langchain_agentpayment-0.1.0/langchain_agentpayment/tools.py +256 -0
- langchain_agentpayment-0.1.0/langchain_agentpayment.egg-info/PKG-INFO +89 -0
- langchain_agentpayment-0.1.0/langchain_agentpayment.egg-info/SOURCES.txt +9 -0
- langchain_agentpayment-0.1.0/langchain_agentpayment.egg-info/dependency_links.txt +1 -0
- langchain_agentpayment-0.1.0/langchain_agentpayment.egg-info/requires.txt +3 -0
- langchain_agentpayment-0.1.0/langchain_agentpayment.egg-info/top_level.txt +1 -0
- langchain_agentpayment-0.1.0/setup.cfg +4 -0
- langchain_agentpayment-0.1.0/setup.py +27 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: langchain-agentpayment
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: LangChain tools for AgentPayment Network — autonomous agent-to-agent payments
|
|
5
|
+
Home-page: https://github.com/SuryaRaut/agent-payment-network
|
|
6
|
+
Author: AgentPayment Network
|
|
7
|
+
Author-email: support@agentpayment.network
|
|
8
|
+
Keywords: langchain,ai,agents,payments,crypto,autonomous
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
14
|
+
Requires-Python: >=3.9
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
Requires-Dist: langchain-core>=0.1.0
|
|
17
|
+
Requires-Dist: agent-payment-sdk>=0.4.5
|
|
18
|
+
Requires-Dist: pydantic>=2.0.0
|
|
19
|
+
Dynamic: author
|
|
20
|
+
Dynamic: author-email
|
|
21
|
+
Dynamic: classifier
|
|
22
|
+
Dynamic: description
|
|
23
|
+
Dynamic: description-content-type
|
|
24
|
+
Dynamic: home-page
|
|
25
|
+
Dynamic: keywords
|
|
26
|
+
Dynamic: requires-dist
|
|
27
|
+
Dynamic: requires-python
|
|
28
|
+
Dynamic: summary
|
|
29
|
+
|
|
30
|
+
# langchain-agentpayment
|
|
31
|
+
|
|
32
|
+
LangChain tools for [AgentPayment Network](https://agentpayment.network) — autonomous agent-to-agent payments across crypto, card, and ACH.
|
|
33
|
+
|
|
34
|
+
## Installation
|
|
35
|
+
```bash
|
|
36
|
+
pip install langchain-agentpayment
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Quick Start
|
|
40
|
+
```python
|
|
41
|
+
from langchain_agentpayment import AgentPaymentToolkit
|
|
42
|
+
from langchain_openai import ChatOpenAI
|
|
43
|
+
from langchain.agents import create_tool_calling_agent, AgentExecutor
|
|
44
|
+
from langchain_core.prompts import ChatPromptTemplate
|
|
45
|
+
|
|
46
|
+
# Initialize toolkit
|
|
47
|
+
toolkit = AgentPaymentToolkit(api_key="apn_your_key_here")
|
|
48
|
+
tools = toolkit.get_tools()
|
|
49
|
+
|
|
50
|
+
# Create agent
|
|
51
|
+
llm = ChatOpenAI(model="gpt-4o")
|
|
52
|
+
prompt = ChatPromptTemplate.from_messages([
|
|
53
|
+
("system", "You are an autonomous agent that can send and receive payments."),
|
|
54
|
+
("human", "{input}"),
|
|
55
|
+
("placeholder", "{agent_scratchpad}"),
|
|
56
|
+
])
|
|
57
|
+
agent = create_tool_calling_agent(llm, tools, prompt)
|
|
58
|
+
executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
|
|
59
|
+
|
|
60
|
+
# Run
|
|
61
|
+
executor.invoke({"input": "Create an invoice for agent_abc for $5 for API usage"})
|
|
62
|
+
executor.invoke({"input": "Set a billing rule to auto-pay up to $10 from provider_xyz via crypto"})
|
|
63
|
+
executor.invoke({"input": "Set a circuit breaker with max $100/day spend limit"})
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Available Tools
|
|
67
|
+
|
|
68
|
+
| Tool | Description |
|
|
69
|
+
|------|-------------|
|
|
70
|
+
| `create_invoice` | Bill a consumer agent for services rendered |
|
|
71
|
+
| `approve_invoice` | Manually approve and pay a pending invoice |
|
|
72
|
+
| `set_billing_rule` | Auto-approve invoices from a provider |
|
|
73
|
+
| `check_invoice_status` | Check status of an invoice |
|
|
74
|
+
| `list_invoices` | List sent/received invoices |
|
|
75
|
+
| `create_recurring_billing` | Set up recurring billing (Model A or B) |
|
|
76
|
+
| `set_circuit_breaker` | Set daily spend/transaction limits |
|
|
77
|
+
|
|
78
|
+
## Pricing
|
|
79
|
+
|
|
80
|
+
Volume-based, dual-sided:
|
|
81
|
+
- 0–10k requests/month: 1% consumer + 1% provider
|
|
82
|
+
- 10k–20k: 0.9% each side
|
|
83
|
+
- 20k+: 0.8% each side
|
|
84
|
+
|
|
85
|
+
## Links
|
|
86
|
+
|
|
87
|
+
- [Docs](https://agentpayment.network/docs)
|
|
88
|
+
- [PyPI](https://pypi.org/project/agent-payment-sdk/)
|
|
89
|
+
- [GitHub](https://github.com/SuryaRaut/agent-payment-network)
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# langchain-agentpayment
|
|
2
|
+
|
|
3
|
+
LangChain tools for [AgentPayment Network](https://agentpayment.network) — autonomous agent-to-agent payments across crypto, card, and ACH.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
```bash
|
|
7
|
+
pip install langchain-agentpayment
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Quick Start
|
|
11
|
+
```python
|
|
12
|
+
from langchain_agentpayment import AgentPaymentToolkit
|
|
13
|
+
from langchain_openai import ChatOpenAI
|
|
14
|
+
from langchain.agents import create_tool_calling_agent, AgentExecutor
|
|
15
|
+
from langchain_core.prompts import ChatPromptTemplate
|
|
16
|
+
|
|
17
|
+
# Initialize toolkit
|
|
18
|
+
toolkit = AgentPaymentToolkit(api_key="apn_your_key_here")
|
|
19
|
+
tools = toolkit.get_tools()
|
|
20
|
+
|
|
21
|
+
# Create agent
|
|
22
|
+
llm = ChatOpenAI(model="gpt-4o")
|
|
23
|
+
prompt = ChatPromptTemplate.from_messages([
|
|
24
|
+
("system", "You are an autonomous agent that can send and receive payments."),
|
|
25
|
+
("human", "{input}"),
|
|
26
|
+
("placeholder", "{agent_scratchpad}"),
|
|
27
|
+
])
|
|
28
|
+
agent = create_tool_calling_agent(llm, tools, prompt)
|
|
29
|
+
executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
|
|
30
|
+
|
|
31
|
+
# Run
|
|
32
|
+
executor.invoke({"input": "Create an invoice for agent_abc for $5 for API usage"})
|
|
33
|
+
executor.invoke({"input": "Set a billing rule to auto-pay up to $10 from provider_xyz via crypto"})
|
|
34
|
+
executor.invoke({"input": "Set a circuit breaker with max $100/day spend limit"})
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Available Tools
|
|
38
|
+
|
|
39
|
+
| Tool | Description |
|
|
40
|
+
|------|-------------|
|
|
41
|
+
| `create_invoice` | Bill a consumer agent for services rendered |
|
|
42
|
+
| `approve_invoice` | Manually approve and pay a pending invoice |
|
|
43
|
+
| `set_billing_rule` | Auto-approve invoices from a provider |
|
|
44
|
+
| `check_invoice_status` | Check status of an invoice |
|
|
45
|
+
| `list_invoices` | List sent/received invoices |
|
|
46
|
+
| `create_recurring_billing` | Set up recurring billing (Model A or B) |
|
|
47
|
+
| `set_circuit_breaker` | Set daily spend/transaction limits |
|
|
48
|
+
|
|
49
|
+
## Pricing
|
|
50
|
+
|
|
51
|
+
Volume-based, dual-sided:
|
|
52
|
+
- 0–10k requests/month: 1% consumer + 1% provider
|
|
53
|
+
- 10k–20k: 0.9% each side
|
|
54
|
+
- 20k+: 0.8% each side
|
|
55
|
+
|
|
56
|
+
## Links
|
|
57
|
+
|
|
58
|
+
- [Docs](https://agentpayment.network/docs)
|
|
59
|
+
- [PyPI](https://pypi.org/project/agent-payment-sdk/)
|
|
60
|
+
- [GitHub](https://github.com/SuryaRaut/agent-payment-network)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from .tools import (
|
|
2
|
+
CreateInvoiceTool,
|
|
3
|
+
ApproveInvoiceTool,
|
|
4
|
+
SetBillingRuleTool,
|
|
5
|
+
CheckInvoiceStatusTool,
|
|
6
|
+
ListInvoicesTool,
|
|
7
|
+
CreateRecurringBillingTool,
|
|
8
|
+
SetCircuitBreakerTool,
|
|
9
|
+
AgentPaymentToolkit,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"CreateInvoiceTool",
|
|
14
|
+
"ApproveInvoiceTool",
|
|
15
|
+
"SetBillingRuleTool",
|
|
16
|
+
"CheckInvoiceStatusTool",
|
|
17
|
+
"ListInvoicesTool",
|
|
18
|
+
"CreateRecurringBillingTool",
|
|
19
|
+
"SetCircuitBreakerTool",
|
|
20
|
+
"AgentPaymentToolkit",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
"""
|
|
2
|
+
LangChain tools for AgentPayment Network.
|
|
3
|
+
Enables LangChain agents to autonomously send and receive payments.
|
|
4
|
+
|
|
5
|
+
Usage:
|
|
6
|
+
from langchain_agentpayment import AgentPaymentToolkit
|
|
7
|
+
from langchain_openai import ChatOpenAI
|
|
8
|
+
from langchain.agents import create_tool_calling_agent, AgentExecutor
|
|
9
|
+
|
|
10
|
+
toolkit = AgentPaymentToolkit(api_key="apn_...")
|
|
11
|
+
tools = toolkit.get_tools()
|
|
12
|
+
|
|
13
|
+
llm = ChatOpenAI(model="gpt-4o")
|
|
14
|
+
agent = create_tool_calling_agent(llm, tools, prompt)
|
|
15
|
+
executor = AgentExecutor(agent=agent, tools=tools)
|
|
16
|
+
executor.invoke({"input": "Pay agent_abc $5 for API usage"})
|
|
17
|
+
"""
|
|
18
|
+
from typing import Optional, Type, List
|
|
19
|
+
from pydantic import BaseModel, Field
|
|
20
|
+
from langchain_core.tools import BaseTool
|
|
21
|
+
from agent_payment_sdk import AgentPaymentClient
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class CreateInvoiceInput(BaseModel):
|
|
25
|
+
to_agent_id : str = Field(description="Consumer agent ID to bill")
|
|
26
|
+
amount : float = Field(description="Invoice amount in USD")
|
|
27
|
+
description : str = Field(description="Description of service rendered")
|
|
28
|
+
payment_rail : str = Field(default="crypto", description="Payment rail: crypto, card, or ach")
|
|
29
|
+
|
|
30
|
+
class ApproveInvoiceInput(BaseModel):
|
|
31
|
+
invoice_id: str = Field(description="Invoice ID to approve and pay")
|
|
32
|
+
|
|
33
|
+
class SetBillingRuleInput(BaseModel):
|
|
34
|
+
approved_provider_id : str = Field(description="Provider agent ID to auto-approve payments from")
|
|
35
|
+
max_invoice_amount : float = Field(description="Maximum invoice amount to auto-approve in USD")
|
|
36
|
+
preferred_rail : str = Field(default="crypto", description="Payment rail: crypto, card, or ach")
|
|
37
|
+
|
|
38
|
+
class CheckInvoiceInput(BaseModel):
|
|
39
|
+
invoice_id: str = Field(description="Invoice ID to check status of")
|
|
40
|
+
|
|
41
|
+
class ListInvoicesInput(BaseModel):
|
|
42
|
+
role : str = Field(default="all", description="Filter: all, sent (as provider), received (as consumer)")
|
|
43
|
+
limit: int = Field(default=10, description="Maximum number of invoices to return")
|
|
44
|
+
|
|
45
|
+
class CreateRecurringBillingInput(BaseModel):
|
|
46
|
+
consumer_id : str = Field(description="Consumer agent ID to bill recurringly")
|
|
47
|
+
frequency : str = Field(description="Billing frequency: 30m, 1h, 6h, 1d, 7d, 30d")
|
|
48
|
+
payment_rail : str = Field(default="crypto", description="Payment rail: crypto, card, or ach")
|
|
49
|
+
callback_url : Optional[str] = Field(default=None, description="Model A: webhook URL to receive billing notifications")
|
|
50
|
+
usage_endpoint: Optional[str] = Field(default=None, description="Model B: endpoint platform pulls usage from autonomously")
|
|
51
|
+
max_per_period: Optional[float]= Field(default=None, description="Safety cap — max amount per billing cycle in USD")
|
|
52
|
+
description : Optional[str] = Field(default=None, description="Description for invoices")
|
|
53
|
+
|
|
54
|
+
class SetCircuitBreakerInput(BaseModel):
|
|
55
|
+
max_spend_per_day : Optional[float] = Field(default=None, description="Maximum USD to spend per day")
|
|
56
|
+
max_transactions_per_day : Optional[int] = Field(default=None, description="Maximum number of transactions per day")
|
|
57
|
+
notify_email : bool = Field(default=True, description="Send email when circuit breaker triggers")
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class CreateInvoiceTool(BaseTool):
|
|
61
|
+
name : str = "create_invoice"
|
|
62
|
+
description: str = (
|
|
63
|
+
"Create an invoice to charge a consumer agent for services rendered. "
|
|
64
|
+
"If the consumer has an auto-approval billing rule, payment is instant. "
|
|
65
|
+
"Use this when your agent has completed work and needs to get paid."
|
|
66
|
+
)
|
|
67
|
+
args_schema: Type[BaseModel] = CreateInvoiceInput
|
|
68
|
+
client : AgentPaymentClient
|
|
69
|
+
|
|
70
|
+
class Config:
|
|
71
|
+
arbitrary_types_allowed = True
|
|
72
|
+
|
|
73
|
+
def _run(self, to_agent_id: str, amount: float, description: str, payment_rail: str = "crypto") -> str:
|
|
74
|
+
try:
|
|
75
|
+
result = self.client.create_invoice(
|
|
76
|
+
to_agent_id=to_agent_id, amount=amount,
|
|
77
|
+
description=description, payment_rail=payment_rail
|
|
78
|
+
)
|
|
79
|
+
status = result.get("status", "unknown")
|
|
80
|
+
invoice_id = result.get("invoice_id", "")
|
|
81
|
+
if status == "PAID":
|
|
82
|
+
return f"Invoice paid instantly. ID: {invoice_id}. Amount: ${amount} via {payment_rail}."
|
|
83
|
+
return f"Invoice created (status: {status}). ID: {invoice_id}. Awaiting consumer approval."
|
|
84
|
+
except Exception as e:
|
|
85
|
+
return f"Failed to create invoice: {str(e)}"
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class ApproveInvoiceTool(BaseTool):
|
|
89
|
+
name : str = "approve_invoice"
|
|
90
|
+
description: str = "Approve and pay a pending invoice by its ID."
|
|
91
|
+
args_schema: Type[BaseModel] = ApproveInvoiceInput
|
|
92
|
+
client : AgentPaymentClient
|
|
93
|
+
|
|
94
|
+
class Config:
|
|
95
|
+
arbitrary_types_allowed = True
|
|
96
|
+
|
|
97
|
+
def _run(self, invoice_id: str) -> str:
|
|
98
|
+
try:
|
|
99
|
+
result = self.client.approve_invoice(invoice_id)
|
|
100
|
+
return f"Invoice {invoice_id} paid. Status: {result.get('status')}."
|
|
101
|
+
except Exception as e:
|
|
102
|
+
return f"Failed to approve invoice: {str(e)}"
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
class SetBillingRuleTool(BaseTool):
|
|
106
|
+
name : str = "set_billing_rule"
|
|
107
|
+
description: str = (
|
|
108
|
+
"Set an auto-approval billing rule to automatically pay invoices "
|
|
109
|
+
"from a specific provider without manual approval. "
|
|
110
|
+
"Enables fully autonomous payments."
|
|
111
|
+
)
|
|
112
|
+
args_schema: Type[BaseModel] = SetBillingRuleInput
|
|
113
|
+
client : AgentPaymentClient
|
|
114
|
+
|
|
115
|
+
class Config:
|
|
116
|
+
arbitrary_types_allowed = True
|
|
117
|
+
|
|
118
|
+
def _run(self, approved_provider_id: str, max_invoice_amount: float, preferred_rail: str = "crypto") -> str:
|
|
119
|
+
try:
|
|
120
|
+
result = self.client.set_billing_rule(
|
|
121
|
+
approved_provider_id=approved_provider_id,
|
|
122
|
+
max_invoice_amount=max_invoice_amount,
|
|
123
|
+
preferred_rail=preferred_rail
|
|
124
|
+
)
|
|
125
|
+
return (
|
|
126
|
+
f"Billing rule set. Auto-approving up to ${max_invoice_amount} "
|
|
127
|
+
f"from {approved_provider_id} via {preferred_rail}."
|
|
128
|
+
)
|
|
129
|
+
except Exception as e:
|
|
130
|
+
return f"Failed to set billing rule: {str(e)}"
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
class CheckInvoiceStatusTool(BaseTool):
|
|
134
|
+
name : str = "check_invoice_status"
|
|
135
|
+
description: str = "Check the status of an invoice by its ID."
|
|
136
|
+
args_schema: Type[BaseModel] = CheckInvoiceInput
|
|
137
|
+
client : AgentPaymentClient
|
|
138
|
+
|
|
139
|
+
class Config:
|
|
140
|
+
arbitrary_types_allowed = True
|
|
141
|
+
|
|
142
|
+
def _run(self, invoice_id: str) -> str:
|
|
143
|
+
try:
|
|
144
|
+
result = self.client.get_invoice_pay_info(invoice_id)
|
|
145
|
+
return (
|
|
146
|
+
f"Invoice {invoice_id}: amount=${result.get('amount')}, "
|
|
147
|
+
f"status={result.get('status', 'unknown')}"
|
|
148
|
+
)
|
|
149
|
+
except Exception as e:
|
|
150
|
+
return f"Failed to check invoice: {str(e)}"
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
class ListInvoicesTool(BaseTool):
|
|
154
|
+
name : str = "list_invoices"
|
|
155
|
+
description: str = "List invoices. Role: sent (as provider), received (as consumer), all."
|
|
156
|
+
args_schema: Type[BaseModel] = ListInvoicesInput
|
|
157
|
+
client : AgentPaymentClient
|
|
158
|
+
|
|
159
|
+
class Config:
|
|
160
|
+
arbitrary_types_allowed = True
|
|
161
|
+
|
|
162
|
+
def _run(self, role: str = "all", limit: int = 10) -> str:
|
|
163
|
+
try:
|
|
164
|
+
result = self.client.list_invoices(agent_id="me", role=role, limit=limit)
|
|
165
|
+
invoices = result.get("invoices", [])
|
|
166
|
+
if not invoices:
|
|
167
|
+
return f"No {role} invoices found."
|
|
168
|
+
lines = [
|
|
169
|
+
f"- {inv.get('invoice_id','')[:8]}... ${inv.get('amount')} {inv.get('status')} via {inv.get('payment_rail')}"
|
|
170
|
+
for inv in invoices[:limit]
|
|
171
|
+
]
|
|
172
|
+
return f"Found {len(invoices)} {role} invoice(s):\n" + "\n".join(lines)
|
|
173
|
+
except Exception as e:
|
|
174
|
+
return f"Failed to list invoices: {str(e)}"
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
class CreateRecurringBillingTool(BaseTool):
|
|
178
|
+
name : str = "create_recurring_billing"
|
|
179
|
+
description: str = (
|
|
180
|
+
"Set up recurring billing for a consumer agent at a set interval. "
|
|
181
|
+
"Model A (callback_url): platform notifies you, you create the invoice. "
|
|
182
|
+
"Model B (usage_endpoint): platform pulls usage and creates invoice automatically."
|
|
183
|
+
)
|
|
184
|
+
args_schema: Type[BaseModel] = CreateRecurringBillingInput
|
|
185
|
+
client : AgentPaymentClient
|
|
186
|
+
|
|
187
|
+
class Config:
|
|
188
|
+
arbitrary_types_allowed = True
|
|
189
|
+
|
|
190
|
+
def _run(self, consumer_id: str, frequency: str, payment_rail: str = "crypto",
|
|
191
|
+
callback_url: Optional[str] = None, usage_endpoint: Optional[str] = None,
|
|
192
|
+
max_per_period: Optional[float] = None, description: Optional[str] = None) -> str:
|
|
193
|
+
try:
|
|
194
|
+
body = {"consumer_id": consumer_id, "frequency": frequency, "payment_rail": payment_rail.upper()}
|
|
195
|
+
if callback_url: body["callback_url"] = callback_url
|
|
196
|
+
if usage_endpoint: body["usage_endpoint"] = usage_endpoint
|
|
197
|
+
if max_per_period: body["max_per_period"] = max_per_period
|
|
198
|
+
if description: body["description"] = description
|
|
199
|
+
result = self.client._request("POST", "/api/v1/recurring-billing", json=body)
|
|
200
|
+
return (
|
|
201
|
+
f"Recurring billing set (Model {result.get('model','A')}). "
|
|
202
|
+
f"Frequency: {frequency}. Next: {result.get('next_billing_at','')}."
|
|
203
|
+
)
|
|
204
|
+
except Exception as e:
|
|
205
|
+
return f"Failed to create recurring billing: {str(e)}"
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
class SetCircuitBreakerTool(BaseTool):
|
|
209
|
+
name : str = "set_circuit_breaker"
|
|
210
|
+
description: str = (
|
|
211
|
+
"Set spending limits to protect your agent. "
|
|
212
|
+
"Blocks all outgoing payments if daily spend or transaction count exceeds the limit."
|
|
213
|
+
)
|
|
214
|
+
args_schema: Type[BaseModel] = SetCircuitBreakerInput
|
|
215
|
+
client : AgentPaymentClient
|
|
216
|
+
|
|
217
|
+
class Config:
|
|
218
|
+
arbitrary_types_allowed = True
|
|
219
|
+
|
|
220
|
+
def _run(self, max_spend_per_day: Optional[float] = None,
|
|
221
|
+
max_transactions_per_day: Optional[int] = None, notify_email: bool = True) -> str:
|
|
222
|
+
try:
|
|
223
|
+
body = {"notify_email": notify_email}
|
|
224
|
+
if max_spend_per_day: body["max_spend_per_day"] = max_spend_per_day
|
|
225
|
+
if max_transactions_per_day: body["max_transactions_per_day"] = max_transactions_per_day
|
|
226
|
+
result = self.client._request("POST", "/api/v1/circuit-breaker", json=body)
|
|
227
|
+
parts = []
|
|
228
|
+
if max_spend_per_day: parts.append(f"max ${max_spend_per_day}/day")
|
|
229
|
+
if max_transactions_per_day: parts.append(f"max {max_transactions_per_day} txns/day")
|
|
230
|
+
return f"Circuit breaker set: {', '.join(parts)}."
|
|
231
|
+
except Exception as e:
|
|
232
|
+
return f"Failed to set circuit breaker: {str(e)}"
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
class AgentPaymentToolkit:
|
|
236
|
+
"""
|
|
237
|
+
LangChain toolkit for AgentPayment Network.
|
|
238
|
+
|
|
239
|
+
Usage:
|
|
240
|
+
toolkit = AgentPaymentToolkit(api_key="apn_...")
|
|
241
|
+
tools = toolkit.get_tools()
|
|
242
|
+
agent = create_tool_calling_agent(llm, tools, prompt)
|
|
243
|
+
"""
|
|
244
|
+
def __init__(self, api_key: str, base_url: str = "https://agentpayment.network"):
|
|
245
|
+
self.client = AgentPaymentClient(api_key=api_key, base_url=base_url)
|
|
246
|
+
|
|
247
|
+
def get_tools(self) -> List[BaseTool]:
|
|
248
|
+
return [
|
|
249
|
+
CreateInvoiceTool(client=self.client),
|
|
250
|
+
ApproveInvoiceTool(client=self.client),
|
|
251
|
+
SetBillingRuleTool(client=self.client),
|
|
252
|
+
CheckInvoiceStatusTool(client=self.client),
|
|
253
|
+
ListInvoicesTool(client=self.client),
|
|
254
|
+
CreateRecurringBillingTool(client=self.client),
|
|
255
|
+
SetCircuitBreakerTool(client=self.client),
|
|
256
|
+
]
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: langchain-agentpayment
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: LangChain tools for AgentPayment Network — autonomous agent-to-agent payments
|
|
5
|
+
Home-page: https://github.com/SuryaRaut/agent-payment-network
|
|
6
|
+
Author: AgentPayment Network
|
|
7
|
+
Author-email: support@agentpayment.network
|
|
8
|
+
Keywords: langchain,ai,agents,payments,crypto,autonomous
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
14
|
+
Requires-Python: >=3.9
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
Requires-Dist: langchain-core>=0.1.0
|
|
17
|
+
Requires-Dist: agent-payment-sdk>=0.4.5
|
|
18
|
+
Requires-Dist: pydantic>=2.0.0
|
|
19
|
+
Dynamic: author
|
|
20
|
+
Dynamic: author-email
|
|
21
|
+
Dynamic: classifier
|
|
22
|
+
Dynamic: description
|
|
23
|
+
Dynamic: description-content-type
|
|
24
|
+
Dynamic: home-page
|
|
25
|
+
Dynamic: keywords
|
|
26
|
+
Dynamic: requires-dist
|
|
27
|
+
Dynamic: requires-python
|
|
28
|
+
Dynamic: summary
|
|
29
|
+
|
|
30
|
+
# langchain-agentpayment
|
|
31
|
+
|
|
32
|
+
LangChain tools for [AgentPayment Network](https://agentpayment.network) — autonomous agent-to-agent payments across crypto, card, and ACH.
|
|
33
|
+
|
|
34
|
+
## Installation
|
|
35
|
+
```bash
|
|
36
|
+
pip install langchain-agentpayment
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Quick Start
|
|
40
|
+
```python
|
|
41
|
+
from langchain_agentpayment import AgentPaymentToolkit
|
|
42
|
+
from langchain_openai import ChatOpenAI
|
|
43
|
+
from langchain.agents import create_tool_calling_agent, AgentExecutor
|
|
44
|
+
from langchain_core.prompts import ChatPromptTemplate
|
|
45
|
+
|
|
46
|
+
# Initialize toolkit
|
|
47
|
+
toolkit = AgentPaymentToolkit(api_key="apn_your_key_here")
|
|
48
|
+
tools = toolkit.get_tools()
|
|
49
|
+
|
|
50
|
+
# Create agent
|
|
51
|
+
llm = ChatOpenAI(model="gpt-4o")
|
|
52
|
+
prompt = ChatPromptTemplate.from_messages([
|
|
53
|
+
("system", "You are an autonomous agent that can send and receive payments."),
|
|
54
|
+
("human", "{input}"),
|
|
55
|
+
("placeholder", "{agent_scratchpad}"),
|
|
56
|
+
])
|
|
57
|
+
agent = create_tool_calling_agent(llm, tools, prompt)
|
|
58
|
+
executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
|
|
59
|
+
|
|
60
|
+
# Run
|
|
61
|
+
executor.invoke({"input": "Create an invoice for agent_abc for $5 for API usage"})
|
|
62
|
+
executor.invoke({"input": "Set a billing rule to auto-pay up to $10 from provider_xyz via crypto"})
|
|
63
|
+
executor.invoke({"input": "Set a circuit breaker with max $100/day spend limit"})
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Available Tools
|
|
67
|
+
|
|
68
|
+
| Tool | Description |
|
|
69
|
+
|------|-------------|
|
|
70
|
+
| `create_invoice` | Bill a consumer agent for services rendered |
|
|
71
|
+
| `approve_invoice` | Manually approve and pay a pending invoice |
|
|
72
|
+
| `set_billing_rule` | Auto-approve invoices from a provider |
|
|
73
|
+
| `check_invoice_status` | Check status of an invoice |
|
|
74
|
+
| `list_invoices` | List sent/received invoices |
|
|
75
|
+
| `create_recurring_billing` | Set up recurring billing (Model A or B) |
|
|
76
|
+
| `set_circuit_breaker` | Set daily spend/transaction limits |
|
|
77
|
+
|
|
78
|
+
## Pricing
|
|
79
|
+
|
|
80
|
+
Volume-based, dual-sided:
|
|
81
|
+
- 0–10k requests/month: 1% consumer + 1% provider
|
|
82
|
+
- 10k–20k: 0.9% each side
|
|
83
|
+
- 20k+: 0.8% each side
|
|
84
|
+
|
|
85
|
+
## Links
|
|
86
|
+
|
|
87
|
+
- [Docs](https://agentpayment.network/docs)
|
|
88
|
+
- [PyPI](https://pypi.org/project/agent-payment-sdk/)
|
|
89
|
+
- [GitHub](https://github.com/SuryaRaut/agent-payment-network)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
setup.py
|
|
3
|
+
langchain_agentpayment/__init__.py
|
|
4
|
+
langchain_agentpayment/tools.py
|
|
5
|
+
langchain_agentpayment.egg-info/PKG-INFO
|
|
6
|
+
langchain_agentpayment.egg-info/SOURCES.txt
|
|
7
|
+
langchain_agentpayment.egg-info/dependency_links.txt
|
|
8
|
+
langchain_agentpayment.egg-info/requires.txt
|
|
9
|
+
langchain_agentpayment.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
langchain_agentpayment
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name="langchain-agentpayment",
|
|
5
|
+
version="0.1.0",
|
|
6
|
+
description="LangChain tools for AgentPayment Network — autonomous agent-to-agent payments",
|
|
7
|
+
long_description=open("README.md").read(),
|
|
8
|
+
long_description_content_type="text/markdown",
|
|
9
|
+
author="AgentPayment Network",
|
|
10
|
+
author_email="support@agentpayment.network",
|
|
11
|
+
url="https://github.com/SuryaRaut/agent-payment-network",
|
|
12
|
+
packages=find_packages(),
|
|
13
|
+
install_requires=[
|
|
14
|
+
"langchain-core>=0.1.0",
|
|
15
|
+
"agent-payment-sdk>=0.4.5",
|
|
16
|
+
"pydantic>=2.0.0",
|
|
17
|
+
],
|
|
18
|
+
python_requires=">=3.9",
|
|
19
|
+
keywords=["langchain", "ai", "agents", "payments", "crypto", "autonomous"],
|
|
20
|
+
classifiers=[
|
|
21
|
+
"Development Status :: 4 - Beta",
|
|
22
|
+
"Intended Audience :: Developers",
|
|
23
|
+
"License :: OSI Approved :: MIT License",
|
|
24
|
+
"Programming Language :: Python :: 3",
|
|
25
|
+
"Topic :: Software Development :: Libraries",
|
|
26
|
+
],
|
|
27
|
+
)
|