feat: Support Sequential State Propagation for Batch Tool Calls #33911
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: Feature OverviewAdded the sequential_tool_calls parameter to support sequential execution during batch tool calls, ensuring subsequent tools can access state updates from previous tools.
Problem BackgroundWhen an LLM returns multiple tool calls at once, the default behavior is concurrent execution, where all tools operate on the same initial state snapshot. When dependencies exist between tools, subsequent tools cannot obtain state updates from previous ones, leading to unexpected results.
SolutionNew Parameter: Added the sequential_tool_calls parameter to the create_agent function (defaults to False for backward compatibility).Implement SequentialToolNode Class: Wraps the standard ToolNode to execute tool calls sequentially.State Propagation: Updates state after each tool execution to ensure subsequent tools can see results from the previous one.
Key ChangesFile: libs/langchain_v1/langchain/agents/factory.pyAdded SequentialToolNode class (supports synchronous and asynchronous operations).Modified create_agent function signature to include the sequential_tool_calls parameter.Updated docstrings to explain usage of the new parameter.
Issue: Fixes #33832
Dependencies: None