Skip to content

Commit bcf0dda

Browse files
google-genai-botcopybara-github
authored andcommitted
fix: AgentTool returns last content, instead of the content in the last event
This fixes the issue when inner agent has after_agent_callback updating state only, AgentTool will always return empty. PiperOrigin-RevId: 799814933
1 parent 4c70606 commit bcf0dda

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/google/adk/tools/agent_tool.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ async def run_async(
139139
state=tool_context.state.to_dict(),
140140
)
141141

142-
last_event = None
142+
last_content = None
143143
async with Aclosing(
144144
runner.run_async(
145145
user_id=session.user_id, session_id=session.id, new_message=content
@@ -149,11 +149,12 @@ async def run_async(
149149
# Forward state delta to parent session.
150150
if event.actions.state_delta:
151151
tool_context.state.update(event.actions.state_delta)
152-
last_event = event
152+
if event.content:
153+
last_content = event.content
153154

154-
if not last_event or not last_event.content or not last_event.content.parts:
155+
if not last_content:
155156
return ''
156-
merged_text = '\n'.join(p.text for p in last_event.content.parts if p.text)
157+
merged_text = '\n'.join(p.text for p in last_content.parts if p.text)
157158
if isinstance(self.agent, LlmAgent) and self.agent.output_schema:
158159
tool_result = self.agent.output_schema.model_validate_json(
159160
merged_text

0 commit comments

Comments
 (0)