Skip to content

Python: Fix ollama_chat_client.py sample: pass tools via options dict#6480

Open
giles17 wants to merge 2 commits into
microsoft:mainfrom
giles17:fix-ollama-client-sample
Open

Python: Fix ollama_chat_client.py sample: pass tools via options dict#6480
giles17 wants to merge 2 commits into
microsoft:mainfrom
giles17:fix-ollama-client-sample

Conversation

@giles17

@giles17 giles17 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes the ollama_chat_client.py sample which was passing tools as a direct keyword argument to get_response(), causing a TypeError. The tools parameter must be passed inside the options dict per the SupportsChatGetResponse protocol.

Changes

  • python/samples/02-agents/providers/ollama/ollama_chat_client.py: Changed tools=get_time to options={"tools": get_time} in both the streaming and non-streaming get_response() calls.

Testing

Ran the sample locally with Ollama (mistral model) - no TypeError, runs successfully.

Fixes #6411

The sample was passing tools as a direct keyword argument to
get_response(), which caused a TypeError. The tools parameter
must be passed inside the options dict per the SupportsChatGetResponse
protocol.

Fixes microsoft#6411

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 11, 2026 17:25
@github-actions github-actions Bot changed the title Fix ollama_chat_client.py sample: pass tools via options dict Python: Fix ollama_chat_client.py sample: pass tools via options dict Jun 11, 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

Fixes the Ollama Python sample to comply with the SupportsChatGetResponse/FunctionInvocationLayer.get_response API shape by passing tool definitions via the options parameter (instead of an unsupported tools= keyword argument), eliminating the runtime TypeError reported in #6411.

Changes:

  • Update the streaming get_response() call to pass tools via options={"tools": get_time}.
  • Update the non-streaming get_response() call to pass tools via options={"tools": get_time}.

@github-actions github-actions Bot 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.

Automated Code Review

Reviewers: 5 | Confidence: 95%

✓ Correctness

The fix is correct. The get_response protocol signature (lines 171-180 of _clients.py) accepts options as a typed parameter but has no tools keyword argument. The _ChatOptionsBase TypedDict (line 3393 of _types.py) declares tools: ToolTypes | Callable[.., Any] | Sequence[ToolTypes | Callable[..., Any]] | None, confirming that {"tools": get_time} is the correct way to pass tools via the options dict. The single callable get_time matches the accepted type.

✓ Security Reliability

This is a straightforward and correct bug fix to a sample file. The get_response() protocol method accepts options as a keyword-only parameter (a TypedDict), not tools directly. The fix correctly moves the tools value into the options dict, matching the SupportsChatGetResponse protocol signature at _clients.py:176 and the _ChatOptionsBase TypedDict definition at _types.py:393. No security or reliability concerns — this is a sample file passing a locally-defined function reference through a well-typed options dict.

✓ Test Coverage

This is a correct sample fix that aligns the code with the SupportsChatGetResponse protocol. The underlying functionality (passing tools via options dict) is already well-tested in test_ollama_chat_client.py with tests like test_cmc_streaming_with_tool_call, test_cmc_integration_with_tool_call, and test_cmc_streaming_integration_with_tool_call. The single-tool (non-list) pattern used in the sample is valid because validate_tools in the core package normalizes single tools into lists. As a sample file fix, no additional automated tests are needed.

✓ Failure Modes

The change correctly fixes the sample by passing tools inside the options dict, matching the SupportsChatGetResponse protocol signature. The protocol's get_response method accepts options: OptionsContraT | ChatOptions[Any] | None (line 176 of _clients.py), and ChatOptions (a TypedDict) defines a tools field (line 3393 of _types.py). No failure modes are introduced.

✗ Design Approach

The PR fixes the wrong keyword argument, but it still leaves the Ollama sample on a broken tool-calling path by passing a single FunctionTool where the Ollama client expects a list of tools. I found one blocking design issue in the changed sample lines.


Automated review by giles17's agents

Comment thread python/samples/02-agents/providers/ollama/ollama_chat_client.py Outdated
_prepare_tools_for_ollama iterates the tools value, so it must be a
list rather than a bare FunctionTool instance.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@giles17 giles17 enabled auto-merge June 11, 2026 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: ollama_chat_client.py sample passes tools as direct argument to get_response() causing TypeError

4 participants