Commit 17cf823
authored
fix: preserve Ollama streaming tool calls (#1948)
Closes #1922.
Ollama can emit `tool_calls` before the final `done=true` chunk when
streaming. The adapter was only reading `chunk.message.tool_calls` from
the final chunk, so a real streamed tool call could turn into an empty
final ADK response.
I changed the streaming path to accumulate tool calls across chunks,
then include them when building the final `LlmResponse`. I also moved
the Ollama tool-call to ADK part conversion into one helper so streaming
and non-streaming stay consistent.
I verified this two ways:
- Added a regression test where the tool call arrives on a non-final
chunk and the done chunk has no tool calls. This failed before the fix
and passes after it.
- Reproduced against a live local Ollama server with `qwen3:0.6b`. Raw
Ollama emitted `get_temperature({"city": "Tokyo"})` on `done=false`,
then a final `done=true` chunk with no tool calls. Before the fix,
kagent returned `function_calls=0`; after the fix, kagent returned the
expected `get_temperature` function call.
Checks run:
- `uv run pytest
packages/kagent-adk/tests/unittests/models/test_ollama.py -q`
- `uv run pytest packages/kagent-adk/tests/unittests/models
--ignore=packages/kagent-adk/tests/unittests/models/test_tls_e2e.py -q`
- `uv run ruff check
packages/kagent-adk/src/kagent/adk/models/_ollama.py
packages/kagent-adk/tests/unittests/models/test_ollama.py`
One note: the full model test directory has unrelated local TLS E2E
failures because the cert fixture files are missing in my checkout. The
non-TLS model tests passed.
Signed-off-by: andreivince <andreivince21@gmail.com>1 parent 32ce1fb commit 17cf823
2 files changed
Lines changed: 56 additions & 11 deletions
File tree
- python/packages/kagent-adk
- src/kagent/adk/models
- tests/unittests/models
Lines changed: 11 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
136 | 143 | | |
137 | 144 | | |
138 | 145 | | |
| |||
190 | 197 | | |
191 | 198 | | |
192 | 199 | | |
| 200 | + | |
193 | 201 | | |
194 | 202 | | |
195 | 203 | | |
| |||
198 | 206 | | |
199 | 207 | | |
200 | 208 | | |
| 209 | + | |
201 | 210 | | |
202 | 211 | | |
203 | 212 | | |
| |||
211 | 220 | | |
212 | 221 | | |
213 | 222 | | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
| 223 | + | |
221 | 224 | | |
222 | 225 | | |
223 | 226 | | |
| |||
245 | 248 | | |
246 | 249 | | |
247 | 250 | | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
| 251 | + | |
252 | 252 | | |
253 | 253 | | |
254 | 254 | | |
| |||
Lines changed: 45 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
95 | 140 | | |
96 | 141 | | |
97 | 142 | | |
| |||
0 commit comments