How to Integrate LangChain for banking with Slack for AI agents
If you’re building AI agents for banking workflows, Slack is usually where the human side of the system already lives. Pairing it with LangChain for banking gives you a clean path from internal chat to controlled retrieval, policy-aware responses, and approval flows without forcing users into another UI.
This integration is useful when an agent needs to answer account questions, summarize transactions, draft compliance-safe responses, or route sensitive requests to a banker in Slack.
Prerequisites
- •Python 3.10+
- •A Slack workspace with:
- •a Slack app created in the API dashboard
- •
chat:write,channels:read,groups:read,im:read,im:write, andapp_mentions:readscopes - •a bot token (
xoxb-...) - •signing secret
- •Access to your banking data layer or sandbox API
- •LangChain installed with your banking integration package
- •Environment variables configured:
- •
SLACK_BOT_TOKEN - •
SLACK_SIGNING_SECRET - •bank API credentials or sandbox keys
- •any LangChain model/provider keys you use
- •
Install the core packages:
pip install slack-bolt slack-sdk langchain langchain-community python-dotenv
If your banking stack exposes tools or retrievers through LangChain, install that package too. In most production setups, you’ll wrap your bank API client as a LangChain tool.
Integration Steps
1) Build a banking tool for LangChain
Start by exposing only the bank operations you want the agent to use. Don’t hand the model direct database access; wrap approved endpoints as tools.
import os
import requests
from langchain_core.tools import tool
BANK_API_BASE = os.getenv("BANK_API_BASE", "https://sandbox.bank.example.com")
BANK_API_KEY = os.getenv("BANK_API_KEY")
@tool
def get_account_balance(account_id: str) -> str:
"""Fetch the current balance for an approved account."""
resp = requests.get(
f"{BANK_API_BASE}/accounts/{account_id}/balance",
headers={"Authorization": f"Bearer {BANK_API_KEY}"},
timeout=10,
)
resp.raise_for_status()
data = resp.json()
return f"Account {account_id} balance is {data['currency']} {data['balance']}"
For banking agents, keep the tool surface narrow. Add allowlists, audit logging, and request IDs before you ship this to production.
2) Create a LangChain agent that uses the banking tool
Now wire the tool into a LangChain agent. The agent can answer questions from Slack by calling approved functions instead of guessing.
from langchain_openai import ChatOpenAI
from langchain.agents import create_tool_calling_agent, AgentExecutor
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
prompt = ChatPromptTemplate.from_messages([
("system", "You are a banking assistant. Use tools for account data. Never invent balances."),
("human", "{input}"),
MessagesPlaceholder(variable_name="agent_scratchpad"),
])
tools = [get_account_balance]
agent = create_tool_calling_agent(llm, tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
This pattern works well when your agent needs deterministic access to bank systems and natural-language reasoning on top.
3) Connect Slack events to the agent
Use Slack Bolt to receive mentions or direct messages. When a user asks a question in Slack, forward it to the LangChain executor and post the result back.
import os
from slack_bolt import App
from slack_sdk.web.client import WebClient
slack_app = App(
token=os.environ["SLACK_BOT_TOKEN"],
signing_secret=os.environ["SLACK_SIGNING_SECRET"],
)
@slack_app.event("app_mention")
def handle_mention(event, say):
user_text = event.get("text", "")
channel_id = event["channel"]
result = executor.invoke({"input": user_text})
say(text=result["output"], channel=channel_id)
if __name__ == "__main__":
slack_app.start(port=int(os.getenv("PORT", "3000")))
If you need richer control, use WebClient.chat_postMessage() directly instead of say(). The Bolt abstraction is enough for most bot workflows.
4) Add an approval flow for sensitive actions
For anything that changes state — transfers, limit changes, card freezes — don’t let the agent act immediately. Post a draft response in Slack and wait for human approval.
from slack_sdk import WebClient
client = WebClient(token=os.environ["SLACK_BOT_TOKEN"])
def request_approval(channel_id: str, summary: str):
return client.chat_postMessage(
channel=channel_id,
text=f"Approval needed:\n{summary}\nReact with :white_check_mark: to approve."
)
def freeze_card(card_id: str) -> str:
# Replace with your internal workflow or bank API call.
return f"Card {card_id} freeze requested"
@slack_app.event("message")
def handle_message(event):
text = event.get("text", "")
if "freeze card" in text.lower():
summary = f"User requested card freeze workflow: `{text}`"
request_approval(event["channel"], summary)
In regulated environments, this pattern matters more than model quality. Human-in-the-loop approval is what keeps your bot usable by compliance teams.
5) Route replies back into threaded Slack conversations
Keep each request in a thread so bankers can follow context. That makes audits easier and reduces noise in busy channels.
@slack_app.event("app_mention")
def handle_threaded_mention(event, say):
channel_id = event["channel"]
thread_ts = event.get("ts")
user_text = event.get("text", "")
result = executor.invoke({"input": user_text})
client.chat_postMessage(
channel=channel_id,
thread_ts=thread_ts,
text=result["output"],
)
Threaded replies are especially useful when an agent pulls balances, flags anomalies, then hands off to a human banker for confirmation.
Testing the Integration
Run your Slack app locally with ngrok or Socket Mode enabled, then mention the bot in a test channel.
test_input = {"input": "What is the balance for account 12345?"}
result = executor.invoke(test_input)
print(result["output"])
Expected output:
Account 12345 balance is USD 15420.88
If Slack is wired correctly too, you should see the same response posted back into the channel thread after mentioning the bot.
Real-World Use Cases
- •
Balance and transaction Q&A
- •Employees ask in Slack for account summaries.
- •The agent pulls data through approved LangChain tools and responds with controlled formatting.
- •
Ops escalation assistant
- •The agent detects high-risk requests like freezes or reversals.
- •It posts an approval message in Slack and waits for a banker to confirm.
- •
Compliance-safe customer support drafting
- •The agent drafts responses from policy documents and customer context.
- •A human reviews and sends from Slack before anything reaches the customer.
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