feat(llm): add opt-in Responses API mode#898
Conversation
Walkthrough
ChangesResponses API support
Estimated code review effort: 4 (Complex) | ~45 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Independent review follow-upA separate read-only reviewer audited the staged changes after implementation. Verdict: no blocking security, correctness, or compatibility issues. Verified by the reviewer:
Non-blocking notes considered:
No follow-up code change was required. |
There was a problem hiding this comment.
🧹 Nitpick comments (3)
src/llm/backends/openai.py (2)
153-164: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value
temperature,stop, andthinking_budget_tokensare silently dropped in Responses mode.Both the
complete()(here) andstream()(Lines 267-280) responses branches forward only a subset of the caller-provided arguments. The Responses API does accepttemperature/stop-equivalent parameters, so callers setting them will find them silently ignored onceapi_mode="responses". If this omission is intentional (e.g. reasoning-only usage), a brief comment documenting it would prevent confusion; otherwise these should be threaded into_build_responses_params.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/llm/backends/openai.py` around lines 153 - 164, Update the Responses-mode branches in complete() and stream() to preserve temperature, stop, and thinking_budget_tokens from the caller, threading them through _complete_responses and _build_responses_params as supported by the Responses API. If any parameter is intentionally unsupported, document that explicitly in a concise comment instead of silently dropping it.
10-10: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAvoid the private OpenAI helper import
openai.lib._pydantic.to_strict_json_schemais an internal SDK symbol, so a routine OpenAI upgrade can break this backend at import time. Prefer a public schema helper or a small compatibility wrapper around the import.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/llm/backends/openai.py` at line 10, Replace the direct private import of to_strict_json_schema in the OpenAI backend with a compatibility wrapper that prefers a public schema-generation API and falls back safely when needed; update all call sites to use the wrapper so OpenAI SDK upgrades cannot break module import.tests/llm/test_backends/test_openai.py (1)
1103-1121: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider adding coverage for a named-function
tool_choice.The tool tests only exercise
tool_choice="required", which passes through unchanged. A named-function choice (e.g.tool_choice="lookup") would surface the Chat-Completions-vs-Responses shape mismatch flagged insrc/llm/backends/openai.py(Lines 468-472). Adding that assertion would guard against the regression.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/llm/test_backends/test_openai.py` around lines 1103 - 1121, Add a test case in the OpenAI Responses tool-choice coverage that passes a named function such as tool_choice="lookup" through the relevant test setup, then assert client.responses.stream receives the Responses API function-choice object with the expected function name rather than the Chat Completions shape. Keep the existing required-choice assertions and use the existing test symbols and call-capture pattern.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/llm/backends/openai.py`:
- Around line 153-164: Update the Responses-mode branches in complete() and
stream() to preserve temperature, stop, and thinking_budget_tokens from the
caller, threading them through _complete_responses and _build_responses_params
as supported by the Responses API. If any parameter is intentionally
unsupported, document that explicitly in a concise comment instead of silently
dropping it.
- Line 10: Replace the direct private import of to_strict_json_schema in the
OpenAI backend with a compatibility wrapper that prefers a public
schema-generation API and falls back safely when needed; update all call sites
to use the wrapper so OpenAI SDK upgrades cannot break module import.
In `@tests/llm/test_backends/test_openai.py`:
- Around line 1103-1121: Add a test case in the OpenAI Responses tool-choice
coverage that passes a named function such as tool_choice="lookup" through the
relevant test setup, then assert client.responses.stream receives the Responses
API function-choice object with the expected function name rather than the Chat
Completions shape. Keep the existing required-choice assertions and use the
existing test symbols and call-capture pattern.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 94cdb010-abda-46be-815a-3f59993fe707
📒 Files selected for processing (2)
src/llm/backends/openai.pytests/llm/test_backends/test_openai.py
|
All LLM tests, Ruff, basedpyright, live structured/tool/streaming probes, and the attribution canary pass. The author has requested immediate merge; this PR is mergeable but requires maintainer review and merge permission. |
Summary
response.completedevent omits assembled outputmax_output_tokenswhen their Responses endpoint rejects itprovider_params.api_modeis explicitlyresponsesValidation
pytest -n 0 tests/llm -q— 231 passedruff check— passedbasedpyright src/llm/backends/openai.py— 0 errors, 0 warningsgpt-5.6-lunabridge:STREAM_OKCompatibility
Responses mode is opt-in through model
provider_params; existing OpenAI Chat Completions callers retain the original code path.Summary by CodeRabbit
New Features
Tests