From e0079030903db3d033064e5443dccb01aee0d15d Mon Sep 17 00:00:00 2001 From: Tarak Chandra Sarkar Date: Tue, 7 Apr 2026 21:50:45 +0530 Subject: [PATCH 1/3] Support Ollama local model - agent_basic.py - agent_tool.py - agent_tools.py - update README --- README.md | 19 ++++++++++++++++++- examples/agent_basic.py | 6 ++++++ examples/agent_tool.py | 6 ++++++ examples/agent_tools.py | 6 ++++++ 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e26c8af..140278e 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,7 @@ The dev container includes a Redis server, which is used by the `agent_history_r * [Python 3.10+](https://www.python.org/downloads/) * [uv](https://docs.astral.sh/uv/getting-started/installation/) * Git + * Ollama - (optional for local Ollama model api call) 2. Clone the repository: @@ -73,8 +74,24 @@ The dev container includes a Redis server, which is used by the `agent_history_r git clone https://github.com/Azure-Samples/python-agentframework-demos cd python-agentframework-demos ``` +3. Create a virtual environment: -3. Install the dependencies: + ```shell + python -m venv .venv + ``` +3. Activate the virtual environment: + + ```shell + source .venv/bin/activate + # On Windows: .venv\Scripts\activate + ``` +4. Install the uv: + + ```shell + pip uv + ``` + +4. Install the dependencies: ```shell uv sync diff --git a/examples/agent_basic.py b/examples/agent_basic.py index 9a4f32a..bdc80e9 100644 --- a/examples/agent_basic.py +++ b/examples/agent_basic.py @@ -20,6 +20,12 @@ api_key=token_provider, model=os.environ["AZURE_OPENAI_CHAT_DEPLOYMENT"], ) +elif API_HOST == "ollama": + client = OpenAIChatClient( + base_url=os.environ['OLLAMA_BASE_URL'], + model=os.environ["OLLAMA_MODEL"], + api_key=os.environ['OLLAMA_API_KEY'], + ) else: client = OpenAIChatClient( api_key=os.environ["OPENAI_API_KEY"], model=os.environ.get("OPENAI_MODEL", "gpt-5.4") diff --git a/examples/agent_tool.py b/examples/agent_tool.py index c390ce7..7d4937f 100644 --- a/examples/agent_tool.py +++ b/examples/agent_tool.py @@ -31,6 +31,12 @@ api_key=token_provider, model=os.environ["AZURE_OPENAI_CHAT_DEPLOYMENT"], ) +elif API_HOST == "ollama": + client = OpenAIChatClient( + base_url=os.environ['OLLAMA_BASE_URL'], + model=os.environ["OLLAMA_MODEL"], + api_key=os.environ['OLLAMA_API_KEY'], + ) else: client = OpenAIChatClient( api_key=os.environ["OPENAI_API_KEY"], model=os.environ.get("OPENAI_MODEL", "gpt-5.4") diff --git a/examples/agent_tools.py b/examples/agent_tools.py index e97594b..4280c0e 100644 --- a/examples/agent_tools.py +++ b/examples/agent_tools.py @@ -33,6 +33,12 @@ api_key=token_provider, model=os.environ["AZURE_OPENAI_CHAT_DEPLOYMENT"], ) +elif API_HOST == "ollama": + client = OpenAIChatClient( + base_url=os.environ['OLLAMA_BASE_URL'], + model=os.environ["OLLAMA_MODEL"], + api_key=os.environ['OLLAMA_API_KEY'], + ) else: client = OpenAIChatClient( api_key=os.environ["OPENAI_API_KEY"], model=os.environ.get("OPENAI_MODEL", "gpt-5.4") From 2e5a858e39a46b0bceb944f4d3680567f2b19861 Mon Sep 17 00:00:00 2001 From: Tarak Chandra Sarkar Date: Tue, 7 Apr 2026 22:04:38 +0530 Subject: [PATCH 2/3] Add .enev.example with required settings for Ollama local model configuration --- .env.sample | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.env.sample b/.env.sample index accded0..0d4ec88 100644 --- a/.env.sample +++ b/.env.sample @@ -1,8 +1,12 @@ -# API_HOST can be either azure or openai: +# API_HOST can be either azure, ollama or openai: API_HOST=azure # Configure for Azure: AZURE_OPENAI_ENDPOINT=https://YOUR-AZURE-OPENAI-SERVICE-NAME.openai.azure.com AZURE_OPENAI_CHAT_DEPLOYMENT=YOUR-AZURE-DEPLOYMENT-NAME +# Config for Ollama +OLLAMA_BASE_URL=http://localhost:11434/v1 +OLLAMA_MODEL=qwen3.5:0.8b +OLLAMA_API_KEY="dummy_key" # Configure for OpenAI.com: OPENAI_API_KEY=YOUR-OPENAI-KEY OPENAI_MODEL=gpt-5.4 From 7d8076a30e021a07d957b2acbfe49f165d87e9d8 Mon Sep 17 00:00:00 2001 From: Tarak Chandra Sarkar Date: Wed, 8 Apr 2026 20:10:44 +0530 Subject: [PATCH 3/3] Support Ollama local model in Workflow with Fan-In & Fan-Out at edges --- examples/workflow_fan_out_fan_in_edges.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/examples/workflow_fan_out_fan_in_edges.py b/examples/workflow_fan_out_fan_in_edges.py index 74df090..df837c8 100644 --- a/examples/workflow_fan_out_fan_in_edges.py +++ b/examples/workflow_fan_out_fan_in_edges.py @@ -34,6 +34,12 @@ api_key=token_provider, model=os.environ["AZURE_OPENAI_CHAT_DEPLOYMENT"], ) +elif API_HOST == "ollama": + client = OpenAIChatClient( + base_url=os.environ['OLLAMA_BASE_URL'], + model=os.environ["OLLAMA_MODEL"], + api_key=os.environ['OLLAMA_API_KEY'], + ) else: client = OpenAIChatClient(api_key=os.environ["OPENAI_API_KEY"], model=os.environ.get("OPENAI_MODEL", "gpt-5.4"))