Repository navigation
refactor(narratives): decouple Gemini model configuration per role - #541
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces granular, per-role Gemini model configurations within the narratives agent. Instead of routing most roles through a single discovery_model, individual configuration fields have been added for synthesis_model, chart_config_model, chart_validation_model, follow_up_model, and compaction_model alongside the existing classify_model and discovery_model. The GeminiConfig class, parser, JSON schema, example configuration, and documentation have been updated to support these new fields, and the corresponding unit tests have been expanded to verify independent configuration and fallback behaviors. There are no review comments to evaluate, and I have no additional feedback to provide.
Overview
After #537 and #538,
config_model.pydefines sevenGeminiRolemembers (CLASSIFY,DISCOVERY,SYNTHESIS,CHART_CONFIG,CHART_VALIDATION,FOLLOW_UP, andCOMPACTION) and resolves each role's model, temperature, and thinking level throughAgentConfig.resolve_role_config. However,GeminiConfigstill carries onlyclassify_modelanddiscovery_modeland routes six roles (DISCOVERY,SYNTHESIS,CHART_CONFIG,CHART_VALIDATION,FOLLOW_UP, andCOMPACTION) toself.gemini.discovery_model, preventing operators from configuring a lighter or faster model forDISCOVERY,CHART_CONFIG,FOLLOW_UP, orCOMPACTIONwithout also changing the model used forSYNTHESIS.This PR gives every
GeminiRoleits own<role>_modelfield onGeminiConfig(classify_model,discovery_model,synthesis_model,chart_config_model,chart_validation_model,follow_up_model, andcompaction_model) and inschemas/agent-config.schema.json, and updatesAgentConfig.resolve_role_configto resolve each role's model from its matchingGeminiConfigattribute via_ROLE_MODEL_ATTRS. Because all workflow call sites already resolve their model viaconfig.resolve_role_config(role).model, each LLM-calling role can now be configured independently without changing any workflow call sites.Related Issues
Changes Made
config_model.py): Addssynthesis_model,chart_config_model,chart_validation_model,follow_up_model, andcompaction_modeltoGeminiConfig(each defaulting toDEFAULT_GEMINI_MODEL), parses all sevengemini.<role>_modelkeys inparse_agent_configvia_read_model_name, and resolves eachGeminiRole's model inAgentConfig.resolve_role_configvia_ROLE_MODEL_ATTRS.schemas/,workflows/): Adds the five newgemini.<role>_modelproperties toschemas/agent-config.schema.jsonandschemas/agent-config.example.json, and updates theconfigparameter docstrings inworkflows/chart_config.py,workflows/follow_up.py, andworkflows/transcript.pyto reference their respectivegemini.<role>_modelkeys.config_model_test.py,docs/deployment.md): Parametrizes model-fallback and independent per-role model override tests across all sevenGeminiRolemembers inconfig_model_test.py, and updatesdocs/deployment.mdto document all sevengemini.<role>_modelkeys and their defaults.Testing Done
pnpm test:agent(uv run pytest): 863 passed (826 onmainat16cc4e50, with 37 net new parametrized per-role model fallback and independent override test cases inconfig_model_test.py).pnpm test:ui(vitest run): 26 files, 286 passed.pnpm lint:ui(tsc --noEmitandbiome check): passed across 48 checked files.pnpm lint:agent(ruff format --check,ruff check, andmypy --strict): passed across all 64 source files with no overrides.pnpm lint:deploy:terraform fmt -check,shellcheck, andhadolintpassed (terraform validatehas a pre-existing local Terraform 1.15 backend-config error unrelated to this PR; nodeploy/files are modified).npx --yes -p ajv-cli@5.0.0 -p ajv-formats@3.0.1 ajv validate --spec=draft2020 --strict=false -c ajv-formats -s schemas/agent-config.schema.json -d defaults/agent-config.jsonand-d schemas/agent-config.example.json: both valid.pnpm buildwas not run.Checklist:
config_model_test.pyupdated to cover all sevengemini.<role>_modelfields)Manual
Verified with
uv run pythonagainstparse_agent_configanddefaults/agent-config.json:defaults/agent-config.json(which specifies onlygemini.classify_model) throughparse_agent_config. Verified that no warnings were logged,GeminiRole.CLASSIFYresolved togemini-3.5-flash-liteatMINIMALthinking, andDISCOVERY,SYNTHESIS,CHART_CONFIG,CHART_VALIDATION,FOLLOW_UP, andCOMPACTIONall resolved togemini-3.8-flash(DEFAULT_GEMINI_MODEL).{"gemini": {"synthesis_model": "gemini-3-pro", "follow_up_model": "gemini-3.5-flash-lite"}}and verified throughresolve_role_configthatSYNTHESISresolved togemini-3-proandFOLLOW_UPresolved togemini-3.5-flash-litewhileDISCOVERY,CHART_CONFIG,CHART_VALIDATION, andCOMPACTIONremained ongemini-3.8-flash.{"gemini": {"chart_config_model": " "}}and verified thatparse_agent_configlogged a single warning (Agent configuration key 'gemini.chart_config_model' is blank; using 'gemini-3.8-flash') and resolvedGeminiRole.CHART_CONFIGtogemini-3.8-flash.Risk & Rollback
All new
gemini.<role>_modelkeys (synthesis_model,chart_config_model,chart_validation_model,follow_up_model, andcompaction_model) are optional and default togemini-3.8-flash(DEFAULT_GEMINI_MODEL), preserving identical model resolution when omitted (defaults/agent-config.jsonrequires no changes). There are no active production deployments of Narratives. Rollback is reverting the PR.Follow-ups
Checklist
AGENTS.mdand followedCODING_GUIDELINES.md, plusFRONTEND.mdfor UI changes.Note: Only Maintainers can approve and merge PRs. Expected initial review time: 3 business days.