Skip to content

Python: fix(python): exclude unsupported ChatOptions in Ollama chat client (#7054) - #7317

Closed
hsusul wants to merge 1 commit into
microsoft:mainfrom
hsusul:fix-python-ollama-unsupported-options
Closed

Python: fix(python): exclude unsupported ChatOptions in Ollama chat client (#7054)#7317
hsusul wants to merge 1 commit into
microsoft:mainfrom
hsusul:fix-python-ollama-unsupported-options

Conversation

@hsusul

@hsusul hsusul commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Motivation & Context

When using OllamaChatClient (for example, with orchestration patterns like HandoffBuilder or when passing options like allow_multiple_tool_calls=False, user, store, logit_bias, metadata), requests fail with a runtime TypeError:
AsyncClient.chat() got an unexpected keyword argument 'allow_multiple_tool_calls'.

OllamaChatOptions explicitly 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 excluded instructions and tool_choice from exclude_keys, while relying on value is None for other options. When allow_multiple_tool_calls=False or another non-None unsupported option was passed, _prepare_options() added it to run_options, which was then unpacked into ollama.AsyncClient.chat() as an unknown kwarg.

Description & Review Guide

  • What are the major changes?
    Added all unsupported OllamaChatOptions fields (allow_multiple_tool_calls, user, store, logit_bias, metadata) to exclude_keys in OllamaChatClient._prepare_options().
  • What is the impact of these changes?
    Prevents runtime TypeError crashes when non-None unsupported ChatOptions (e.g. allow_multiple_tool_calls=False injected by HandoffAgentExecutor or passed by users) are provided to OllamaChatClient.
  • What do you want reviewers to focus on?
    OllamaChatClient._prepare_options() in python/packages/ollama/agent_framework_ollama/_chat_client.py and the corresponding unit tests in python/packages/ollama/tests/test_ollama_chat_client.py.

Related Issue

Fixes #7054

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change.

Copilot AI review requested due to automatic review settings July 25, 2026 05:47
@hsusul
hsusul temporarily deployed to github-app-auth July 25, 2026 05:47 — with GitHub Actions Inactive
@hsusul
hsusul temporarily deployed to github-app-auth July 25, 2026 05:47 — with GitHub Actions Inactive
@hsusul
hsusul temporarily deployed to github-app-auth July 25, 2026 05:47 — with GitHub Actions Inactive
@hsusul
hsusul temporarily deployed to github-app-auth July 25, 2026 05:47 — with GitHub Actions Inactive
@agent-framework-automation agent-framework-automation Bot added the python Usage: [Issues, PRs], Target: Python label Jul 25, 2026
@github-actions github-actions Bot changed the title fix(python): exclude unsupported ChatOptions in Ollama chat client (#7054) Python: fix(python): exclude unsupported ChatOptions in Ollama chat client (#7054) Jul 25, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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()’s exclude_keys to drop unsupported ChatOptions fields 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 calling get_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.

@eavanvalkenburg

Copy link
Copy Markdown
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: Handoff workflow + Ollama: allow_multiple_tool_calls passed to AsyncClient.chat()

3 participants