narrow-chef-71655
10/30/2025, 5:56 AMnarrow-chef-71655
10/30/2025, 6:29 AMlively-winter-88668
10/30/2025, 11:48 AMnarrow-chef-71655
10/30/2025, 12:04 PMon_user_turn_completed function (code snippet provided below).
However, when a user asks the agent a question, it needs to create a record in my system, which requires making a tool call. The issue is that during this process, the agent makes the tool call but starts speaking in parallel instead of waiting for the tool’s response. Then, once the tool execution completes, the agent responds again with the same message.
async def on_user_turn_completed(
self, turn_ctx: llm.ChatContext, new_message: llm.ChatMessage
) -> None:
if self.is_observer and new_message.role == "user":
transcript = new_message.text_content.strip()
transcript_lower = transcript.lower()
logging.info(f"case_id {self.case_id} agent_id {self.agent_id} user said: {transcript}")
wake_detected = any(wake in transcript_lower for wake in self.wake_words_lower)
if wake_detected:
logging.info(
f"case_id {self.case_id} agent_id {self.agent_id} Wake word detected! Unmuting agent and responding...")
self.session.output.set_audio_enabled(True)
asyncio.create_task(
create_item_and_send_to_webhook(new_message.text_content, "user", new_message.created_at,
self.room.name, self.webhook_url))
turn_ctx.add_message(role="user", content=new_message.content)
await self.update_chat_ctx(turn_ctx)
clean_query = transcript_lower
for wake in self.wake_words_lower:
clean_query = clean_query.replace(wake, "", 1).strip()
if clean_query:
logging.info(f"clean_query {clean_query}")
await self.session.generate_reply(
instructions=f"Answer this question briefly and directly: {clean_query}",
allow_interruptions=True
)
else:
await self.session.generate_reply(
instructions="The user successfully called you. Respond warmly and ask how you can help.",
allow_interruptions=True
)
logging.info(
f"case_id {self.case_id} agent_id {self.agent_id} Response complete. Clearing chat context and Muting agent again...")
self.session.output.set_audio_enabled(False)
raise StopResponse()
also MCP setting is given below that I am using
mcp.MCPServerHTTP(
url=url,
timeout=20,
client_session_timeout_seconds=20,
)narrow-chef-71655
10/30/2025, 12:07 PMlively-winter-88668
10/31/2025, 10:54 AM