-
Notifications
You must be signed in to change notification settings - Fork 840
Fix duplication between OpenAI Assistants pre-configured tools #6896
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
Conversation
There was a problem hiding this 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
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIAssistantsChatClient.cs
Outdated
Show resolved
Hide resolved
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.
d74b40c to
6a6ea3f
Compare
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