Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/google/adk/flows/llm_flows/contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,9 @@ def _get_current_turn_contents(
# Find the latest event that starts the current turn and process from there
for i in range(len(events) - 1, -1, -1):
event = events[i]
if _should_include_event_in_context(current_branch, event) and (
event.author == 'user' or _is_other_agent_reply(agent_name, event)
if (_should_include_event_in_context(current_branch, event)
and (event.author == "user" or _is_other_agent_reply(agent_name, event))
and not _is_direct_transfer(event)
):
return _get_contents(
current_branch,
Expand All @@ -570,6 +571,21 @@ def _get_current_turn_contents(
return []


def _is_direct_transfer(event : Event) -> bool:
"Check whether the event is a direct transfer event."

return bool(
event.actions.transfer_to_agent
or (
event.content.parts
and any(
p.function_call and p.function_call.name == 'transfer_to_agent'
for p in event.content.parts
)
)
)


def _is_other_agent_reply(current_agent_name: str, event: Event) -> bool:
"""Whether the event is a reply from another agent."""
return bool(
Expand Down