Skip to content

A programming framework for agentic AI

Fix OllamaChatCompletionClient load_component() error by adding to WELL_KNOWN_PROVIDERS (#7030)

Copilotc469fc0d8ce3
diff --git a/python/packages/autogen-core/src/autogen_core/_component_config.py b/python/packages/autogen-core/src/autogen_core/_component_config.py
index bb603a839..10284ada0 100644
--- a/python/packages/autogen-core/src/autogen_core/_component_config.py
+++ b/python/packages/autogen-core/src/autogen_core/_component_config.py
@@ -49,6 +49,7 @@ WELL_KNOWN_PROVIDERS = {
"AzureOpenAIChatCompletionClient": "autogen_ext.models.openai.AzureOpenAIChatCompletionClient",
"openai_chat_completion_client": "autogen_ext.models.openai.OpenAIChatCompletionClient",
"OpenAIChatCompletionClient": "autogen_ext.models.openai.OpenAIChatCompletionClient",
+ "OllamaChatCompletionClient": "autogen_ext.models.ollama.OllamaChatCompletionClient",
}
diff --git a/python/packages/autogen-ext/tests/models/test_ollama_chat_completion_client.py b/python/packages/autogen-ext/tests/models/test_ollama_chat_completion_client.py
index ff88b4a39..363801dde 100644
--- a/python/packages/autogen-ext/tests/models/test_ollama_chat_completion_client.py
+++ b/python/packages/autogen-ext/tests/models/test_ollama_chat_completion_client.py
@@ -1313,3 +1313,46 @@ async def test_tool_choice_default_behavior(monkeypatch: pytest.MonkeyPatch) ->
assert len(create_result.content) > 0
assert isinstance(create_result.content[0], FunctionCall)
assert create_result.content[0].name == add_tool.name
+
+
+def test_ollama_load_component() -> None:
+ """Test that OllamaChatCompletionClient can be loaded via ChatCompletionClient.load_component()."""
+ from autogen_core.models import ChatCompletionClient
+
+ # Test the exact configuration from the issue
+ config = {
+ "provider": "OllamaChatCompletionClient",
+ "config": {
+ "model": "qwen3",
+ "host": "http://1.2.3.4:30130",
+ },
+ }
+
+ # This should not raise an error anymore
+ client = ChatCompletionClient.load_component(config)
+
+ # Verify we got the right type of client
+ assert isinstance(client, OllamaChatCompletionClient)
+ assert client._model_name == "qwen3" # type: ignore[reportPrivateUsage]
+
+ # Test that the config was applied correctly
+ create_args = client.get_create_args()
+ assert create_args["model"] == "qwen3" # type: ignore[reportPrivateUsage]
+
+
+def test_ollama_load_component_via_class() -> None:
+ """Test that OllamaChatCompletionClient can be loaded via the class directly."""
+ config = {
+ "provider": "OllamaChatCompletionClient",
+ "config": {
+ "model": "llama3.2",
+ "host": "http://localhost:11434",
+ },
+ }
+
+ # Load via the specific class
+ client = OllamaChatCompletionClient.load_component(config)
+
+ # Verify we got the right type and configuration
+ assert isinstance(client, OllamaChatCompletionClient)
+ assert client._model_name == "llama3.2" # type: ignore[reportPrivateUsage]