Skip to content

Commit 71b3cfd

Browse files
committed
refactor(model-caps): enhance model capabilities resolution and validation
- Remove xAI chat model configs from YAML (now server-driven) - Add supports_strict_tools and supports_max_completion_tokens fields - Implement model capability validation with reasonable limits clamping - Improve canonical model name parsing for multi-segment paths (OpenRouter, Gemini) - Add refresh lock to prevent concurrent model caps updates - Make cache I/O async with proper directory creation - Update OpenAI/Gemini model capabilities (strict tools, no temperature) - Add comprehensive tests for resolution, validation, and patterns - Fix default model validation to use full model IDs Fixes #model-capabilities-resolution
1 parent 9157c1c commit 71b3cfd

File tree

6 files changed

+207
-54
lines changed

6 files changed

+207
-54
lines changed

refact-agent/engine/src/caps/caps.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -471,29 +471,23 @@ pub async fn load_caps(
471471

472472
fn validate_default_models(caps: &CodeAssistantCaps) -> Result<(), String> {
473473
if !caps.defaults.chat_default_model.is_empty() {
474-
let model_name = caps.defaults.chat_default_model.split('/').last()
475-
.unwrap_or(&caps.defaults.chat_default_model);
476-
if resolve_model_caps(&caps.model_caps, model_name).is_none() {
474+
if resolve_model_caps(&caps.model_caps, &caps.defaults.chat_default_model).is_none() {
477475
return Err(format!(
478476
"Default chat model '{}' is not supported (not found in model capabilities registry)",
479477
caps.defaults.chat_default_model
480478
));
481479
}
482480
}
483481
if !caps.defaults.chat_thinking_model.is_empty() {
484-
let model_name = caps.defaults.chat_thinking_model.split('/').last()
485-
.unwrap_or(&caps.defaults.chat_thinking_model);
486-
if resolve_model_caps(&caps.model_caps, model_name).is_none() {
482+
if resolve_model_caps(&caps.model_caps, &caps.defaults.chat_thinking_model).is_none() {
487483
return Err(format!(
488484
"Default thinking model '{}' is not supported (not found in model capabilities registry)",
489485
caps.defaults.chat_thinking_model
490486
));
491487
}
492488
}
493489
if !caps.defaults.chat_light_model.is_empty() {
494-
let model_name = caps.defaults.chat_light_model.split('/').last()
495-
.unwrap_or(&caps.defaults.chat_light_model);
496-
if resolve_model_caps(&caps.model_caps, model_name).is_none() {
490+
if resolve_model_caps(&caps.model_caps, &caps.defaults.chat_light_model).is_none() {
497491
return Err(format!(
498492
"Default light model '{}' is not supported (not found in model capabilities registry)",
499493
caps.defaults.chat_light_model
@@ -556,11 +550,14 @@ pub fn resolve_chat_model(
556550

557551
let base_record = resolve_model(&caps.chat_models, model_id)?;
558552

559-
let model_name = model_id.split('/').last().unwrap_or(model_id);
560-
let resolved = resolve_model_caps(&caps.model_caps, model_name);
553+
let resolved = resolve_model_caps(&caps.model_caps, model_id);
561554

562555
match resolved {
563556
Some(resolved_caps) => {
557+
tracing::debug!(
558+
"Model '{}' resolved via {:?}, matched key: '{}'",
559+
model_id, resolved_caps.source, resolved_caps.matched_key
560+
);
564561
let mut effective = (*base_record).clone();
565562
apply_registry_caps_to_chat_model(&mut effective, &resolved_caps.caps);
566563
Ok(Arc::new(effective))
@@ -576,7 +573,10 @@ pub fn resolve_chat_model(
576573

577574
fn apply_registry_caps_to_chat_model(record: &mut ChatModelRecord, caps: &ModelCapabilities) {
578575
record.base.n_ctx = caps.n_ctx;
576+
record.base.supports_max_completion_tokens = caps.supports_max_completion_tokens;
577+
579578
record.supports_tools = caps.supports_tools;
579+
record.supports_strict_tools = caps.supports_strict_tools;
580580
record.supports_multimodality = caps.supports_vision;
581581
record.supports_clicks = caps.supports_clicks;
582582
record.default_temperature = caps.default_temperature;
@@ -596,7 +596,6 @@ fn apply_registry_caps_to_chat_model(record: &mut ChatModelRecord, caps: &ModelC
596596
};
597597

598598
record.supports_boost_reasoning = caps.supports_reasoning_effort;
599-
600599
record.supports_agent = caps.supports_tools;
601600
}
602601

refact-agent/engine/src/caps/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ pub mod providers;
44
pub mod self_hosted;
55

66
pub use caps::*;
7-
pub use model_caps::*;

0 commit comments

Comments
 (0)