Can I use LiveKit LLM for LangGraph StateGraph?
# ask-ai
f
Can I use LiveKit LLM for LangGraph StateGraph?
t
Thanks for reaching out, Taras. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Absolutely! You can definitely use LiveKit with LangGraph StateGraph through its LangChain integration. The LiveKit LangChain plugin comes with an
LLMAdapter
that makes it super easy to plug your LangGraph workflows right into a LiveKit
AgentSession
as the LLM component. Here’s how you can get started: compile your LangGraph StateGraph and pass it to the
LLMAdapter
when you set up your agent. Check out this example:
Copy code
from langgraph.graph import StateGraph
from livekit.agents import AgentSession, Agent
from livekit.plugins import langchain

def create_workflow():
    workflow = StateGraph(...)
    # Add nodes and edges
    return workflow.compile()

session = AgentSession(
    llm=langchain.LLMAdapter(
        graph=create_workflow()
    ),
    # ... other parameters (stt, tts, etc.)
)
The
LLMAdapter
handles converting LiveKit chat context into LangChain message types seamlessly. Plus, it supports cool features like vision, structured output, and custom models. If you want to dive deeper, the
langgraph_agent.py
example in the LiveKit examples repo is a great resource. Sources: livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/llm.py | LangChain integration guide | LiveKit Docs | Large language model (LLM) integrations | LiveKit Docs
f
where can I find langgraph_agent.py?
t
Hey! You can find the
langgraph_agent.py
file over in the LiveKit Agents GitHub repository right here: https://github.com/livekit/agents/blob/main/examples/voice_agents/langgraph_agent.py This example is a great way to see how LangGraph works with LiveKit Agents, showing you how to handle voice orchestration and use LangGraph workflows inside a voice agent. If you have any questions, feel free to ask! Sources: livekit-plugins/livekit-plugins-langchain/README.md