ancient-judge-59849
02/14/2025, 9:03 PMgray-monkey-83525
02/14/2025, 9:03 PMallow_interruptions
, interrupt_speech_duration
, and interrupt_min_words
. These parameters are part of the agent's setup and can be configured when initializing the agent. For example, setting allow_interruptions
to False
will disable interruptions, while interrupt_speech_duration
and interrupt_min_words
control the conditions under which interruptions are considered intentional.
Would you like more details on how to implement these changes?
Sources:
- VoicePipelineAgent Interruption Handling
- VoicePipelineAgent Configuration 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.ancient-judge-59849
02/25/2025, 3:23 AMgray-monkey-83525
02/25/2025, 3:23 AMancient-judge-59849
02/25/2025, 5:12 AMgray-monkey-83525
02/25/2025, 5:12 AMasync def switch_agent(ctx, user_variable):
if user_variable == 1:
# Initialize Agent 1
agent = Agent1()
elif user_variable == 2:
# Initialize Agent 2
agent = Agent2()
await agent.start(ctx.room)
# Function to update user variable and switch agents
async def update_variable_and_switch(ctx, new_value):
user_variable = new_value
await switch_agent(ctx, user_variable)
This approach allows you to manage agent transitions based on the user variable dynamically.
Would you like more detailed guidance or a specific code example?
Sources:
- Managing Agent State 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.ancient-judge-59849
02/25/2025, 5:13 AMgray-monkey-83525
02/25/2025, 5:13 AMasync def handle_conversation(ctx, user_variable):
# Start with the initial agent
agent = Agent1()
await agent.start(ctx.room)
# Function to handle switching
async def switch_agent(new_value):
nonlocal agent
user_variable = new_value
await agent.stop() # Stop the current agent
# Initialize the new agent based on the updated variable
if user_variable == 1:
agent = Agent1()
elif user_variable == 2:
agent = Agent2()
await agent.start(ctx.room) # Start the new agent
# Example of detecting a trigger and switching agents
@agent.on("message_received")
async def on_message_received(msg):
if "switch" in msg.content: # Example trigger
await switch_agent(2) # Update variable and switch agent
# Start handling the conversation
await handle_conversation(ctx, user_variable=1)
This setup allows you to dynamically switch agents based on the conversation flow, ensuring that the participant's input determines the active agent.
Would you like further clarification or assistance with specific parts of this process?
Sources:
- Managing Agent State 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.ancient-judge-59849
02/25/2025, 5:15 AMgray-monkey-83525
02/25/2025, 5:15 AMimport asyncio
from livekit.agents import VoicePipelineAgent
from livekit.plugins import openai, silero, deepgram
async def handle_conversation(ctx):
user_variable = 1 # Initial state
# Define agents
agent1 = VoicePipelineAgent(
vad=silero.VAD.load(),
stt=deepgram.STT(model="nova-2-general"),
llm=openai.LLM(model="gpt-3.5-turbo"),
tts=openai.TTS(model="tts-1", voice="alloy"),
chat_ctx=openai.ChatContext().append(role="system", text="You are Agent 1."),
)
agent2 = VoicePipelineAgent(
vad=silero.VAD.load(),
stt=deepgram.STT(model="nova-2-general"),
llm=openai.LLM(model="gpt-3.5-turbo"),
tts=openai.TTS(model="tts-1", voice="shimmer"),
chat_ctx=openai.ChatContext().append(role="system", text="You are Agent 2."),
)
# Start with Agent 1
current_agent = agent1
await current_agent.start(ctx.room)
async def switch_agent(new_value):
nonlocal current_agent, user_variable
user_variable = new_value
await current_agent.stop() # Stop the current agent
# Switch to the new agent based on the updated variable
if user_variable == 1:
current_agent = agent1
elif user_variable == 2:
current_agent = agent2
await current_agent.start(ctx.room) # Start the new agent
# Example of detecting a trigger and switching agents
@current_agent.on("message_received")
async def on_message_received(msg):
if "switch" in msg.content: # Example trigger
await switch_agent(2) # Update variable and switch agent
# Example usage
async def main():
# Assuming ctx is a valid JobContext
await handle_conversation(ctx)
# Run the main function in an asyncio event loop
if __name__ == "__main__":
asyncio.run(main())
This code sets up two agents with different configurations and switches between them based on a trigger word "switch" in the conversation. The switch_agent
function handles stopping the current agent and starting the new one.
Would you like more details or modifications to this example?
Sources:
- https://livekit-users.slack.com/archives/C07FY8WHGPM/p1732895035.813109
- https://livekit-users.slack.com/archives/C07FY8WHGPM/p1730355369.957779 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.