feat: make LLM and embedding model configurable via YAML config - #112
feat: make LLM and embedding model configurable via YAML config#112AaryanCode69 wants to merge 2 commits into
Conversation
Previously, the model provider and model name were hard-coded in
AgentGraph.__init__() as get_llm("openai", "gpt-4o-mini") and
get_embedding("openai", "text-embedding-3-large"). This made it
impossible to switch models without modifying source code.
- Add llm and embedding configuration fields to the YAML config schema
- Update Pydantic config models to validate new model settings
- Update AgentGraph to read provider/model from YAML config instead
of hard-coded values
- Retain existing defaults for backward compatibility
Resolves reactome#108
Pydantic v2 BaseModel rejects unknown fields by default. Adding a `models` key to config.yml caused the entire Config to fail validation, returning None and silently disabling messages, rate limits, and feature flags. Setting extra="ignore" lets the parser skip unrecognized keys while still loading all known configuration correctly.
|
Thank you @AaryanCode69 — and sorry it took this long to come back to you. This is now implemented in #201, and the design is yours. Two things you got right that I kept: Named fields rather than a parsed string. #151 proposed the same feature as Optional with sane fallbacks, so a What I changed, and whyYour What I did not take:
|
T025-T027. Both contributed PRs are closed as implemented, each with a comment saying specifically what was taken from it and why the embedding half was not: a query embedded with a different model than built the vectors returns confident nonsense rather than an error, so the model comes from the bundle path and config.yml deliberately cannot name one. Records the two defects writing it found -- pydantic silently ignoring unknown keys, and the same guard being one level too low so a typo in the section name loaded cleanly and did nothing -- and the pattern behind both: the guard was placed on the thing being built rather than on the seam beside it. User Story 3 remains unbuilt on purpose; only chat exists. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Summary
Make LLM and embedding model/provider configurable via the existing YAML config system instead of being hard-coded in
AgentGraph.__init__().Problem
The model provider and model name were hard-coded in
AgentGraph.__init__():This made it impossible to switch models, providers, or base URLs without directly modifying source code — limiting experimentation, self-hosting with local models (e.g., Ollama), and deployment flexibility.
Solution
Introduce a
ModelsConfigPydantic model and wire it through the existing YAML config pipeline so users can control models declaratively:AgentGraphnow reads from config instead of hard-coded values:Changes
src/util/config_yml/models.pyLLMConfig,EmbeddingConfig, andModelsConfigPydantic models with sensible defaultssrc/util/config_yml/__init__.pymodels: ModelsConfigfield toConfigwith a default so existing configs without the key still worksrc/agent/graph.pyAgentGraph.__init__()accepts optionalModelsConfig; reads provider/model from config instead of hard-coded stringsbin/chat-chainlit.pyconfig.modelsthrough toAgentGraphat startupconfig_default.ymlmodelssection with current default values documentedBackward Compatibility
modelskey in YAML is optional —ModelsConfigdefaults toopenai/gpt-4o-miniandopenai/text-embedding-3-large, matching the previously hard-coded values.AgentGraphacceptsmodels_config=Noneand falls back to the same defaults.config.ymlfiles without amodelssection continue to work without modification.Example: Switching to Ollama
No code changes required — just update the YAML config and restart.
How This Enables Future MCP Integration
AgentGraphno longer owns provider/model decisions, making it easier for an MCP server to initialize its own LLM instances from the same shared config.ModelsConfigPydantic model provides a validated, extensible schema. Future MCP settings (server URL, transport, tool registrations) can follow the same pattern and live alongside it inconfig.yml.Related Issue
Resolves #108