limited-planet-15554
10/24/2025, 1:18 PMtall-airline-16756
10/24/2025, 1:18 PMtall-airline-16756
10/24/2025, 1:19 PMsession.interrupt() method. By default, interruptions are turned on, so the agent will pause speaking and adjust its conversation history to include only what the user heard before the interruption—pretty neat, right?
For instance, if you're working on longer tasks like a web search, the system gracefully handles interruptions by canceling the ongoing operation if the user steps in mid-execution. And if you have critical or irreversible actions, you can easily disable interruptions at the tool level using run_ctx.disallow_interruptions(), giving you full control.
Plus, you can tailor the interruption behavior to your needs with parameters like allow_interruptions, min_interruption_duration, and min_interruption_words right in the AgentSession constructor.
If you'd like to see how this works in practice, feel free to check out these helpful examples:
• Long Running Tools Example
• Interrupt User Example Sources: livekit-agents/livekit/agents/voice/agent_activity.py | Tool definition and use | LiveKit Docs | docs/index.yaml | Turn detection and interruptions | LiveKit Docs | Docs::Agentslimited-planet-15554
10/24/2025, 1:47 PMtall-airline-16756
10/24/2025, 1:48 PMAgentSession class is designed to automatically keep track of states like initializing, listening, thinking, or speaking. Plus, if you want to customize, developers can use userdata for managing custom state, which you can access within tools via the RunContext. This setup makes it easy to handle session-based CRUD operations and share state smoothly between the agent and frontend.
Now, LangGraph shines when it comes to workflow orchestration, especially with persistent state graphs for more complex workflows. But here’s a great tip: LiveKit can work hand-in-hand with LangGraph through the langchain.LLMAdapter. This way, LangGraph can take care of reasoning and state transitions, while LiveKit focuses on real-time communication.
If you’d like to see state management in action with LiveKit, I recommend checking out the RPC Agent Example in the LiveKit examples repository. It’s a helpful resource to get you started!
Sources: Web and mobile frontends | LiveKit Docs | Workflows | LiveKit Docs | docs/index.yaml | examples/voice_agents/README.mdlimited-planet-15554
10/24/2025, 1:48 PMtall-airline-16756
10/24/2025, 1:49 PMuserdata to handle session-based state in a friendly and straightforward way:
from livekit.agent import AgentSession
from dataclasses import dataclass
@dataclass
class UserData:
user_name: str
task_list: list
# Initialize session with custom userdata
session = AgentSession(userdata=UserData(user_name="John", task_list=[]))
# Access and modify state within a tool
def add_task(run_ctx):
task = run_ctx.input.get("task")
run_ctx.userdata.task_list.append(task)
return f"Task '{task}' added. Current tasks: {run_ctx.userdata.task_list}"
# Example usage
session.register_tool("add_task", add_task)
response = session.run_tool("add_task", {"task": "Complete report"})
print(response) # Output: Task 'Complete report' added. Current tasks: ['Complete report']
This example gently walks you through initializing a session with your own custom state, updating it within a tool, and keeping it consistent across different interactions. If you're interested in exploring more advanced topics like RPC-based state management or working with multi-agent workflows, just let me know—I’d be happy to guide you through those as well!