@@ -572,6 +572,28 @@ def _get_current_turn_contents(
572572
573573def _is_other_agent_reply (current_agent_name : str , event : Event ) -> bool :
574574 """Whether the event is a reply from another agent."""
575+ # In live/bidi mode, all events from any agents, including the current
576+ # agent, will be marked as other agent's reply. When agent transfers,
577+ # the conversation history will be sent to the Live API. If the current
578+ # agent previously used `transfer_to_agent` to transfer to another agent,
579+ # when the conversation is sent back to the current agent, the history will
580+ # contain a `transfer_to_agent` function call event from the current agent.
581+ # The Live API marks anything after the function response as model response.
582+ # This will confuse the model and cause the model to not respond.
583+ #
584+ # E.g. when the conversation is transferred from agent A to agent B, then
585+ # back to agent A, the history in the last transfer will be:
586+ # User: "Some message that triggers transfer to agent B"
587+ # Model: transfer_to_agent(B)
588+ # User: transfer_to_agent(B) response
589+ # User: "Some message that triggers transfer to agent A"
590+ # User: "For context: [agent B] called transfer_to_agent(A)"
591+ # User: "For context: [agent B] tool transfer_to_agent(A) returned result:"
592+ #
593+ # In this case, the last three events are marked as model response by the
594+ # Live API, instead of user input.
595+ if event .live_session_id :
596+ return event .author != 'user'
575597 return bool (
576598 current_agent_name
577599 and event .author != current_agent_name
0 commit comments