hello I’ve recently started building a LiveKit age...
# ask-ai
t
hello I’ve recently started building a LiveKit agent and I’m using LangGraph to orchestrate the workflow. I’d really appreciate any resources or code examples you can share. Thanks in advance!
t
Thanks for reaching out, med. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm here to help you get started with building a LiveKit agent using LangGraph! To make things easier, I've gathered some helpful resources and examples for you: • LangChain Integration Guide • Complete Example Code • Plugin Source Code • Voice Agent Examples To get you going, here’s how you can install the necessary packages:
Copy code
# Install the core LangChain plugin
pip install livekit-plugins-langchain

# Install LiveKit agents with voice and LangChain support
pip install "livekit-agents[openai,silero,langchain,deepgram,turn_detector]"
For a hands-on example, check out the langgraph_agent.py file—it’s a great guide on integrating LangGraph workflows with LiveKit’s real-time voice features. If you run into any bumps or have questions along the way, please don’t hesitate to reach out. I’m here to support you! Sources: agent-examples/pyproject.toml | Workflows | LiveKit Docs | Community & Support | livekit/livekit_composite | DeepWiki | LangChain integration guide | LiveKit Docs | README.md
t
so i trying to implement a complex workflow and the code exemple given does not go beond one node
t
I'm glad you're interested in implementing a complex workflow with multiple nodes in LangGraph! You can definitely build on the single-node example by adding more nodes, setting up conditional edges, and managing state effectively. Here’s a friendly overview to get you started: • First, define several nodes in your LangGraph workflow, each dedicated to a particular task or piece of logic. • Then, use conditional edges to navigate between these nodes based on user input or the current state. • Finally, integrate your compiled LangGraph workflow into LiveKit by using the
LLMAdapter
. To make things clearer, here’s a detailed example of how a multi-node workflow might look:
Copy code
from langgraph.graph import StateGraph, START, END
from langgraph.graph.message import add_messages
from langchain_core.messages import SystemMessage
from typing import TypedDict, Annotated, List

class State(TypedDict):
    messages: Annotated[List, add_messages]
    user_intent: str

def route_intent(state: State):
    # Logic to classify user intent
    pass

def handle_order(state: State):
    # Logic for order handling
    pass

def handle_support(state: State):
    # Logic for support handling
    pass

def create_complex_graph() -> StateGraph:
    workflow = StateGraph(State)
    workflow.add_node("route_intent", route_intent)
    workflow.add_node("handle_order", handle_order)
    workflow.add_node("handle_support", handle_support)
    workflow.add_edge(START, "route_intent")
    workflow.add_conditional_edges("route_intent", lambda state: "handle_order" if state["user_intent"] == "order" else "handle_support")
    workflow.add_edge("handle_order", END)
    workflow.add_edge("handle_support", END)
    return workflow.compile()
If you’d like to explore more, the LangGraph agent example is a fantastic resource that you can adapt to include multiple nodes and custom logic. And of course, if you have any questions or want help with specific parts of your workflow, just let me know—I’m here to help! Sources: LangChain integration guide | LiveKit Docs | livekit-plugins/livekit-plugins-langchain/README.md | Workflows | LiveKit Docs
t
this does not work the agent tend to riun all the steps at once
t
I understand how it can be a bit confusing when all the steps seem to run at once in your LangGraph workflow. This usually happens if the workflow isn’t set up for conditional execution just right. The great thing about LangGraph is that it supports step-by-step execution through its streaming architecture, which processes each step one at a time based on certain conditions. To help you get that smooth conditional routing, here are a few tips: • Try using the
add_conditional_edges
method in your workflow. This helps define the logic for moving between nodes depending on the state or what the user inputs. • Make sure each node only runs its logic when it’s triggered by the step before it. • Double-check that your
LLMAdapter
is set up correctly to use the compiled LangGraph workflow with
stream_mode="messages"
. If you’d like, feel free to share more about how your workflow is set up. I’d be happy to take a closer look and help you fine-tune it so the steps run just the way you want, without all of them firing at once. Sources: uv.lock | LangChain integration guide | LiveKit Docs
t
the issue is that the user does not interrupt the workflow
t
I completely understand how important it is for user interruptions to smoothly fit into your workflow. Luckily, LiveKit has some great built-in features to help with this! Here are a few friendly tips to get things working just right: • Make sure interruptions are enabled in the
AgentSession
by setting
allow_interruptions=True
(this is actually the default setting). • Adjust parameters like
min_interruption_words
and
false_interruption_timeout
to better control when interruptions should kick in. • Double-check that your LangGraph workflow is connected with LiveKit through the
LLMAdapter
, which helps keep the workflow updated in real time based on what the user says. If you’d like, feel free to share your current setup with me—I’m here to help you troubleshoot or guide you through implementing these settings so everything runs smoothly for you. Sources: Agent Session & Client Integration | livekit/livekit_composite | DeepWiki | LangChain integration guide | LiveKit Docs | basics/interrupts_user.py | Turn detection and interruptions | LiveKit Docs | examples/voice_agents/resume_interrupted_agent.py
t
can't we escalate the issue to some humain guidance
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!