Skip to content

Conversation

@stephentoub
Copy link
Member

@stephentoub stephentoub commented Oct 6, 2025

Assistants lets you configure an agent with function signatures it's implicitly aware of, rather than them needing to be provided per request. That, however, creates complication for callers, as if they provide that function in ChatTools.Options, it leads to the function's signature being sent as part of the request, and the duplication of it with the pre-configured function signature results in an error. It's possible to work around this, by simply not including that function in the request, but it's a natural thing for a developer to do, especially if they want the function to be automatically invoked when the model requests it. You can achieve that by putting the function into the FunctionInvocationChatClient's AdditionalTools, which exists for this kind of purpose, but that's harder to discover.

Rather than try something more complicated, this commit simply deduplicates all tools by putting them into a set, deduplicating any duplicates provided.

Fixes #6743

Microsoft Reviewers: Open in CodeFlow

@stephentoub stephentoub requested a review from a team as a code owner October 6, 2025 21:45
@Copilot Copilot AI review requested due to automatic review settings October 6, 2025 21:45
@github-actions github-actions bot added the area-ai Microsoft.Extensions.AI libraries label Oct 6, 2025
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 fixes a duplication issue in OpenAI Assistants where function signatures are sent twice - once from pre-configured assistant tools and once from ChatTools.Options - causing API errors. The solution tracks assistant function names and filters out duplicates from the request tools.

Key changes:

  • Added tracking of assistant function names to avoid duplicate tool definitions
  • Modified tool processing logic to skip functions already configured on the assistant
  • Introduced thread-safe initialization method for assistant tools and function names

Assistants lets you configure an agent with function signatures it's implicitly aware of, rather than them needing to be provided per request. That, however, creates complication for callers, as if they provide that function in ChatTools.Options, it leads to the function's signature being sent as part of the request, and the duplication of it with the pre-configured function signature results in an error. It's possible to work around this, by simply not including that function in the request, but it's a natural thing for a developer to do, especially if they want the function to be automatically invoked when the model requests it. You can achieve that by putting the function into the FunctionInvocationChatClient's AdditionalTools, which exists for this kind of purpose, but that's harder to discover.

Rather than try something more complicated, this commit simply deduplicates all tools by putting them into a set, deduplicating any duplicates provided.
This was referenced Oct 22, 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.

Adding Tools to the Assistant ChatClient OpenAI Assistants level

2 participants