Skip to content

Only the first part's text is returned from last_event.content.parts, causing loss of multi-part responses #606

@TP9-dev

Description

@TP9-dev

File: agent_tool.py

Description:
The code returns only the text of the first part in last_event.content.parts:

tool_result = last_event.content.parts[0].text

This implementation causes issues when the response contains multiple parts, as only the first part's text is returned and any additional parts are ignored. As a result, important information in subsequent parts is lost, leading to incomplete or incorrect tool outputs.

Expected behavior:
All parts' texts should be concatenated (e.g., joined with \n) and returned as a single string, so that multi-part responses are handled correctly.

Suggested fix:
Replace the above line with:

tool_result = "\n".join(
    [p.text for p in last_event.content.parts if getattr(p, "text", None)]
)

This will ensure that all available text parts are included in the tool result.

Metadata

Metadata

Assignees

Labels

core[Component] This issue is related to the core interface and implementation

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions