How to Integrate LangGraph for investment banking with LangSmith for AI agents
Combining LangGraph for investment banking with LangSmith gives you a production-grade control plane for agent workflows. You get deterministic orchestration for things like deal screening, KYC triage, and market-data driven analysis, plus traceability when a banker asks, “why did the agent recommend this?”
Prerequisites
- •Python 3.10+
- •
langgraph - •
langchain - •
langsmith - •An OpenAI API key or another model provider supported by LangChain
- •A LangSmith account and project created
- •Environment variables set:
- •
LANGCHAIN_TRACING_V2=true - •
LANGCHAIN_API_KEY=... - •
LANGCHAIN_PROJECT=... - •
OPENAI_API_KEY=...
- •
Install the packages:
pip install langgraph langchain langsmith langchain-openai
Integration Steps
- •
Set up LangSmith tracing first
LangSmith works best when tracing is enabled before you build the graph. This gives you full visibility into every node execution, prompt, tool call, and retry.
import os
os.environ["LANGCHAIN_TRACING_V2"] = "true"
os.environ["LANGCHAIN_API_KEY"] = "lsv2_YourLangSmithApiKey"
os.environ["LANGCHAIN_PROJECT"] = "investment-banking-agent"
os.environ["OPENAI_API_KEY"] = "sk-your-openai-key"
- •
Create the graph state and model
For investment banking workflows, keep state explicit. You want to carry deal metadata, analyst notes, risk flags, and the final recommendation through the graph.
from typing import TypedDict, Annotated
from operator import add
from langchain_openai import ChatOpenAI
from langgraph.graph import StateGraph, START, END
class DealState(TypedDict):
company_name: str
sector: str
revenue: float
ebitda_margin: float
risk_flags: list[str]
recommendation: str
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
- •
Define graph nodes for banking tasks
Split the workflow into deterministic steps. One node can classify risk flags, another can draft a recommendation using those flags.
def assess_deal(state: DealState) -> dict:
prompt = f"""
You are an investment banking analyst.
Company: {state['company_name']}
Sector: {state['sector']}
Revenue: {state['revenue']}
EBITDA Margin: {state['ebitda_margin']}
Return only a short list of risk flags.
"""
response = llm.invoke(prompt)
flags = [line.strip("- ").strip() for line in response.content.splitlines() if line.strip()]
return {"risk_flags": flags}
def draft_recommendation(state: DealState) -> dict:
prompt = f"""
You are writing an investment committee note.
Company: {state['company_name']}
Sector: {state['sector']}
Revenue: {state['revenue']}
EBITDA Margin: {state['ebitda_margin']}
Risk Flags: {state['risk_flags']}
Write a concise recommendation.
"""
response = llm.invoke(prompt)
return {"recommendation": response.content}
- •
Build and compile the LangGraph workflow
This is where LangGraph becomes useful for banking systems. You get a clear execution path that is easier to audit than a single monolithic agent loop.
workflow = StateGraph(DealState)
workflow.add_node("assess_deal", assess_deal)
workflow.add_node("draft_recommendation", draft_recommendation)
workflow.add_edge(START, "assess_deal")
workflow.add_edge("assess_deal", "draft_recommendation")
workflow.add_edge("draft_recommendation", END)
app = workflow.compile()
- •
Run the graph with LangSmith tracing enabled
When tracing is enabled, every call through
app.invoke()is captured in LangSmith automatically. That gives you node-level visibility without changing your business logic.
initial_state = {
"company_name": "Northstar Payments",
"sector": "Fintech",
"revenue": 185_000_000,
"ebitda_margin": 0.31,
"risk_flags": [],
"recommendation": "",
}
result = app.invoke(initial_state)
print(result["risk_flags"])
print(result["recommendation"])
Testing the Integration
Use a smoke test that validates both orchestration and tracing behavior. The graph should return a populated recommendation, and the run should appear in your LangSmith project.
def test_integration():
result = app.invoke({
"company_name": "Apex Capital Markets",
"sector": "Investment Banking",
"revenue": 420_000_000,
"ebitda_margin": 0.27,
"risk_flags": [],
"recommendation": "",
})
assert isinstance(result["risk_flags"], list)
assert len(result["recommendation"]) > 0
print("Integration OK")
print("Recommendation:", result["recommendation"][:120])
test_integration()
Expected output:
Integration OK
Recommendation: ...
In LangSmith, you should see:
- •one trace for the graph run
- •separate child runs for each node
- •model calls attached to each node execution
Real-World Use Cases
- •
Deal screening agents
Classify inbound opportunities by sector fit, leverage profile, margin quality, and red flags before an analyst touches them. - •
KYC / AML triage workflows
Route cases through graph nodes that extract entities, check sanctions exposure, summarize findings, and escalate suspicious activity with full traceability. - •
Investment committee memo generation
Turn raw financials and analyst notes into structured IC drafts with auditable intermediate steps in LangSmith.
If you want this pattern to hold up in production, keep your graph nodes small, make state explicit, and use LangSmith traces as part of your review process. That combination gives you control over agent behavior without turning every workflow into a black box.
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