feat: per-task LLM model selection + backup-model fallback (closes #15)#31
Merged
Conversation
All agents previously ran off a single global LLM config, even though profile gen, report writing, and sentiment classification have very different cost/quality needs — and a failed call had no graceful recovery. - Config: LLM_TASK_MODELS (LLM_MODEL_<TASK> env overrides) with model_for_task() resolving per-task -> global default, plus LLM_FALLBACK_* and an llm_settings() helper that returns a directly-constructable settings dict. - LLMClient: new for_task(task) factory and an optional backup model. chat() now selects the model per call and, on a primary failure, retries once against the configured fallback model (which may live on a different provider). The fallback is skipped when unset or identical to the primary. - Wired task sites: report/ontology/tools -> LLMClient.for_task(); profile/ config/sentiment -> Config.model_for_task(). - Documented the new env vars in .env.example. - tests/test_llm_task_config.py: per-task resolution, fallback engagement, primary-success path, error propagation when no/identical fallback. Stacked on the #17 guardrail branch (shared llm_client.py changes). Co-Authored-By: PRATHAMESH75 <prathamesh290504@gmail.com>
This was referenced Jun 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #15. Lets each agent task pick its own model and adds graceful fallback to a backup model when a call fails.
Changes
config.pyLLM_TASK_MODELS— per-task overrides viaLLM_MODEL_<TASK>env vars (profile,config,report,ontology,sentiment,tools).Config.model_for_task(task)— resolves task override → globalLLM_MODEL_NAME.LLM_FALLBACK_MODEL/LLM_FALLBACK_BASE_URL/LLM_FALLBACK_API_KEY+Config.llm_settings(task)returning a directly-constructable settings dict.llm_client.pyLLMClient.for_task(task, **overrides)factory.chat()selects the model per call and, on a primary failure, retries once against the fallback. Skipped when the fallback is unset or identical to the primary.report_agent/ontology_generator/zep_tools→LLMClient.for_task(...);oasis_profile_generator/simulation_config_generator/sentiment_analyzer→Config.model_for_task(...)..env.example— documented all new vars.Acceptance criteria
Testing
tests/test_llm_task_config.py(11 tests): per-task resolution + global fallback,llm_settingswith/without fallback,for_taskmodel selection + override precedence, fallback engagement on primary failure, primary-success path (backup untouched), error propagation when no/identical fallback.🤖 Generated with Claude Code