Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
06828ee
Initial Commit for Olama Connector
nmoeller Sep 12, 2025
02c4852
Merge remote-tracking branch 'origin/main' into nmoeller/olamaconnector
nmoeller Sep 12, 2025
beab7d4
Added Olama Sample
nmoeller Sep 12, 2025
80cf98d
Add Sample & Fixed Open Telemetry
nmoeller Sep 12, 2025
afc7190
Fixed Spelling from Olama to Ollama
nmoeller Sep 12, 2025
cbdb533
remove"opentelemetry-semantic-conventions-ai ~=0.4.13" since its hand…
nmoeller Sep 12, 2025
c1f2ee6
Merge branch 'main' into features/python_olama_connector
nmoeller Sep 14, 2025
3518527
Added Tool Calling
nmoeller Sep 15, 2025
545b52e
Merge remote-tracking branch 'origin/main' into features/python_olama…
nmoeller Sep 15, 2025
9c93812
Merge remote-tracking branch 'origin/main' into features/python_olama…
nmoeller Sep 17, 2025
460be3c
Finalizing test cases
nmoeller Sep 20, 2025
1c4115a
Merge branch 'main' into features/python_olama_connector
nmoeller Sep 20, 2025
279392d
Adjust samples to be more reliable
nmoeller Sep 20, 2025
efac8b7
Merge branch 'features/python_olama_connector' of https://github.com/…
nmoeller Sep 20, 2025
0e62fd8
Update python/packages/ollama/agent_framework_ollama/_chat_client.py
nmoeller Sep 20, 2025
ea7f1d5
Update python/packages/ollama/pyproject.toml
nmoeller Sep 20, 2025
0abeec6
Update python/packages/ollama/tests/test_ollama_chat_client.py
nmoeller Sep 20, 2025
d2e2f1b
Update python/packages/ollama/agent_framework_ollama/_chat_client.py
nmoeller Sep 20, 2025
133fd12
Improved Docstrings & Sample
nmoeller Sep 21, 2025
22e7438
Merge branch 'features/python_olama_connector' of https://github.com/…
nmoeller Sep 21, 2025
8a78094
Update python/packages/ollama/agent_framework_ollama/_chat_client.py
nmoeller Sep 23, 2025
f96f817
Integrate PR Feedback
nmoeller Sep 24, 2025
9a09b52
Merge branch 'features/python_olama_connector' of https://github.com/…
nmoeller Sep 24, 2025
d28bea0
Revert setting, so it can be none
nmoeller Sep 24, 2025
1030b50
Validate Message formatting between AF and Ollama
nmoeller Sep 24, 2025
290d2f7
Catch Ollama Error and raise a ServiceResponse Error
nmoeller Sep 25, 2025
883e51a
Merge remote-tracking branch 'origin/main' into features/python_olama…
nmoeller Sep 25, 2025
79933f8
Fix mypy error
nmoeller Sep 25, 2025
604b545
remove .vscode comma
nmoeller Sep 25, 2025
2e0da1e
Merge remote-tracking branch 'origin/main' into features/python_olama…
nmoeller Oct 2, 2025
d180c2c
Add Reasoning support & adjust to new structure
nmoeller Oct 2, 2025
c09242b
Add Ollama Multimodality and Reasoning
nmoeller Oct 3, 2025
f0bc638
Add test cases for reasoning
nmoeller Oct 3, 2025
9d39405
Merge branch 'main' into features/python_olama_connector
nmoeller Oct 3, 2025
83ba556
Add Tests for Error Handling in Ollama Client
nmoeller Oct 3, 2025
9df622e
Update python/samples/getting_started/multimodal_input/ollama_chat_mu…
nmoeller Oct 3, 2025
3c697dc
Merge branch 'features/python_olama_connector' of https://github.com/…
nmoeller Oct 3, 2025
ce819ef
Integrated Copilot Feedback
nmoeller Oct 3, 2025
637f2a8
Merge branch 'main' into features/python_olama_connector
nmoeller Oct 14, 2025
1eecd6d
Implement first PR Feedback
nmoeller Oct 14, 2025
14614c7
Adjust Readme files for examples
nmoeller Oct 14, 2025
e74dd4e
Adjust argument passing via additional chat options
nmoeller Oct 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions python/packages/core/agent_framework/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2051,6 +2051,15 @@ def text(self) -> str:
"""
return " ".join(content.text for content in self.contents if isinstance(content, TextContent))

@property
def reasoning(self) -> str:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please don't add things without first discussing why we need this, not saying we won't need this, but we don't want to just add stuff for everything.

Copy link
Author

@nmoeller nmoeller Oct 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me share my thought when I was adding this and why it could be useful :

These were just my idea for adding this to the core package, like I said very happy to implement this just in the Ollama Package.

"""Returns the reasoning content of the message.

