Skip to content

Python: honor tool_choice="none" in OllamaChatClient - #9049

Closed
Suhas Aggarwal (suhasagg) wants to merge 3 commits into
microsoft:mainfrom
suhasagg:fix-8986-ollama-tool-choice-none
Closed

Suhas Aggarwal (suhasagg) wants to merge 3 commits into
microsoft:mainfrom
suhasagg:fix-8986-ollama-tool-choice-none

Conversation

@suhasagg

Copy link
Copy Markdown
Contributor

Summary

Honor tool_choice="none" when preparing Ollama chat requests.

Problem

OllamaChatClient._prepare_options() excludes tool_choice from the
provider request because Ollama does not accept that option directly.

However, tools were still processed by the generic option path and
included in the Ollama request even when the caller explicitly selected
tool_choice="none".

Changes

  • Treat tools as a specially handled option instead of passing it
    through the generic option-processing path.
  • Omit tools when tool_choice="none".
  • Preserve existing tool behavior when tool use is enabled.
  • Add regression tests covering disabled and automatic tool choice.

Testing

  • Focused regression tests: 2 passed
  • Ollama non-integration tests: 49 passed, 5 deselected
  • Ruff check: passed
  • Ruff format check: passed
  • MyPy reports two existing TypedDict ** expansion errors in
    _chat_client.py; the same errors reproduce on the unmodified baseline.

Fixes #8986

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.

Copilot review overview

🟡 Changes recommended

ToolMode mappings remain unsupported and the public options type contradicts the new behavior.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Updates Ollama request preparation to honor disabled tool choice.

Changes:

  • Handles tools separately from generic options.
  • Omits tools for tool_choice="none".
  • Adds regression tests for none and auto.
File Description
_chat_client.py Conditionally includes Ollama tools.
test_ollama_chat_client.py Tests disabled and automatic tool choice.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread python/packages/ollama/agent_framework_ollama/_chat_client.py Outdated
@suhasagg

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

auto-merge was automatically disabled October 5, 2026 14:33

Head branch was pushed to by a user without write access

@eavanvalkenburg

Copy link
Copy Markdown
Member

Suhas Aggarwal (@suhasagg) Thanks for the contribution. This implements the same change as #8987, so we'll continue the work there and close this duplicate.

This branch was previously deployed

1 inactive deployment
github-app-auth — ce0e4fae Deployed Oct 5, 2026 by suhasagg via add_label #24443
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: [Bug]: OllamaChatClient still sends tools when tool_choice is "none"

3 participants