strong-pizza-31661
08/03/2025, 9:19 PMvoiceAgentMultiLogging.py so that # automatic activity detection and related sensitivities are aligned across # our agents. rt_cfg = genai_types.RealtimeInputConfig( automatic_activity_detection={ "disabled": False, "start_of_speech_sensitivity": "START_SENSITIVITY_LOW", "end_of_speech_sensitivity": "END_SENSITIVITY_LOW", "prefix_padding_ms": 20, "silence_duration_ms": 100, } ) import os load_dotenv() # Load Pronet agent prompt (English) PRONET_PROMPT = Path("pronet_agent_prompt_en.txt").read_text(encoding="utf-8") class Assistant(Agent): def __init__(self) -> None: super().__init__(instructions=PRONET_PROMPT) async def entrypoint(ctx: agents.JobContext): await ctx.connect() model = google.beta.realtime.RealtimeModel( api_key=os.getenv("GEMINI_API_KEY"), model="gemini-live-2.5-flash-preview", modalities=["text"], temperature=0.8, #input_audio_transcription=None, realtime_input_config=rt_cfg, # <- typed object with the attr LK needs ) # Create AgentSession with the multimodal model session = AgentSession( llm=model, tts=elevenlabs.TTS( voice_id="cgSgspJ2msm6clMCkdW9", language="en", streaming_latency=3, ), ) # -------------------------------------------------- # DATA COLLECTION: track conversation items # -------------------------------------------------- chat_history: list[dict] = [] @session.on("conversation_item_added") def _on_item(ev): if hasattr(ev.item, "role"): role = ev.item.role text_content = getattr(ev.item, "text_content", "") or "" chat_history.append({"role": role, "text": text_content}) # Instantiate your Assistant agent and start the voice session agent_instance = Assistant() await session.start( room=ctx.room, agent=agent_instance, ) # -------------------------------------------------- # OUTPUT COLLECTED DATA # -------------------------------------------------- print("\n=== Conversation Transcript ===") for turn in chat_history: print(f"{turn['role']}: {turn['text']}") print("=== End of Transcript ===\n") if name == "__main__": agents.cli.run_app(agents.WorkerOptions(entrypoint_fnc=entrypoint))tall-airline-16756
08/03/2025, 9:19 PMtall-airline-16756
08/03/2025, 9:20 PMstrong-pizza-31661
08/03/2025, 9:20 PMtall-airline-16756
08/03/2025, 9:22 PMrealtime_input_config parameter includes activity_handling=types.ActivityHandling.INTERRUPTION. 2. Session Configuration: - When you create the AgentSession, set allow_interruptions=True and pick a good value for min_interruption_duration (like 0.5 seconds). 3. Activity Detection: - Double-check that automatic_activity_detection is turned on and set up right so it can catch when you start talking. 4. Event Handling: - Use callbacks like on_input_speech_started to keep an eye on interruptions and handle them as they happen. If you want, I’m here to help you walk through adding these to your code—just let me know! Sources: livekit-agents/livekit/agents/voice/agent_session.pystrong-pizza-31661
08/03/2025, 9:37 PMvoiceAgentMultiLogging.py so that
# automatic activity detection and related sensitivities are aligned across
# our agents.
rt_cfg = genai_types.RealtimeInputConfig(
# Enable interruption handling if supported by current SDK version; fallback gracefully.
_activity_handling_=getattr(genai_types.ActivityHandling, "INTERRUPTION", genai_types.ActivityHandling.NO_INTERRUPTION),
_automatic_activity_detection_={
"disabled": False,
"start_of_speech_sensitivity": "START_SENSITIVITY_LOW",
"end_of_speech_sensitivity": "END_SENSITIVITY_LOW",
"prefix_padding_ms": 20,
"silence_duration_ms": 100,
}
)
import os
load_dotenv()
# Load Pronet agent prompt (English)
PRONET_PROMPT = Path("pronet_agent_prompt_en.txt").read_text(encoding="utf-8")
class Assistant(Agent):
def __init__(self) -> None:
super().__init__(instructions=PRONET_PROMPT)
# ------------------------------
# INTERRUPTION EVENT CALLBACKS
# ------------------------------
def on_user_started_speaking(self) -> None:
print("🔊 User started speaking (interruption detected)")
def on_user_stopped_speaking(self) -> None:
print("🔈 User stopped speaking")
def on_agent_speech_interrupted(self) -> None:
print("⛔️ Agent speech interrupted by user")
async def entrypoint(_ctx_: agents.JobContext):
await ctx.connect()
model = google.beta.realtime.RealtimeModel(
_api_key_=os.getenv("GEMINI_API_KEY"),
model="gemini-live-2.5-flash-preview",
modalities=["text"],
temperature=0.8,
_#input_audio_transcription=None,_
_realtime_input_config_=rt_cfg, # <- typed object with the attr LK needs
)
# Create AgentSession with the multimodal model
session = AgentSession(
llm=model,
tts=elevenlabs.TTS(
_voice_id_="cgSgspJ2msm6clMCkdW9",
language="en",
_streaming_latency_=3,
),
_allow_interruptions_=True,
_min_interruption_duration_=0.5,
)
# --------------------------------------------------
# DATA COLLECTION: track conversation items
# --------------------------------------------------
chat_history: list[dict] = []
@session.on("conversation_item_added")
def _on_item(ev):
if hasattr(ev.item, "role"):
role = ev.item.role
text_content = getattr(ev.item, "text_content", "") or ""
chat_history.append({"role": role, "text": text_content})
# Instantiate your Assistant agent and start the voice session
agent_instance = Assistant()
await session.start(
room=ctx.room,
agent=agent_instance,
)
# --------------------------------------------------
# OUTPUT COLLECTED DATA
# --------------------------------------------------
print("\n=== Conversation Transcript ===")
for turn in chat_history:
print(f"{turn['role']}: {turn['text']}")
print("=== End of Transcript ===\n")
if name == "__main__":
agents.cli.run_app(agents.WorkerOptions(_entrypoint_fnc_=entrypoint))tall-airline-16756
08/03/2025, 9:37 PMactivity_handling=genai_types.ActivityHandling.INTERRUPTION in RealtimeInputConfig perfectly to enable interruption handling. 2. Callbacks for Interruption Events: - The methods on_user_started_speaking, on_user_stopped_speaking, and on_agent_speech_interrupted are all set up nicely to handle and log those interruption events. 3. Session Configuration: - Using allow_interruptions=True and min_interruption_duration=0.5 in your AgentSession looks spot on to allow and detect interruptions properly. 4. Realtime Model Configuration: - Passing realtime_input_config to the RealtimeModel is done correctly. If you’re still running into any issues, it might be worth double-checking that your GEMINI_API_KEY is valid and that your SDK version supports these settings. Feel free to reach out if you want me to help troubleshoot further!