Remarks:
This property concatenates the text of all TextReasoningContent objects in Contents.
"""
return " ".join(content.text for content in self.contents if isinstance(content, TextReasoningContent))


# region ChatResponse

Expand Down Expand Up @@ -2440,6 +2449,11 @@ def text(self) -> str:
"""Returns the concatenated text of all messages in the response."""
return ("\n".join(message.text for message in self.messages if isinstance(message, ChatMessage))).strip()

@property
def reasoning(self) -> str:
"""Returns the concatenated reasoning of all messages in the response."""
return ("\n".join(message.reasoning for message in self.messages if isinstance(message, ChatMessage))).strip()

def __str__(self) -> str:
return self.text

Expand Down Expand Up @@ -2575,6 +2589,11 @@ def text(self) -> str:
"""Returns the concatenated text of all contents in the update."""
return "".join(content.text for content in self.contents if isinstance(content, TextContent))

@property
def reasoning(self) -> str:
"""Returns the reasoning content of the message."""
return " ".join(content.text for content in self.contents if isinstance(content, TextReasoningContent))

def __str__(self) -> str:
return self.text

Expand Down Expand Up @@ -2684,6 +2703,11 @@ def text(self) -> str:
"""Get the concatenated text of all messages."""
return "".join(msg.text for msg in self.messages) if self.messages else ""

@property
def reasoning(self) -> str:
"""Get the concatenated reasoning of all messages."""
return " ".join(msg.reasoning for msg in self.messages) if self.messages else ""

@property
def user_input_requests(self) -> list[UserInputRequestContents]:
"""Get all BaseUserInputRequest messages from the response."""
Expand Down Expand Up @@ -2850,6 +2874,11 @@ def text(self) -> str:
else ""
)

@property
def reasoning(self) -> str:
"""Get the concatenated text of all TextReasoningContent objects in contents."""
return " ".join(content.text for content in self.contents if isinstance(content, TextReasoningContent))

@property
def user_input_requests(self) -> list[UserInputRequestContents]:
"""Get all BaseUserInputRequest messages from the response."""
Expand Down
27 changes: 27 additions & 0 deletions python/packages/core/agent_framework/ollama/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (c) Microsoft. All rights reserved.

import importlib
from typing import Any

PACKAGE_NAME = "agent_framework_ollama"
PACKAGE_EXTRA = "ollama"
_IMPORTS = [
"OllamaChatClient",
"OllamaSettings",
"__version__",
]


def __getattr__(name: str) -> Any:
if name in _IMPORTS:
try:
return getattr(importlib.import_module(PACKAGE_NAME), name)
except ModuleNotFoundError as exc:
raise ModuleNotFoundError(
f"The '{PACKAGE_EXTRA}' extra is not installed, please do `pip install agent-framework-{PACKAGE_EXTRA}`"
) from exc
raise AttributeError(f"Module {PACKAGE_NAME} has no attribute {name}.")


def __dir__() -> list[str]:
return _IMPORTS
13 changes: 13 additions & 0 deletions python/packages/core/agent_framework/ollama/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) Microsoft. All rights reserved.

from agent_framework_ollama import (
OllamaChatClient,
OllamaSettings,
__version__,
)

__all__ = [
"OllamaChatClient",
"OllamaSettings",
"__version__",
]
21 changes: 21 additions & 0 deletions python/packages/core/tests/core/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,26 @@ def test_chat_message_contents():
assert message.text == "Hello, how are you? I'm fine, thank you!"


def test_chat_message_reasoning_contents():
"""Test the ChatMessage class to ensure it initializes correctly with contents."""
# Create a ChatMessage with a role and multiple contents
content1 = TextReasoningContent("For this task, we need to consider the following...")
content2 = TextReasoningContent("And then we can proceed with the next steps.")
message = ChatMessage(role="user", contents=[content1, content2])

# Check the type and content
assert message.role == Role.USER
assert len(message.contents) == 2
assert isinstance(message.contents[0], TextReasoningContent)
assert isinstance(message.contents[1], TextReasoningContent)
assert message.contents[0].text == "For this task, we need to consider the following..."
assert message.contents[1].text == "And then we can proceed with the next steps."
assert (
message.reasoning
== "For this task, we need to consider the following... And then we can proceed with the next steps."
)


def test_chat_message_with_chatrole_instance():
m = ChatMessage(role=Role.USER, text="hi")
assert m.role == Role.USER
Expand Down Expand Up @@ -646,6 +666,7 @@ def test_chat_response_updates_to_chat_response_multiple():
# Check the type and content
assert len(chat_response.messages) == 1
assert chat_response.text == "I'm doing well, thank you!"
assert chat_response.reasoning == "Additional context"
assert isinstance(chat_response.messages[0], ChatMessage)
assert len(chat_response.messages[0].contents) == 3
assert chat_response.messages[0].message_id == "1"
Expand Down
21 changes: 21 additions & 0 deletions python/packages/ollama/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Microsoft Corporation.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
9 changes: 9 additions & 0 deletions python/packages/ollama/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Get Started with Microsoft Agent Framework Ollama

Please install this package as the extra for `agent-framework`:

```bash
pip install agent-framework-ollama --pre
```

and see the [README](https://github.com/microsoft/agent-framework/tree/main/python/README.md) for more information.
16 changes: 16 additions & 0 deletions python/packages/ollama/agent_framework_ollama/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright (c) Microsoft. All rights reserved.

import importlib.metadata

from ._chat_client import OllamaChatClient, OllamaSettings

try:
__version__ = importlib.metadata.version(__name__)
except importlib.metadata.PackageNotFoundError:
__version__ = "0.0.0" # Fallback for development mode

__all__ = [
"OllamaChatClient",
"OllamaSettings",
"__version__",
]
Loading