Fix Document truncation in FunctionTool._parse_tool_output #19585
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Document objects returned by tools are being truncated to ~400 characters instead of providing full content to agents, causing infinite loops and degraded performance.
Root Cause
FunctionTool._parse_tool_output()callsstr(raw_output)which triggersDocument.__str__()that truncates content to 350 characters for display purposes. This truncated content is then used for agent processing instead of display only.Solution
str(raw_output)withraw_output.get_content()for Document objectsstr()fallback for non-Document objectsTesting
Before fix:
After fix:
Impact
Here is a simple test to prove that this indeed happens :
Here are the results that clearly shows the issue:
Here is a PR where I thought that the issue was with my test : #19301
but after debugging further I found this :
And started debugging to see weather it is applied, and even when calling the document and found that the small change in my PR solves this issue.
@logan-markewich - Can you please take a look ? I might be wrong but it looks like something is off.