Python: fix(python): exclude unsupported ChatOptions in Ollama chat client (#7054) - #7317
Closed
hsusul wants to merge 1 commit into
Closed
Python: fix(python): exclude unsupported ChatOptions in Ollama chat client (#7054)#7317hsusul wants to merge 1 commit into
hsusul wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a Python runtime incompatibility in the Ollama connector by ensuring that OllamaChatClient does not forward Agent Framework ChatOptions fields that are explicitly unsupported by Ollama’s AsyncClient.chat() API, preventing TypeError crashes in orchestration scenarios (e.g., handoff injecting allow_multiple_tool_calls=False).
Changes:
- Expanded
_prepare_options()’sexclude_keysto drop unsupportedChatOptionsfields even when they are non-None(e.g.,allow_multiple_tool_calls=False). - Added unit tests that validate unsupported options are filtered both at
_prepare_options()level and when callingget_response().
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| python/packages/ollama/agent_framework_ollama/_chat_client.py | Excludes additional unsupported ChatOptions keys from the kwargs passed into ollama.AsyncClient.chat(). |
| python/packages/ollama/tests/test_ollama_chat_client.py | Adds regression tests to ensure unsupported options do not reach the Ollama client call path. |
Member
|
This is not the approach we want for this issue, needs to be fixed in handoffs, closing this PR. If you want to create that fix, please open a new PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation & Context
When using
OllamaChatClient(for example, with orchestration patterns likeHandoffBuilderor when passing options likeallow_multiple_tool_calls=False,user,store,logit_bias,metadata), requests fail with a runtimeTypeError:AsyncClient.chat() got an unexpected keyword argument 'allow_multiple_tool_calls'.OllamaChatOptionsexplicitly marks these options as unsupported in Ollama (tool_choice: None,allow_multiple_tool_calls: None,user: None,store: None,logit_bias: None,metadata: None). However,OllamaChatClient._prepare_options()previously only excludedinstructionsandtool_choicefromexclude_keys, while relying onvalue is Nonefor other options. Whenallow_multiple_tool_calls=Falseor another non-None unsupported option was passed,_prepare_options()added it torun_options, which was then unpacked intoollama.AsyncClient.chat()as an unknown kwarg.Description & Review Guide
Added all unsupported
OllamaChatOptionsfields (allow_multiple_tool_calls,user,store,logit_bias,metadata) toexclude_keysinOllamaChatClient._prepare_options().Prevents runtime
TypeErrorcrashes when non-None unsupportedChatOptions(e.g.allow_multiple_tool_calls=Falseinjected byHandoffAgentExecutoror passed by users) are provided toOllamaChatClient.OllamaChatClient._prepare_options()inpython/packages/ollama/agent_framework_ollama/_chat_client.pyand the corresponding unit tests inpython/packages/ollama/tests/test_ollama_chat_client.py.Related Issue
Fixes #7054
Contribution Checklist