From 526096f1989e513e6516d9102ef125eb3e1c4e56 Mon Sep 17 00:00:00 2001 From: Alex Fournier Date: Mon, 28 Sep 2026 18:09:49 -0700 Subject: [PATCH] refactor(runner): group route execution state Signed-off-by: Alex Fournier --- crates/switchyard-runner/src/route.rs | 50 ++++++++++++++++----------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/crates/switchyard-runner/src/route.rs b/crates/switchyard-runner/src/route.rs index 9d177c768..5fbd1162d 100644 --- a/crates/switchyard-runner/src/route.rs +++ b/crates/switchyard-runner/src/route.rs @@ -105,21 +105,26 @@ impl RunnerError { } } -/// A configured algorithm and the per-target clients its calls resolve through. -pub struct Route { +// State that can select or call a model during one route execution. +struct ExecutionLane { algorithm: Arc, // Resolves each offloaded call to the client configured for the target the algorithm // selected. A route is a synthetic model with no upstream of its own, so this is a // per-target lookup, never one client serving the whole route. clients: ClientRouter, - caller_auth: Option, - capabilities: ModelCapabilities, anthropic_auxiliary_target: Option, responses_auxiliary_target: Option, decision_targets: Vec, models: Arc, } +/// A configured algorithm and the per-target clients its calls resolve through. +pub struct Route { + lane: ExecutionLane, + caller_auth: Option, + capabilities: ModelCapabilities, +} + /// The selected model and untouched response produced by a route execution. pub struct RunOutput { pub selected_model: ModelId, @@ -140,20 +145,22 @@ impl Route { models: RuntimeModels, ) -> Self { Self { - algorithm, - clients, + lane: ExecutionLane { + algorithm, + clients, + anthropic_auxiliary_target, + responses_auxiliary_target, + decision_targets, + models: Arc::new(models), + }, caller_auth, capabilities, - anthropic_auxiliary_target, - responses_auxiliary_target, - decision_targets, - models: Arc::new(models), } } /// Returns the configured libsy algorithm name. pub fn algorithm_name(&self) -> &str { - self.algorithm.name() + self.lane.algorithm.name() } /// Returns model-list capability metadata. @@ -168,7 +175,8 @@ impl Route { /// Resolves a selected model to this route's non-secret target metadata. pub(crate) fn decision_target(&self, model: &ModelId) -> Option { - self.decision_targets + self.lane + .decision_targets .iter() .find(|target| target.model == *model) .cloned() @@ -176,7 +184,7 @@ impl Route { /// Returns the models grouped for one algorithm execution. pub fn models(&self) -> &RuntimeModels { - &self.models + &self.lane.models } /// Rejects a caller format incompatible with forwarded credentials. @@ -196,10 +204,10 @@ impl Route { observer: Option, ) -> Result { let (selected_model, response) = switchyard_llm_client::run( - Arc::clone(&self.algorithm), - self.clients.clone(), + Arc::clone(&self.lane.algorithm), + self.lane.clients.clone(), request, - Arc::clone(&self.models), + Arc::clone(&self.lane.models), observer, ) .await?; @@ -212,10 +220,10 @@ impl Route { /// Completes routing-time calls without serving a post-routing completion. pub async fn decide(&self, request: Request) -> Result { switchyard_llm_client::decide( - Arc::clone(&self.algorithm), - self.clients.clone(), + Arc::clone(&self.lane.algorithm), + self.lane.clients.clone(), request, - Arc::clone(&self.models), + Arc::clone(&self.lane.models), ) .await .map_err(Into::into) @@ -228,9 +236,9 @@ impl Route { operation: AuxiliaryOperation, ) -> Result { let target = match operation { - AuxiliaryOperation::AnthropicCountTokens => &self.anthropic_auxiliary_target, + AuxiliaryOperation::AnthropicCountTokens => &self.lane.anthropic_auxiliary_target, AuxiliaryOperation::ResponsesInputTokens | AuxiliaryOperation::ResponsesCompact => { - &self.responses_auxiliary_target + &self.lane.responses_auxiliary_target } } .as_ref()