Add previous messages to LLM response context / fix OpenAI regressions
Merged
JJ
8mo ago+928+928+012345678901234567890123456789-81-81-01234567890123456789
Motivation
- Rebase the feature that forwards conversation history to LLM providers and introduce a centralized LLM configuration while keeping existing behavior and tests stable.
- Restore correct OpenAI model resolution precedence and compatibility for custom providers that broke during the rebase.
Description
- Add a new YAML LLM config file and loader (
config/llm.yml,Provider::Openai.llm_config/active_provider) to drive provider defaults and capabilities. - Restore ENV-first model precedence by reading
OPENAI_MODELwithENV.fetchfallback and use the class-leveleffective_modelwhere appropriate to determine defaults. - Wire conversation history from
Assistant::Responderinto the provider call path and ensure it is passed into both the native responses flow and the generic chat flow viamessages:. - Extend
Provider::Openai::ChatConfig#build_inputandProvider::LlmConceptto accept fullmessagesarrays (including serialized tool call/results), and normalizesupported_models_descriptionformatting to match existing tests. - Update tests to assert that conversation history is passed through and adapt test expectations to the new chat payload shape.
Testing
- Ran targeted unit tests with
bin/rails test test/models/assistant_test.rbandbin/rails test test/models/chat_test.rb test/models/provider/openai_test.rb test/models/provider/registry_test.rb, which passed with no failures. - Installed bundle with the project Ruby and ran the full test suite via
bin/rails test, which completed successfully in this environment (skips present as in CI).
Summary by CodeRabbit
-
New Features
- Configurable LLM token-budget controls in hosting settings (context window, max response tokens, max items per batch).
-
Configuration
- New example/env docs and flags for LLM budgeting and OpenAI-compatible capabilities; settings UI fields added with validation and min constraints.
-
Improvements
- Conversation-history trimming and batching to optimize context usage.
- Streaming error handling now marks partial assistant responses as failed.
-
Tests
- Expanded test coverage for budgeting, history trimming, token estimation, and batching.