Commit ffa6142
refactor: clean up reasoning implementation (#5429)
## Summary
Follow-up cleanups to #5206 (reasoning output in responses API) and
#5407 (type fixes), addressing items from [mattf's
review](#5206 (comment)).
**Code changes**
- **Extracted shared reasoning util**
(`src/llama_stack/providers/utils/inference/reasoning.py`): All three
providers (vLLM, Ollama, Bedrock) had identical message mapping and
chunk wrapping code. Pulled it into a shared `reasoning.py` util with no
defaults -- each provider explicitly passes its field names.
- **Simplified return type**: `openai_chat_completions_with_reasoning`
is streaming-only across all providers. Removed
`OpenAIChatCompletionWithReasoning` from return type in the API
protocol, router, and all provider implementations.
- **Removed dead code**: Deleted no-op `_prepare_reasoning_params` stubs
from vLLM and Bedrock providers. Inlined Ollama's version (2-line
default for `reasoning_effort`).
- **Removed type ignores**: Eliminated `# type: ignore` on
`_separate_tool_calls` assignment (reordered if/else to assign base type
first) and on `tool_call.index` usage in streaming chunk processing.
**Test changes:**
- Added `test_reasoning_basic_streaming` and
`test_reasoning_multi_turn_with_tool_call` to the `ollama-reasoning`
test suite.
- Un-skipped vLLM reasoning tests -- the CI action.yaml now configures a
reasoning parser, so vLLM actually returns reasoning tokens.
## Addressed from
[review](#5206 (comment))
| Item | Status |
|------|--------|
| `openai_chat_completions_with_reasoning` is streaming only, remove
non-streaming return type | Done |
| Remove unused `_prepare_reasoning_params` from vLLM | Done |
| Remove unused `_prepare_reasoning_params` from Bedrock | Done |
| Inline `_prepare_reasoning_params` for Ollama | Done |
| bedrock, vllm, ollama need same transformations -- consider a util |
Done |
| Put `message = OpenAIAssistantMessageParam` case first to resolve type
ignore | Done |
| Figure out why there are new type ignores | Done (removed 5 type
ignores) |
| Type of `completion_result` confused by storing both CC and
CC-with-reasoning | Done (removed non-streaming type from union) |
## TODO ( needs design discussion )
| Item | Question |
|------|----------|
| **Non-adjacent reasoning items** | `_get_preceding_reasoning` only
checks `index - 1`, based on what I observed from official openai's
response output. Is there a missing Edge case ? |
| **Error vs silent fallback** | When a user asks for reasoning and the
provider doesn't support it, should we return an error or silently
proceed without reasoning? Currently falls back silently with a
`critical` log. |
| **Move merge logic to provider** | Suggestions Appreciated ... |
| **Gemini implementation** | Gemini is strict on input shape and may
use different field names (e.g. `"thinking"`). The shared util now
supports custom field names, so this is ready to implement. |
| **`n != 1` simplification** | Not sure what this means |
| **Reduce `model_copy()` calls** | For safety, currently copying params
in multiple places. Need to trace mutation paths to determine redundant
copies. |
| **Complete types on `_separate_tool_calls`** | Didn't tamper for now |
## Test plan
- [x] BFCL Eval maintains accuracy
- [x] vllm server renders prompt correctly with reasoning inside
`analysis` channel
- [x] `uv run pre-commit run mypy-full --hook-stage manual --all-files`
# passes
---------
Signed-off-by: robinnarsinghranabhat <robinnarsingha123@gmail.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Matthew Farrellee <matt@cs.wisc.edu>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>1 parent 5e79a81 commit ffa6142
19 files changed
Lines changed: 24046 additions & 2401 deletions
File tree
- docs/docs/api-openai
- src/ogx
- core/routers
- providers/inline/responses/builtin/responses
- tests/integration
- common/recordings
- responses/recordings
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
165 | 165 | | |
166 | 166 | | |
167 | 167 | | |
168 | | - | |
| 168 | + | |
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
49 | 48 | | |
50 | 49 | | |
51 | 50 | | |
| |||
316 | 315 | | |
317 | 316 | | |
318 | 317 | | |
319 | | - | |
| 318 | + | |
320 | 319 | | |
321 | 320 | | |
322 | 321 | | |
| |||
Lines changed: 17 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
569 | 569 | | |
570 | 570 | | |
571 | 571 | | |
572 | | - | |
573 | | - | |
574 | | - | |
| 572 | + | |
| 573 | + | |
575 | 574 | | |
576 | | - | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
577 | 578 | | |
578 | 579 | | |
579 | 580 | | |
| |||
598 | 599 | | |
599 | 600 | | |
600 | 601 | | |
| 602 | + | |
601 | 603 | | |
602 | 604 | | |
603 | 605 | | |
| |||
810 | 812 | | |
811 | 813 | | |
812 | 814 | | |
813 | | - | |
814 | | - | |
815 | | - | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
816 | 821 | | |
817 | 822 | | |
818 | 823 | | |
819 | 824 | | |
820 | 825 | | |
821 | 826 | | |
822 | | - | |
823 | | - | |
824 | | - | |
825 | | - | |
826 | | - | |
827 | 827 | | |
828 | 828 | | |
829 | 829 | | |
| |||
1239 | 1239 | | |
1240 | 1240 | | |
1241 | 1241 | | |
1242 | | - | |
| 1242 | + | |
1243 | 1243 | | |
1244 | 1244 | | |
1245 | 1245 | | |
| |||
1251 | 1251 | | |
1252 | 1252 | | |
1253 | 1253 | | |
1254 | | - | |
| 1254 | + | |
1255 | 1255 | | |
1256 | 1256 | | |
1257 | 1257 | | |
1258 | | - | |
| 1258 | + | |
1259 | 1259 | | |
1260 | 1260 | | |
1261 | 1261 | | |
1262 | | - | |
1263 | | - | |
| 1262 | + | |
| 1263 | + | |
1264 | 1264 | | |
1265 | 1265 | | |
1266 | 1266 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| 83 | + | |
83 | 84 | | |
84 | | - | |
85 | 85 | | |
86 | 86 | | |
Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments