Add previous messages to LLM response context / fix OpenAI regressions

Merged
JJ
8mo ago
+928-81

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_MODEL with ENV.fetch fallback and use the class-level effective_model where appropriate to determine defaults.
  • Wire conversation history from Assistant::Responder into the provider call path and ensure it is passed into both the native responses flow and the generic chat flow via messages:.
  • Extend Provider::Openai::ChatConfig#build_input and Provider::LlmConcept to accept full messages arrays (including serialized tool call/results), and normalize supported_models_description formatting 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.rb and bin/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).

Codex Task

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.