Skip to content

Switchyard lets LLM applications route traffic across models and providers while preserving native OpenAI and Anthropic API compatibility - enabling flexible model selection, benchmarking, and cost/performance optimization.

Rust

feat(vgr): let the efficient tier attempt attachment requests when configured (#1279)

GDRS0a8f516a1872
diff --git a/crates/libsy/src/algorithms/vgr.rs b/crates/libsy/src/algorithms/vgr.rs
index 274a80a62..2b4b2efbb 100644
--- a/crates/libsy/src/algorithms/vgr.rs
+++ b/crates/libsy/src/algorithms/vgr.rs
@@ -150,13 +150,19 @@ struct Capabilities {
}
/// Derives capabilities from the router's own evidence, failing closed.
+///
+/// Media blocks fail closed unless `media_judged_as_text` lets the judge read the text around them.
fn derive_capabilities(
request: &Request,
attempt: &str,
task_type: Option<TaskType>,
+ media_judged_as_text: bool,
) -> Capabilities {
let (turns, unsupported) = text::turns(request);
- if unsupported || text::user_task_text(&turns).trim().is_empty() || attempt.trim().is_empty() {
+ if (unsupported && !media_judged_as_text)
+ || text::user_task_text(&turns).trim().is_empty()
+ || attempt.trim().is_empty()
+ {
return Capabilities::default();
}
let caps = |branch, transcript| Capabilities {
diff --git a/crates/libsy/src/algorithms/vgr/config.rs b/crates/libsy/src/algorithms/vgr/config.rs
index 1c730a10d..006d7d578 100644
--- a/crates/libsy/src/algorithms/vgr/config.rs
+++ b/crates/libsy/src/algorithms/vgr/config.rs
@@ -58,8 +58,8 @@ pub struct VgrConfig {
pub breaker: BreakerConfig,
/// Whether a cheap typing call selects a verification regime.
pub task_typing: bool,
- /// Whether the efficient tier accepts image content.
- pub efficient_supports_images: bool,
+ /// Whether the efficient tier accepts attachments.
+ pub efficient_supports_attachments: bool,
/// Lets a long agentic run with earlier tool errors commit on a capable-tier
/// confirmation once it ends in this many consecutive clean tool results.
pub confirmed_recovery_min_clean_tail: Option<u32>,
@@ -92,7 +92,7 @@ impl VgrConfig {
kill_switch: None,
breaker: BreakerConfig::default(),
task_typing: true,
- efficient_supports_images: false,
+ efficient_supports_attachments: false,
confirmed_recovery_min_clean_tail: None,
agentic_handoff: false,
compact_handoff: false,
diff --git a/crates/libsy/src/algorithms/vgr/runtime.rs b/crates/libsy/src/algorithms/vgr/runtime.rs
index 6d8ac7f3c..9fe171375 100644
--- a/crates/libsy/src/algorithms/vgr/runtime.rs
+++ b/crates/libsy/src/algorithms/vgr/runtime.rs
@@ -154,7 +154,7 @@ impl Classifier for VgrClassifier {
Some("turn_verification_latched")
} else if turn_budget_spent {
Some("efficient_turn_budget")
- } else if !self.config.efficient_supports_images && request_has_image(request) {
+ } else if !self.config.efficient_supports_attachments && request_has_image(request) {
Some("efficient_image_unsupported")
} else if text::newest_prompt_is_blank(request) {
Some("empty_prompt")
@@ -256,7 +256,12 @@ impl Classifier for VgrClassifier {
let attempt = rungs::response_text(&buffered.agg).unwrap_or_default();
let task_type = self.type_task(&context).await;
- let caps = derive_capabilities(request, &attempt, task_type);
+ let caps = derive_capabilities(
+ request,
+ &attempt,
+ task_type,
+ self.config.efficient_supports_attachments,
+ );
let signals = self.gather(&context, &caps).await;
let route = decide::decide(&caps, &signals, self.config.confirmed_min_clean_tail());
if route == Route::Capable {
@@ -310,7 +315,7 @@ impl VgrClassifier {
.as_ref()
.is_some_and(|switch| switch.is_engaged())
&& !self.breaker.is_open()
- && (self.config.efficient_supports_images || !request_has_image(request))
+ && (self.config.efficient_supports_attachments || !request_has_image(request))
}
fn escalate(
diff --git a/crates/libsy/src/algorithms/vgr/tests.rs b/crates/libsy/src/algorithms/vgr/tests.rs
index e414b2a24..8bc0c21e9 100644
--- a/crates/libsy/src/algorithms/vgr/tests.rs
+++ b/crates/libsy/src/algorithms/vgr/tests.rs
@@ -41,7 +41,7 @@ pub(super) fn result(id: &str, text: &str) -> Message {
}
fn branch(request: &Request, attempt: &str, task_type: Option<TaskType>) -> Branch {
- derive_capabilities(request, attempt, task_type).branch
+ derive_capabilities(request, attempt, task_type, false).branch
}
#[test]
@@ -223,7 +223,7 @@ fn trajectory_labels_agree_with_tool_failure_counts() {
})],
),
]);
- let caps = derive_capabilities(&session, "checked", Some(TaskType::Agentic));
+ let caps = derive_capabilities(&session, "checked", Some(TaskType::Agentic), false);
assert_eq!(caps.tools.unwrap().errors, i32::from(failed), "{output}");
let view = caps.transcript.unwrap();
let label = if failed { "tool error" } else { "tool result" };
@@ -243,7 +243,7 @@ fn the_agentic_view_keeps_the_task_and_redacts_the_trajectory() {
call("c1"),
result("c1", "Authorization: Bearer abcdefghijklmnopqrstuvwxyz"),
]);
- let caps = derive_capabilities(&session, "rotated", None);
+ let caps = derive_capabilities(&session, "rotated", None, false);
let view = caps.transcript.unwrap_or_default();
assert_eq!(caps.branch, Branch::Agentic);
assert!(view.starts_with("USER TASK AND UPDATES:\n[user task] rotate the key"));
diff --git a/crates/switchyard-runner/src/algorithm.rs b/crates/switchyard-runner/src/algorithm.rs
index 6a0361633..5f938c0fd 100644
--- a/crates/switchyard-runner/src/algorithm.rs
+++ b/crates/switchyard-runner/src/algorithm.rs
@@ -560,6 +560,9 @@ pub struct VgrRouteConfig {
/// Holds escalations across later user turns.
#[serde(default)]
pub latch_escalation: bool,
+ /// Lets the efficient tier attempt requests that contain attachments.
+ #[serde(default)]
+ pub efficient_supports_attachments: bool,
}
#[derive(Clone, Debug, Default, Deserialize)]
@@ -2142,6 +2145,7 @@ fn build_vgr(
runtime.agentic_handoff = config.agentic_handoff;
runtime.compact_handoff = config.compact_handoff;
runtime.latch_escalation = config.latch_escalation;
+ runtime.efficient_supports_attachments = config.efficient_supports_attachments;
runtime.efficient_turn_budget = config
.efficient_turn_budget_seconds
.map(|seconds| vgr_duration(route_name, "efficient_turn_budget_seconds", seconds))
diff --git a/crates/switchyard-server/tests/server.rs b/crates/switchyard-server/tests/server.rs
index fa703f167..44b0933ca 100644
--- a/crates/switchyard-server/tests/server.rs
+++ b/crates/switchyard-server/tests/server.rs
@@ -6536,3 +6536,59 @@ task_typing = false
}
Ok(())
}
+
+#[tokio::test]
+async fn vgr_image_requests_stay_on_the_efficient_tier_when_configured() -> TestResult {
+ let upstream = MockUpstream::start().await?;
+ for (configured, served) in [
+ ("", "model/vgr-capable"),
+ (
+ "efficient_supports_attachments = true",
+ "model/vgr-efficient",
+ ),
+ ] {
+ let app = build_switchyard_router(load_test_config(&format!(
+ r#"
+schema_version = 1
+[llm_clients.primary]
+format = "openai_chat"
+base_url = "{}"
+[targets]
+efficient = {{ id = "model/vgr-efficient", llm_client = "primary" }}
+capable = {{ id = "model/vgr-capable", llm_client = "primary" }}
+judge = {{ id = "model/vgr-judge", llm_client = "primary" }}
+[routes.vgr]
+id = "switchyard/vgr"
+type = "vgr"
+efficient_target = "efficient"
+capable_target = "capable"
+judge_target = "judge"
+mode = "evaluate"
+task_typing = false
+bounded_efficient = false
+{configured}
+"#,
+ upstream.base_url
+ ))?);
+ let response = send(
+ &app,
+ "POST",
+ "/v1/chat/completions",
+ Some(json!({
+ "model": "switchyard/vgr",
+ "messages": [{"role": "user", "content": [
+ {"type": "text", "text": "answer the question"},
+ {"type": "image_url", "image_url": {"url": "https://example.test/image.png"}}
+ ]}]
+ })),
+ )
+ .await?;
+ assert_eq!(response.status, StatusCode::OK, "{}", response.text()?);
+ assert_eq!(
+ response.headers.get("x-model-router-selected-model"),
+ Some(&HeaderValue::from_str(served)?),
+ "{configured}"
+ );
+ }
+ Ok(())
+}
diff --git a/docs/routing_algorithms/vgr_routing.md b/docs/routing_algorithms/vgr_routing.md
index d8140bc4d..34abc9f92 100644
--- a/docs/routing_algorithms/vgr_routing.md
+++ b/docs/routing_algorithms/vgr_routing.md
@@ -208,6 +208,12 @@ answer. That call receives the original request without the capable handoff note
Fallback is disabled by the kill switch, an open efficient circuit breaker, or an
image request the efficient tier cannot serve.
+By default the efficient tier does not serve requests that contain images. Set
+`efficient_supports_attachments = true` on the VGR route to let it attempt requests
+with attachments. This setting permits attempts; it does not guarantee that the
+efficient model understands every attachment format. The judge reads only the
+surrounding text.
+
## Serving modes
- `off` skips candidate generation and serves the capable tier. This is the default.