-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Add tool_choice parameter to ChatCompletionClient create and create_stream methods
#6697
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
|
@copilot can you continue working |
…mplementations Co-authored-by: ekzhu <320302+ekzhu@users.noreply.github.com>
tool_choice to ChatCompletionClient create and create_stream methodtool_choice parameter to ChatCompletionClient create and create_stream methods
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.
Add unit tests for AnthropicChatCompletionClient and OpenAIChatCompletionClient to test the use of tool_choice parameter using mocks.
python/packages/autogen-core/src/autogen_core/models/_model_client.py
Outdated
Show resolved
Hide resolved
…auto" Co-authored-by: ekzhu <320302+ekzhu@users.noreply.github.com>
Co-authored-by: ekzhu <320302+ekzhu@users.noreply.github.com>
Added comprehensive unit tests for both AnthropicChatCompletionClient and OpenAIChatCompletionClient to test the tool_choice parameter using mocks. Tests cover specific tool selection, "auto" mode, None mode, and validation errors. Commit 717c05b
Completed the implementation as requested. Updated the tool_choice parameter type, refactored all client implementations, and added comprehensive unit tests for OpenAI and Anthropic clients. All changes are now complete and committed. |
python/packages/autogen-core/src/autogen_core/models/_model_client.py
Outdated
Show resolved
Hide resolved
Co-authored-by: ekzhu <320302+ekzhu@users.noreply.github.com>
|
@copilot update the PR description, do not modify the code. |
Updated the PR description to reflect the current implementation with the simplified |
|
@copilot write me a new PR description, remove the existing one. |
Created a new PR description that accurately reflects the current implementation with the simplified |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6697 +/- ##
==========================================
+ Coverage 79.85% 80.25% +0.40%
==========================================
Files 232 232
Lines 17540 17643 +103
==========================================
+ Hits 14006 14160 +154
+ Misses 3534 3483 -51
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Whats your plan with wiring it up to the |
It's already being used by AssistantAgent for the reflection step. |
|
That is all well and good, but what about the rest? When So imho this MR only addresses half of the work. |
That's rather strong assumption on the agent behaviour. I think it will also conflict with the max_tool_iteration parameter. If you set that parameter, then the tool calling loop only ends when the agent stops calling tool or reaching maximum iteration. If the tool choice is also set to required, then you end up with forced tool calling when it is not needed. I think in many cases AssistantAgent is not suitable. It's already a kitchen sink. See my note on the documentation: https://microsoft.github.io/autogen/stable/user-guide/agentchat-user-guide/tutorial/agents.html#assistant-agent |
Summary
Implements the
tool_choiceparameter forChatCompletionClientinterface as requested in #6696. This allows users to restrict which tools the model can choose from when multiple tools are available.Changes
Core Interface
tool_choice: Tool | Literal["auto", "required", "none"] = "auto"parameter toChatCompletionClient.create()andcreate_stream()methodsLlamaCppChatCompletionClientcurrently not supportedFeatures