-
Notifications
You must be signed in to change notification settings - Fork 18.5k
fix(core): properly handle empty or missing arguments for ToolCallChunk
#32017
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
amznero
wants to merge
10
commits into
langchain-ai:master
Choose a base branch
from
amznero:bugfix_tool_call_args
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e048bdf
fix tool call chunks bug
amznero 47b455a
refactor
mdrxy b162b1c
remove type ignore
mdrxy 3f57aa4
update tests, bump lock, rebuild snapshots
mdrxy ef00f99
correct tool call consturction type
mdrxy 76198ac
update `_prep_run_args`
mdrxy 667ad11
corrections for linting
mdrxy 6af5350
simplify
mdrxy 80158ff
simplify
mdrxy 62099a1
simplify
mdrxy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this change necessary?
An empty dict represents no args currently. I'd rather not add a second way to represent the same information
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, an empty dict should represent a completed tool call that has no arguments.
None
is used exclusively to represent the in-progress state where arguments have not yet been received during streaming.Using an empty dictionary for both the "no arguments" state and the "arguments are coming" state makes them indistinguishable. We wouldn't know how to interpret the message, e.g. two scenarios to illustrate this:
args={}
. We'd see this and execute the tool immediately.{}
as a temporary placeholder, we'd seeargs={}
If we went back to
args_ = parse_partial_json(chunk["args"]) if chunk["args"] != "" else {}
, it doesn't handle the case wherechunk["args"]
is literallyNone
. When a streaming chunk arrives withargs=None
,chunk["args"] != ""
evaluates toTrue
(sinceNone != ""
). The code then tries to executeparse_partial_json(None)
, which results in a TypeErrorEven if it mapped
None
to{}
we still lose the ability to distinguish between the two different scenarios.