Skip to content
Draft
Show file tree
Hide file tree
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
17 changes: 16 additions & 1 deletion src/google/adk/agents/invocation_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,24 @@ def should_pause_invocation(self, event: Event) -> bool:
if not event.long_running_tool_ids or not event.get_function_calls():
return False

# Check if we have already received a response for the long-running tool call
# Get all events in the current invocation
events = self._get_events(current_invocation=True)

for fc in event.get_function_calls():
if fc.id in event.long_running_tool_ids:
return True
# Check if there's a function response for this fc.id
has_response = False
for e in events:
for fr in e.get_function_responses():
if fr.id == fc.id:
has_response = True
break
if has_response:
break

if not has_response:
return True

return False

Expand Down
18 changes: 15 additions & 3 deletions src/google/adk/agents/llm_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,15 @@ async def _convert_tool_union_to_tools(
return [FunctionTool(func=tool_union)]

# At this point, tool_union must be a BaseToolset
return await tool_union.get_tools_with_prefix(ctx)
try:
return await tool_union.get_tools_with_prefix(ctx)
except Exception as e:
logger.warning(
'Failed to get tools from toolset %s: %s',
type(tool_union).__name__,
e,
)
return []


class LlmAgent(BaseAgent):
Expand Down Expand Up @@ -466,12 +474,16 @@ async def _run_async_impl(
if agent_state is not None and (
agent_to_transfer := self._get_subagent_to_resume(ctx)
):
sub_agent_paused = False
async with Aclosing(agent_to_transfer.run_async(ctx)) as agen:
async for event in agen:
if ctx.should_pause_invocation(event):
sub_agent_paused = True
yield event

ctx.set_agent_state(self.name, end_of_agent=True)
yield self._create_agent_state_event(ctx)
if not sub_agent_paused:
ctx.set_agent_state(self.name, end_of_agent=True)
yield self._create_agent_state_event(ctx)
return

should_pause = False
Expand Down