Skip to content

Implement RouterLLM and enhance OpenAI compatibility configuration - #2642

Open
openminddev wants to merge 2 commits into
mainfrom
add-simple-llm-router
Open

Implement RouterLLM and enhance OpenAI compatibility configuration#2642
openminddev wants to merge 2 commits into
mainfrom
add-simple-llm-router

Conversation

@openminddev

Copy link
Copy Markdown
Contributor

This pull request introduces a new router-based LLM selection mechanism and enhances configuration flexibility for OpenAI-compatible LLMs. The most significant changes are the addition of the RouterLLM for dynamic routing of prompts to different LLM backends based on keywords and patterns, and the extension of the OpenAI compatibility layer to support extra parameters and tool choice overrides.

New Router-based LLM Selection

  • Added router.go, implementing RouterLLM, which routes prompts to different LLMs based on configurable keywords and regex patterns, with support for a default route and API key propagation.
  • Added comprehensive tests for the router logic in router_test.go, covering route selection, fallback behavior, schema propagation, and configuration validation.

OpenAI Compatibility Improvements

  • Extended compatConfig to support tool_choice and arbitrary extra_params, allowing more flexible configuration of OpenAI-compatible LLMs.
  • Updated the OpenAI compatibility LLM constructor to use these new fields and to propagate extra parameters to the model instance.
  • Added tests to verify that tool_choice and extra_params are correctly overridden from the config.

Introduce a RouterLLM implementation (plugins/llm/router.go) that dispatches prompts to configured sub-LLMs based on keywords and regex patterns, supports a default route, shared API key propagation, and schema propagation. Extend openai_compat to accept tool_choice and extra_params (extraBody) and wire them into the returned openAICompatLLM; update tests accordingly (openai_compat_test.go) and add comprehensive router tests (router_test.go) to validate routing, scoring, call dispatch, schema propagation, and config validation.
Copilot AI review requested due to automatic review settings July 1, 2026 19:47
@openminddev
openminddev requested review from a team as code owners July 1, 2026 19:47
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.70588% with 13 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
plugins/llm/router.go 83.33% 7 Missing and 6 partials ⚠️

📢 Thoughts on this report? Let us know!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new RouterLLM plugin to dynamically select among multiple LLM backends based on keyword/regex scoring, and expands the OpenAI-compatible configuration to allow overriding tool_choice and passing arbitrary extra_params into the request body.

Changes:

  • Introduces RouterLLM with route scoring (keywords + regex patterns), default route fallback, and shared API key propagation.
  • Adds router unit tests covering route selection, fallback behavior, schema propagation, and config validation.
  • Extends OpenAI-compat config with tool_choice and extra_params, plus tests validating these overrides.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
plugins/llm/router.go New router LLM implementation with configurable routes, scoring, default route selection, and API key propagation.
plugins/llm/router_test.go Tests for routing logic, schema propagation, and config validation paths.
plugins/llm/openai_compat.go Adds tool_choice and extra_params to compat config and wires them into instance construction.
plugins/llm/openai_compat_test.go Adds coverage to ensure tool_choice and extra_params are applied from config.

Comment thread plugins/llm/router.go
Comment thread plugins/llm/router.go
Comment thread plugins/llm/openai_compat.go
Copy extraBody into the request body first, then explicitly set core fields so reserved keys (model, messages, tool_choice) cannot be overridden. Add maps import and allocate requestBody with capacity based on extraBody. Remove the manual loop that merged extraBody. Add TestOpenAICompatCallExtraBodyCannotOverrideCoreFields to verify core fields win, messages remain the built array, and non-reserved params (e.g. temperature) still pass through.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants