How to Integrate LangChain for payments with Slack for multi-agent systems
Combining LangChain for payments with Slack gives you a clean control plane for agent-driven commerce. You can route payment intents through an LLM workflow, then push approvals, exceptions, and audit events into Slack so humans can stay in the loop where it matters.
This is useful when you have multiple agents handling billing, fraud checks, refunds, or subscription changes. One agent can draft the action, another can validate policy, and Slack becomes the operational surface for review and escalation.
Prerequisites
- •Python 3.10+
- •A LangChain environment set up with your payment provider integration
- •A Slack app created in your workspace
- •Slack Bot Token with
chat:writescope - •A Slack channel ID for approvals or alerts
- •API keys configured in environment variables:
- •
LANGCHAIN_API_KEY - •
SLACK_BOT_TOKEN - •any payment processor key used by your LangChain payment toolchain
- •
- •
pipinstalled packages:- •
langchain - •
langchain-community - •
slack_sdk
- •
Integration Steps
- •Set up your Python dependencies and clients.
pip install langchain langchain-community slack_sdk
import os
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError
slack_client = WebClient(token=os.environ["SLACK_BOT_TOKEN"])
SLACK_CHANNEL_ID = os.environ["SLACK_CHANNEL_ID"]
- •Build a LangChain tool for payment actions.
If you already have a payment connector exposed as a LangChain tool, wrap it so your agent can call it directly. For example, use a structured tool that creates a charge request.
from pydantic import BaseModel, Field
from langchain_core.tools import tool
class PaymentRequest(BaseModel):
customer_id: str = Field(..., description="Internal customer identifier")
amount_cents: int = Field(..., description="Amount in cents")
currency: str = Field(default="USD")
reason: str = Field(..., description="Why this payment is being created")
@tool("create_payment_intent", args_schema=PaymentRequest)
def create_payment_intent(customer_id: str, amount_cents: int, currency: str = "USD", reason: str = ""):
# Replace this with your actual payment SDK call or LangChain-connected service.
return {
"payment_intent_id": f"pi_{customer_id}_{amount_cents}",
"status": "requires_review",
"currency": currency,
"reason": reason,
}
- •Create a Slack notification function for approvals and exceptions.
Use Slack to notify the finance or ops channel when the agent creates a payment intent that needs review.
def post_payment_review_message(payment_result: dict):
text = (
f"*Payment Review Needed*\n"
f"Intent: `{payment_result['payment_intent_id']}`\n"
f"Status: `{payment_result['status']}`\n"
f"Amount: `{payment_result.get('amount_cents', 'unknown')}` cents\n"
f"Reason: {payment_result['reason']}"
)
try:
response = slack_client.chat_postMessage(
channel=SLACK_CHANNEL_ID,
text=text,
unfurl_links=False,
unfurl_media=False,
)
return response["ts"]
except SlackApiError as e:
raise RuntimeError(f"Slack post failed: {e.response['error']}")
- •Wire both into a multi-agent flow.
A common pattern is:
- •Agent A drafts the payment action.
- •Agent B validates policy.
- •If approval is required, send the event to Slack.
- •If approved, execute the final payment call.
from langchain_core.messages import HumanMessage
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
def route_payment_request(user_text: str):
prompt = (
"You are a payments operations agent. "
"Extract customer_id, amount_cents, currency, and reason from the request. "
"If the request looks risky or ambiguous, mark it as requires_review."
)
result = llm.invoke([HumanMessage(content=f"{prompt}\n\nRequest: {user_text}")])
# In production parse structured output instead of free text.
payment_result = {
"payment_intent_id": "pi_12345",
"status": "requires_review",
"amount_cents": 25000,
"reason": result.content,
}
if payment_result["status"] == "requires_review":
ts = post_payment_review_message(payment_result)
return {"action": "slack_review_sent", "slack_ts": ts}
return {"action": "payment_created", **payment_result}
- •Add an approval callback from Slack back into your workflow.
For production systems, handle interactive buttons or slash commands in your webhook service. When an approver confirms in Slack, call your payment execution path.
from fastapi import FastAPI, Request
app = FastAPI()
@app.post("/slack/approve-payment")
async def approve_payment(request: Request):
payload = await request.json()
approved_intent_id = payload["intent_id"]
approver = payload["approver"]
# Replace with actual execution via your payments layer.
executed_payment = {
"payment_intent_id": approved_intent_id,
"status": "succeeded",
"approved_by": approver,
}
slack_client.chat_postMessage(
channel=SLACK_CHANNEL_ID,
text=f"Payment `{approved_intent_id}` approved by `{approver}` and executed.",
)
return executed_payment
Testing the Integration
Run a basic end-to-end check by creating a test intent and posting it to Slack.
if __name__ == "__main__":
test_result = {
"payment_intent_id": "pi_test_001",
"status": "requires_review",
"amount_cents": 5000,
"reason": "Monthly vendor payout above auto-approval threshold",
}
slack_ts = post_payment_review_message(test_result)
print({"ok": True, "slack_ts": slack_ts})
Expected output:
{'ok': True, 'slack_ts': '1712345678.000200'}
You should also see a message in the configured Slack channel with the payment review details.
Real-World Use Cases
- •
Refund approval workflows
Let one agent draft refund eligibility from tickets or CRM data, then notify finance in Slack for approval before issuing the refund. - •
Subscription billing operations
Use LangChain to classify upgrade/downgrade requests and route edge cases into Slack for human review when proration rules are unclear. - •
Fraud-sensitive payout orchestration
Have one agent score risk signals and another prepare payout actions; send high-risk cases to a Slack channel before execution.
Keep learning
- •The complete AI Agents Roadmap — my full 8-step breakdown
- •Free: The AI Agent Starter Kit — PDF checklist + starter code
- •Work with me — I build AI for banks and insurance companies
By Cyprian Aarons, AI Consultant at Topiax.
Want the complete 8-step roadmap?
Grab the free AI Agent Starter Kit — architecture templates, compliance checklists, and a 7-email deep-dive course.
Get the Starter Kit