Skip to content

[mirror] refactor(platform/copilot): consolidate 4 model-routing LD flags into 1 JSON flag#4

Open
yashwant86 wants to merge 2 commits intomm-base-12917from
mm-pr-12917
Open

[mirror] refactor(platform/copilot): consolidate 4 model-routing LD flags into 1 JSON flag#4
yashwant86 wants to merge 2 commits intomm-base-12917from
mm-pr-12917

Conversation

@yashwant86
Copy link
Copy Markdown

@yashwant86 yashwant86 commented Apr 26, 2026

Mirror of upstream Significant-Gravitas#12917 for benchmark. Do not merge.


Summary by MergeMonkey

  • Documentation:
    • Updated LD flag documentation to reflect consolidation from 4 string flags to 1 JSON flag.
    • Clarified model routing matrix and payload shape in module docstrings.
  • Housekeeping:
    • Consolidated 4 separate LaunchDarkly model-routing flags into single JSON-valued flag.
    • Refactored model resolver to parse nested JSON structure instead of per-cell lookups.

majdyz added 2 commits April 25, 2026 06:31
… 1 JSON flag

Replaces 4 string-valued LaunchDarkly flags (copilot-fast-standard-model,
copilot-fast-advanced-model, copilot-thinking-standard-model,
copilot-thinking-advanced-model) with a single JSON flag
`copilot-model-routing` keyed by `{mode: {tier: model}}`.

Same pattern as Significant-Gravitas#12915 (pricing flags) and Significant-Gravitas#12910 (tier-multipliers): one
flag per config domain, atomic updates, smaller LD UI surface. Per-user
targeting is preserved. Missing mode, missing tier-within-mode, non-string
cell value, non-dict payload, and LD failures all fall back to the
existing ChatConfig default — user-visible semantics don't change.

Removes the per-cell _FLAG_BY_CELL dispatch dict in model_router.py;
docstring references in copilot/config.py + copilot/sdk/service.py
updated to point at the new nested key path.
- Mirror the top-level non-dict warning down to the per-mode level: if the
  operator types a string at copilot-model-routing[<mode>] instead of a
  {tier: model} dict, log a warning so the typo surfaces in operator-facing
  logs instead of silently dropping to ChatConfig defaults.
- Annotate `payload: object` to make the dynamic-typed return value explicit
  for readers who land mid-function.
@bot-mergemonkey
Copy link
Copy Markdown

bot-mergemonkey Bot commented Apr 26, 2026

Risk AssessmentNEEDS-TESTING · ~25 min review

Focus areas: JSON payload parsing and validation logic · Fallback behavior at each validation level · Test coverage for partial/invalid payloads · Backward compatibility with old flag references

Assessment: Consolidates 4 LD flags into 1 JSON flag; requires integration testing with LD service.

Changes

Files Summary
Feature Flag Definition
autogpt_platform/backend/backend/util/feature_flag.py
Replaced 4 separate string-valued model routing flags (COPILOT_FAST_STANDARD_MODEL, COPILOT_FAST_ADVANCED_MODEL, COPILOT_THINKING_STANDARD_MODEL, COPILOT_THINKING_ADVANCED_MODEL) with single JSON-valued COPILOT_MODEL_ROUTING flag supporting nested (mode, tier) structure.
Model Router Core Logic
autogpt_platform/backend/backend/copilot/model_router.py
Refactored resolve_model() to fetch single JSON payload and navigate nested structure (mode → tier → model string) instead of per-cell flag lookups. Added comprehensive validation for payload shape, mode dict, tier value with granular fallback and logging at each level.
Configuration Documentation
autogpt_platform/backend/backend/copilot/config.py
Updated field descriptions to reference consolidated copilot-model-routing[mode][tier] flag path instead of individual flag names.
SDK Service Documentation
autogpt_platform/backend/backend/copilot/sdk/service.py
Updated docstrings and comments to reference consolidated copilot-model-routing[thinking][tier] flag path.
Test Suite Refactor
autogpt_platform/backend/backend/copilot/model_router_test.py
autogpt_platform/backend/backend/copilot/sdk/service_test.py
Removed _FLAG_BY_CELL import and per-cell flag tests. Added comprehensive tests for JSON payload parsing: None payload, full/partial payloads, missing modes/tiers, non-dict payloads, non-string cell values, empty strings, mode-level type errors, and single LD call regression guard.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant resolve_model
    participant LD as LaunchDarkly
    participant Logger
    participant Config
    Caller->>resolve_model: resolve_model(mode, tier, user_id)
    resolve_model->>LD: get_feature_flag_value("copilot-model-routing", user_id)
    alt LD Exception
        LD-->>resolve_model: Exception
        resolve_model->>Logger: warning("LD lookup failed")
        resolve_model->>Config: fallback
    else LD Success
        LD-->>resolve_model: payload (object)
        alt payload is None
            resolve_model->>Config: fallback
        else payload is not dict
            resolve_model->>Logger: warning("expected JSON object")
            resolve_model->>Config: fallback
        else payload is dict
            alt mode not in payload
                resolve_model->>Config: fallback
            else mode in payload but not dict
                resolve_model->>Logger: warning("mode expected dict")
                resolve_model->>Config: fallback
            else mode is dict
                alt tier value is string and non-empty
                    resolve_model-->>Caller: value.strip()
                else tier value is None
                    resolve_model->>Config: fallback
                else tier value is non-string or empty
                    resolve_model->>Logger: warning("invalid cell value")
                    resolve_model->>Config: fallback
                end
            end
        end
    end
Loading

Dig Deeper With Commands

  • /review <file-path> <function-optional>
  • /chat <file-path> "<question>"
  • /roast <file-path>

Runs only when explicitly triggered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants