fix(langchain): set agent name on AIMessage responses when name parameter is provided #33778
+265
−3
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.
Description:
This PR fixes a bug where the
nameparameter provided tocreate_agent()was not being set onAIMessageobjects in the agent responses. Previously,AIMessage.namewas alwaysnullregardless of thenameparameter value, even though the parameter was documented to work.The fix:
_set_agent_name_on_message()helper function to set name on AIMessage objects_handle_model_output()to accept and useagent_nameparameter_execute_model_sync) and async (_execute_model_async) model execution paths to pass the name parameterThis ensures backward compatibility - when
nameis not provided,AIMessage.nameremainsNone.Issue:
Fixes the bug reported where
nameparameter increate_agent()was not reflected in AIMessage responses. (Add issue number if you have it)Dependencies:
None. No new dependencies required.