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.
π οΈ Add onUpdateToolsList callback to streamText function
Overview
This PR introduces a new onUpdateToolsList callback to the streamText function, enabling dynamic tool management during multi-step conversations. This feature allows updating available tools and optionally providing system instructions after each tool execution step.
π Key Features
Update tools dynamically after each tool execution step
Maintain full backward compatibility with existing code
Support both legacy format (tools only) and new format (tools + system instruction)
Optionally provide system instructions alongside tool updates
System instructions are inserted before response messages in the prompt flow
Clean separation of concerns with parameter-based approach
Full TypeScript support with proper type definitions
Maintains type inference for tool calls and results
Uses @ts-ignore strategically where type system limitations exist
π API Usage
Apply to ai-4.3.17.tg...
;
ποΈ Implementation Details
Message Flow Architecture
Apply to ai-4.3.17.tg...
;
Type Definition
Apply to ai-4.3.17.tg...
;
π Workflow
Tool calls are executed in current step
onUpdateToolsList callback is invoked with tool execution context
Callback can return updated tools and optional system instruction
System instruction is inserted before response messages
Next step proceeds with updated tools and enhanced context
β Benefits
Dynamic Tool Management: Adapt available tools based on conversation context
Enhanced Context: Provide relevant instructions when tools change
Backward Compatible: Existing code continues to work unchanged
Type Safe: Full TypeScript support with proper inference
Clean Architecture: Parameter-based approach vs message pollution
π§ͺ Testing
β Builds successfully with TypeScript
β Maintains backward compatibility
β Supports both callback formats
β Proper error handling for failed tool updates