cleanup: remove model name string matching

model_context_window() now reads from config.api_context_window
instead of guessing from model name strings. is_anthropic_model()
replaced with backend == "anthropic" checks. Dead model field
removed from AgentDef/AgentHeader.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
Kent Overstreet 2026-04-02 14:09:54 -04:00
parent 47c6694b10
commit 078dcf22d0
5 changed files with 15 additions and 32 deletions

View file

@ -53,6 +53,7 @@ pub struct ContextGroup {
}
fn default_true() -> bool { true }
fn default_context_window() -> usize { 128_000 }
fn default_identity_dir() -> PathBuf {
PathBuf::from(std::env::var("HOME").expect("HOME not set")).join(".consciousness/identity")
}
@ -85,6 +86,8 @@ pub struct Config {
pub api_key: Option<String>,
#[serde(skip)]
pub api_model: Option<String>,
#[serde(skip, default = "default_context_window")]
pub api_context_window: usize,
/// Used to resolve API settings, not stored on Config
#[serde(default)]
agent_model: Option<String>,
@ -134,6 +137,7 @@ impl Default for Config {
api_base_url: None,
api_key: None,
api_model: None,
api_context_window: default_context_window(),
agent_model: None,
api_reasoning: "high".to_string(),
agent_types: vec![
@ -178,6 +182,9 @@ impl Config {
.and_then(|v| v.as_str()).map(String::from);
}
config.api_model = Some(model_id.to_string());
if let Some(cw) = model_cfg.get("context_window").and_then(|v| v.as_u64()) {
config.api_context_window = cw as usize;
}
}
Some(config)
@ -479,7 +486,7 @@ impl AppConfig {
api_base = base;
api_key = key;
model = mdl;
prompt_file = if is_anthropic_model(&model) {
prompt_file = if self.backend == "anthropic" {
self.prompts.anthropic.clone()
} else {
self.prompts.other.clone()
@ -546,7 +553,7 @@ impl AppConfig {
let prompt_file = model.prompt_file.clone()
.unwrap_or_else(|| {
if is_anthropic_model(&model.model_id) {
if model.backend == "anthropic" {
self.prompts.anthropic.clone()
} else {
self.prompts.other.clone()
@ -651,11 +658,6 @@ pub fn reload_for_model(app: &AppConfig, prompt_file: &str) -> Result<(String, V
Ok((system_prompt, context_parts))
}
fn is_anthropic_model(model: &str) -> bool {
let m = model.to_lowercase();
m.contains("claude") || m.contains("opus") || m.contains("sonnet")
}
pub fn show_config(app: &AppConfig, figment: &Figment) {
fn mask(key: &str) -> String {
if key.is_empty() { "(not set)".into() }