How to Integrate LangGraph for healthcare with LangSmith for AI agents
Combining LangGraph for healthcare with LangSmith gives you something useful in production: a controllable agent workflow plus full observability on every decision, tool call, and state transition. For healthcare, that matters because you need traceability, auditability, and tight control over what the agent is allowed to do.
The pattern is straightforward: use LangGraph for healthcare to model the clinical or admin workflow, then wire LangSmith into the graph so every run is traced, inspected, and debugged.
Prerequisites
- •Python 3.10+
- •A working LangGraph installation
- •A LangSmith account and API key
- •Environment variables configured:
- •
LANGCHAIN_API_KEY - •
LANGCHAIN_TRACING_V2=true - •
LANGCHAIN_PROJECT=healthcare-agent
- •
- •Access to a model provider supported by LangChain, such as OpenAI or Anthropic
- •Basic familiarity with:
- •
StateGraph - •
MessagesState - •
@toolfunctions - •
langsmith.Client
- •
Integration Steps
- •
Install the required packages
You want LangGraph for orchestration, LangChain for model calls, and LangSmith for tracing. In practice, these are the packages I install together:
pip install langgraph langchain langchain-openai langsmithIf you are using a different provider, swap
langchain-openaifor the matching integration package. - •
Set up tracing for LangSmith
LangSmith tracing works through environment variables and the standard LangChain callback stack. This is the lowest-friction way to get traces from a graph run without writing custom instrumentation.
import os os.environ["LANGCHAIN_TRACING_V2"] = "true" os.environ["LANGCHAIN_PROJECT"] = "healthcare-agent" os.environ["LANGCHAIN_API_KEY"] = "ls__your_api_key_here"You can also initialize the client directly if you want to create datasets or inspect runs programmatically:
from langsmith import Client client = Client() print(client) - •
Build a healthcare workflow in LangGraph
Here is a simple triage flow: classify symptoms, decide whether escalation is needed, and generate a response. The important part is that every node in the graph becomes visible in LangSmith when tracing is enabled.
from typing import TypedDict from langgraph.graph import StateGraph, START, END class TriageState(TypedDict): symptoms: str risk_level: str recommendation: str def assess_risk(state: TriageState) -> TriageState: symptoms = state["symptoms"].lower() if "chest pain" in symptoms or "shortness of breath" in symptoms: return {**state, "risk_level": "high"} if "fever" in symptoms or "cough" in symptoms: return {**state, "risk_level": "medium"} return {**state, "risk_level": "low"} def recommend_next_step(state: TriageState) -> TriageState: risk = state["risk_level"] if risk == "high": recommendation = "Escalate to clinician immediately." elif risk == "medium": recommendation = "Recommend same-day telehealth review." else: recommendation = "Provide self-care guidance and monitor." return {**state, "recommendation": recommendation} graph = StateGraph(TriageState) graph.add_node("assess_risk", assess_risk) graph.add_node("recommend", recommend_next_step) graph.add_edge(START, "assess_risk") graph.add_edge("assess_risk", "recommend") graph.add_edge("recommend", END) app = graph.compile() - •
Attach an LLM node and let LangSmith trace it
For real agent systems, you usually need at least one model call. Here’s a minimal example using
ChatOpenAIinside a LangGraph node. Because tracing is enabled globally, both the LLM call and graph execution show up in LangSmith.from typing import TypedDict from langchain_openai import ChatOpenAI from langchain_core.messages import SystemMessage, HumanMessage from langgraph.graph import StateGraph, START, END llm = ChatOpenAI(model="gpt-4o-mini", temperature=0) class AgentState(TypedDict): patient_note: str summary: str def summarize_note(state: AgentState) -> AgentState: messages = [ SystemMessage(content="Summarize the note for clinical triage."), HumanMessage(content=state["patient_note"]), ] result = llm.invoke(messages) return {**state, "summary": result.content} workflow = StateGraph(AgentState) workflow.add_node("summarize_note", summarize_note) workflow.add_edge(START, "summarize_note") workflow.add_edge("summarize_note", END) app = workflow.compile() - •
Run the graph with metadata for auditability
In healthcare systems you should pass metadata like patient cohort, tenant ID, or environment tags. That makes filtering runs in LangSmith much easier during debugging and review.
result = app.invoke( {"patient_note": "Patient reports fever and cough for 3 days."}, config={ "metadata": { "service": "triage", "environment": "dev", "domain": "healthcare", }, "tags": ["triage", "clinical-notes"], }, )
print(result)
## Testing the Integration
Run this small check to confirm both execution and tracing are working:
```python
from langsmith import Client
client = Client()
run = app.invoke(
{"patient_note": "Patient reports chest pain after exertion."},
config={"metadata": {"service": "triage", "environment": "test"}},
)
print(run)
Expected output:
{
'patient_note': 'Patient reports chest pain after exertion.',
'summary': '...',
}
What you should also see in LangSmith:
- •A new trace under your
healthcare-agentproject - •The graph run with node-level visibility
- •The LLM call attached as a child run
- •Metadata and tags available for filtering
Real-World Use Cases
- •
Clinical intake triage
- •Route patient messages through deterministic checks first.
- •Use an LLM only where classification or summarization adds value.
- •Trace every step for QA and compliance review.
- •
Prior authorization agents
- •Build multi-step workflows that extract diagnosis codes, policy criteria, and missing documents.
- •Use LangSmith to inspect failure points when claims get stuck.
- •Keep human review steps explicit in the graph.
- •
Care coordination assistants
- •Summarize discharge notes.
- •Generate follow-up tasks.
- •Track every tool call and model output so ops teams can audit behavior later.
The main advantage here is control. LangGraph gives you a predictable execution model for healthcare workflows, while LangSmith gives you visibility into how the agent behaved when it made each decision.
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