Skip to content

onUpdateToolsList #6750

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
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

onUpdateToolsList #6750

wants to merge 5 commits into from

Conversation

eliaweiss
Copy link

@eliaweiss eliaweiss commented Jun 15, 2025 β€’

πŸ› οΈ 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

  1. Dynamic Tool Updates
    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)
  2. System Instruction Support
    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
  3. Type Safety
    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant