Skip to content

Conversation

@MackinnonBuck
Copy link
Member

@MackinnonBuck MackinnonBuck commented Sep 8, 2025

Summary

This draft introduces the tool reduction feature set:

  • New abstractions (IToolReductionStrategy) for selecting a subset of tools per request.
  • Middleware (ToolReducingChatClient) that applies a configured strategy automatically.
  • An initial embedding-based implementation (EmbeddingToolReductionStrategy) as a first strategy.
  • Supporting builder extensions and tests.

All components are marked experimental and may evolve. Additional strategies can be added in follow-up work.

Next Steps

  • Additional tool reduction strategy implementations.
  • Refinements to abstractions as necessary.

Feedback welcome before expanding scope.

Fixes #6670

Microsoft Reviewers: Open in CodeFlow

@github-actions github-actions bot added the area-ai Microsoft.Extensions.AI libraries label Sep 8, 2025
@jeffhandley jeffhandley requested a review from ericstj September 30, 2025 17:22
@MackinnonBuck MackinnonBuck mentioned this pull request Oct 2, 2025
@MackinnonBuck MackinnonBuck marked this pull request as ready for review October 14, 2025 23:53
@MackinnonBuck MackinnonBuck requested a review from a team as a code owner October 14, 2025 23:54
Copilot AI review requested due to automatic review settings October 14, 2025 23:54
@MackinnonBuck MackinnonBuck requested a review from a team as a code owner October 14, 2025 23:54
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a tool reduction feature set for managing large tool catalogs in AI chat applications. The feature allows for automatically selecting a subset of tools per request using configurable strategies.

Key changes:

  • New abstractions for tool reduction strategies with an embedding-based implementation
  • Middleware that automatically applies tool reduction to chat requests
  • Comprehensive test coverage including integration tests across different scenarios

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/Libraries/Microsoft.Extensions.AI.Abstractions/ToolReduction/IToolReductionStrategy.cs Defines the core abstraction interface for tool reduction strategies
src/Libraries/Microsoft.Extensions.AI/ToolReduction/EmbeddingToolReductionStrategy.cs Implements embedding-based tool selection using similarity scoring
src/Libraries/Microsoft.Extensions.AI/ToolReduction/ToolReducingChatClient.cs Middleware client that applies tool reduction before delegating to inner client
src/Libraries/Microsoft.Extensions.AI/ToolReduction/ChatClientBuilderToolReductionExtensions.cs Extension methods for integrating tool reduction into chat client pipelines
test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ToolReductionTests.cs Comprehensive unit and integration tests for tool reduction functionality
test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ChatClientIntegrationTests.cs Integration tests demonstrating real-world tool reduction scenarios
test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIChatClientIntegrationTests.cs Adds embedding generator support for OpenAI integration tests
src/Libraries/Microsoft.Extensions.AI/Microsoft.Extensions.AI.csproj Adds System.Numerics.Tensors dependency for embedding similarity calculations
eng/packages/General.props Moves System.Numerics.Tensors to general packages from test-only
eng/packages/TestOnly.props Removes System.Numerics.Tensors from test-only packages
Comments suppressed due to low confidence (2)

src/Libraries/Microsoft.Extensions.AI/ToolReduction/EmbeddingToolReductionStrategy.cs:1

  • This method exceeds 120 characters per line. Consider breaking the parameter list across multiple lines for better readability.
// Licensed to the .NET Foundation under one or more agreements.

src/Libraries/Microsoft.Extensions.AI/ToolReduction/EmbeddingToolReductionStrategy.cs:1

  • This method exceeds 120 characters per line. Consider breaking the parameter list across multiple lines for better readability.
// Licensed to the .NET Foundation under one or more agreements.

@jeffhandley jeffhandley requested a review from ericstj October 20, 2025 03:59
Copy link
Member

@ericstj ericstj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to get out there and get feedback.

I think this will still only expose a subset of the tools to the model, with no way for the model to page in the rest - but I suppose that's by design for this implementation.

@MackinnonBuck MackinnonBuck merged commit 46d0b49 into main Oct 20, 2025
6 checks passed
@MackinnonBuck MackinnonBuck deleted the mbuck/tool-reduction branch October 20, 2025 23:10
jeffhandley pushed a commit to jeffhandley/extensions that referenced this pull request Oct 21, 2025
jeffhandley pushed a commit to jeffhandley/extensions that referenced this pull request Oct 21, 2025
jeffhandley pushed a commit to jeffhandley/extensions that referenced this pull request Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-ai Microsoft.Extensions.AI libraries

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Middleware for tool reduction

5 participants