wooden-magazine-46516
12/28/2025, 6:41 PMtall-airline-16756
12/28/2025, 6:41 PMtall-airline-16756
12/28/2025, 6:42 PMlangchain.LLMAdapter(graph=...), and
4. passes it into AgentSession so the workflow runs as the agent’s LLM.
Tell me which option you prefer (example code vs runtime/config/troubleshooting) and your environment details and I’ll respond with the exact snippet and next steps.
Sources: LangChain integration guide | LiveKit docswooden-magazine-46516
12/28/2025, 6:44 PMtall-airline-16756
12/28/2025, 6:44 PMLLMAdapter, and pass it into an AgentSession so the workflow acts as the agent’s LLM.
1) Install the plugin:
uv add "livekit-agents[langchain]~=1.3"
2) Example code:
# example_agent_with_langgraph.py
from langgraph.graph import StateGraph
from livekit.agents import AgentSession, Agent
from livekit.plugins import langchain
# 1. Define and compile a simple LangGraph workflow
def create_workflow():
graph = StateGraph()
# Example nodes (replace with real nodes/logic)
# Add states/nodes according to your LangGraph design.
# This is illustrative; use actual node constructors you need.
start = graph.add_state("start")
ask = graph.add_state("ask_user")
respond = graph.add_state("respond")
graph.add_edge(start, ask)
graph.add_edge(ask, respond)
# Compile the graph to get the runtime PregelProtocol
return graph.compile()
# 2. Wrap the compiled workflow with LLMAdapter
llm_adapter = langchain.LLMAdapter(
graph=create_workflow(),
# config optional, e.g. runtime settings or callbacks
# config=my_runnable_config
)
# 3. Create an Agent (optional: configure callbacks, tools, etc.)
agent = Agent(name="langgraph-agent")
# 4. Start an AgentSession using the LLMAdapter as the session's llm
session = AgentSession(
llm=llm_adapter,
agent=agent,
# Optionally configure STT, TTS, VAD, audio, and other runtime pieces here.
# stt=..., tts=..., vad=...
)
# 5. Run the session (API depends on your environment; example placeholder)
# session.run() or await session.start() depending on sync/async runtime
Notes:
• Replace the placeholder LangGraph nodes/edges with your actual states and node implementations.
• LLMAdapter accepts graph (compiled workflow) and optional config for runtime settings or callbacks.
• Configure AgentSession parameters (STT, TTS, VAD, async vs sync) to match your application runtime.
If you want, I can:
• Provide a complete runnable example with concrete LangGraph node types,
• Show async usage (await/async session start),
• Or add an example RunnableConfig for callbacks — which would you prefer?wooden-magazine-46516
12/28/2025, 6:47 PMtall-airline-16756
12/28/2025, 6:48 PMconfig parameter.
Below is a concise Python example showing:
• compiled LangGraph workflow wrapped by LLMAdapter
• LangSmith tracing via LangChainTracer added to config
• required environment variables note
# example_langsmith_integration.py
from langgraph.graph import StateGraph
from livekit.agents import AgentSession, Agent
from livekit.plugins import langchain
from langchain.callbacks.tracers import LangChainTracer
from langchain.callbacks.manager import CallbackManager
def create_workflow():
graph = StateGraph()
# add your states/nodes/edges here
return graph.compile()
# Create LangChain tracer (LangSmith)
tracer = LangChainTracer() # optional: tracer(project_name="my-project")
# Pass callbacks via the Runnable config used by LLMAdapter
runnable_config = {
"callbacks": [tracer]
}
llm_adapter = langchain.LLMAdapter(
graph=create_workflow(),
config=runnable_config
)
agent = Agent(name="langgraph-langsmith-agent")
session = AgentSession(
llm=llm_adapter,
agent=agent,
# stt=..., tts=..., vad=...
)
# Start/run session according to your runtime (sync or async)
# e.g. await session.start()
Environment setup:
• Set LangSmith / LangChain tracing env vars, e.g. LANGCHAIN_TRACING_V2=true and your LangSmith API key (e.g., LANGCHAIN_TRACING_V2_IN_MEMORY=false and provider-specific key) so tracing uploads succeed.
If you’d like, I can:
• provide a fully runnable async example with concrete LangGraph nodes,
• show tracer configuration options (project name, session metadata), or
• help troubleshoot tracer auth/env var settings — which would you prefer? Sources: LangChain integration guide | LiveKit docs