I wish to integrate langgraph as LLM within liveki...
# ask-ai
f
I wish to integrate langgraph as LLM within livekit. But when creating AgentSession, I am required to pass in an agent, do i just create an agent that is unrelated to the langgraph? how does this work?
t
Thanks for reaching out, Mok. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm glad you're interested in integrating LangGraph as an LLM within LiveKit to create an
AgentSession
! To help you get started smoothly, you can use the LiveKit LangChain plugin, which nicely wraps LangGraph workflows for you. Here's a simple overview to guide you: 1. First, install the LiveKit LangChain plugin by running
pip install livekit-plugins-langchain
. 2. Next, create your LangGraph workflow and wrap it using the
langchain.LLMAdapter
. This adapter helps connect LiveKit's chat context with LangGraph's message format seamlessly. 3. Then, set up an
Agent
by using the LangGraph workflow wrapped in the adapter. 4. Finally, configure and start an
AgentSession
with components like VAD (Voice Activity Detection), STT (Speech-to-Text), TTS (Text-to-Speech), and turn detection. This session will manage the voice pipeline and bring your LangGraph workflow to life. If you'd like, I’d be more than happy to provide detailed code examples or walk you through any part of the process. Just let me know—I’m here to help! Sources: livekit-plugins/livekit-plugins-langchain/livekit/plugins/langchain/__init_... | Building voice agents | LiveKit Docs
f
I have set up the AgentSession with langchain.LLMAdapter. However, when defining WorkerOptions, I am required to pass in an agent
t
Thanks for reaching out! Could you please let me know if you're working with Python or Node.js? The way you define
WorkerOptions
and pass an agent can be a bit different depending on the language and setup, so I want to make sure I guide you correctly. Sources: agents/src/worker.ts | Node.js Agents Architecture | livekit/livekit_composite | DeepWiki | examples/avatar_agents/simli/agent_worker.py | LangChain integration guide | LiveKit Docs
f
I am working with python
t
When working with Python and defining
WorkerOptions
, it’s important to know that you don’t pass an agent directly. Instead, you’ll want to create an
entrypoint_fnc
function where the agent is set up and configured. Here’s a friendly guide on how to do it: 1. Inside the
entrypoint_fnc
, create your agent using
langchain.LLMAdapter
along with your LangGraph workflow. 2. Then, pass this
entrypoint_fnc
to
WorkerOptions
when you start the worker with
cli.run_app()
. Here’s a simple example to illustrate:
Copy code
def entrypoint(ctx: JobContext):
    graph = create_graph()
    agent = Agent(instructions="", llm=langchain.LLMAdapter(graph))
    session = AgentSession(
        vad=ctx.proc.userdata["vad"],
        stt=deepgram.STT(model="nova-3", language="multi"),
        tts=deepgram.TTS(),
        turn_detection=MultilingualModel(),
    )
    await session.start(agent=agent, room=ctx.room)

def prewarm(proc: JobProcess):
    proc.userdata["vad"] = silero.VAD.load()

if __name__ == "__main__":
    cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint, prewarm_fnc=prewarm))
This way, your agent is nicely initialized and ready to be used in the
AgentSession
at runtime. If anything feels unclear or if you want me to walk you through any part, just let me know—I’m here to help!