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

chore: Tidy up the imports (#231)

Graham Kingdd60d79d603a
diff --git a/Cargo.lock b/Cargo.lock
index 71f7048b8..3544d5b95 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2092,6 +2092,7 @@ dependencies = [
"serde_json",
"switchyard-libsy",
"switchyard-llm-client",
+ "switchyard-protocol",
"switchyard-translation",
"tempfile",
"tokio",
diff --git a/crates/libsy/examples/ensemble.rs b/crates/libsy/examples/ensemble.rs
index d069e188b..7383eec83 100644
--- a/crates/libsy/examples/ensemble.rs
+++ b/crates/libsy/examples/ensemble.rs
@@ -24,12 +24,12 @@ use std::sync::Arc;
use async_trait::async_trait;
use parking_lot::Mutex;
-use switchyard_libsy::{
- Algorithm, Context, Decision, Driver, LibsyError, LlmTarget, LlmTargetSet, Request, Response,
- Result, RoutedLlmClient,
-};
+use switchyard_libsy::{Algorithm, Driver, LibsyError, LlmTarget, LlmTargetSet, Result};
use switchyard_llm_client::{Backend, HttpBackendConfig, ModelConfig, TranslatingLlmClient};
-use switchyard_protocol::{completion_text, prompt_text, text_request};
+use switchyard_protocol::{
+ completion_text, prompt_text, text_request, Context, Decision, Request, Response,
+ RoutedLlmClient,
+};
const CANDIDATE_MODELS: [&str; 3] = [
"nvidia/qwen/qwen3.6-27b",
@@ -467,8 +467,11 @@ async fn main() -> Result<()> {
#[cfg(test)]
mod tests {
use super::*;
- use switchyard_libsy::{LlmResponse, LlmTarget, Response, RoutedLlmClient, Signals};
- use switchyard_protocol::text_response;
+ use switchyard_libsy::LlmTarget;
+ use switchyard_protocol::{
+ completion_text, prompt_text, text_request, text_response, LlmResponse, Response,
+ RoutedLlmClient, Signals,
+ };
/// Mock client that answers candidate calls with `answer from {model}` and,
/// for the judge model, returns the 1-based number of the response whose
diff --git a/crates/libsy/examples/research_agent.rs b/crates/libsy/examples/research_agent.rs
index 6e17dff62..5fb5f6d65 100644
--- a/crates/libsy/examples/research_agent.rs
+++ b/crates/libsy/examples/research_agent.rs
@@ -14,12 +14,13 @@
use std::sync::Arc;
use async_trait::async_trait;
-use switchyard_libsy::algorithms::{LlmTaskClassifier, TaskClassifierConfig};
use switchyard_libsy::{
- Algorithm, Context, Decision, LibsyError, LlmResponse, LlmTarget, LlmTargetSet, Request,
- Response, Result, RoutedLlmClient,
+ Algorithm, LibsyError, LlmTarget, LlmTargetSet, LlmTaskClassifier, Result, TaskClassifierConfig,
+};
+use switchyard_protocol::{
+ completion_text, text_request, text_response, Context, Decision, LlmResponse, Request,
+ Response, RoutedLlmClient,
};
-use switchyard_protocol::{completion_text, text_request, text_response};
const CLASSIFIER: &str = "classifier/model";
const STRONG: &str = "strong/model";
diff --git a/crates/libsy/examples/research_agent_core.rs b/crates/libsy/examples/research_agent_core.rs
index 7f12b58e3..872156711 100644
--- a/crates/libsy/examples/research_agent_core.rs
+++ b/crates/libsy/examples/research_agent_core.rs
@@ -11,12 +11,13 @@
use std::sync::Arc;
-use switchyard_libsy::algorithms::{LlmTaskClassifier, TaskClassifierConfig};
use switchyard_libsy::{
- Algorithm, Context, Decision, LibsyError, LlmResponse, LlmTarget, LlmTargetSet, Request,
- Response, Result, Step,
+ Algorithm, LibsyError, LlmTarget, LlmTargetSet, LlmTaskClassifier, Result, Step,
+ TaskClassifierConfig,
+};
+use switchyard_protocol::{
+ completion_text, text_request, text_response, Context, Decision, LlmResponse, Request, Response,
};
-use switchyard_protocol::{completion_text, text_request, text_response};
use tokio_stream::StreamExt;
const CLASSIFIER: &str = "classifier/model";
diff --git a/crates/libsy/examples/streaming_agent.rs b/crates/libsy/examples/streaming_agent.rs
index f39692ca7..6cf723748 100644
--- a/crates/libsy/examples/streaming_agent.rs
+++ b/crates/libsy/examples/streaming_agent.rs
@@ -16,12 +16,11 @@ use std::io::Write;
use std::sync::Arc;
use futures::StreamExt;
-use switchyard_libsy::algorithms::Random;
-use switchyard_libsy::{
- Algorithm, Context, LibsyError, LlmResponse, LlmResponseChunk, LlmResponseStream, LlmTarget,
- LlmTargetSet, Request, Response, Result, Step,
+use switchyard_libsy::{Algorithm, LibsyError, LlmTarget, LlmTargetSet, Random, Result, Step};
+use switchyard_protocol::{
+ completion_text, text_request, Context, LlmResponse, LlmResponseChunk, LlmResponseStream,
+ Request, Response,
};
-use switchyard_protocol::{completion_text, text_request};
/// The "real" model call the agent makes to fulfill an offloaded promise: a response
/// whose body is a live token stream (`MessageStart`, one `TextDelta` per token,
diff --git a/crates/libsy/src/algorithms.rs b/crates/libsy/src/algorithms.rs
index b5cb3834e..c95ede17c 100644
--- a/crates/libsy/src/algorithms.rs
+++ b/crates/libsy/src/algorithms.rs
@@ -3,26 +3,16 @@
//! Concrete algorithms and the interfaces for building them.
//!
-//! Reach for them by name — `use switchyard_libsy::algorithms::Random` — rather than through the
-//! per-algorithm submodules.
+//! Everything public here is re-exported at the crate root; reach for it by name —
+//! `use switchyard_libsy::Random`.
-mod fall_through;
+pub mod fall_through;
pub mod llm_class;
pub mod noop;
pub mod passthrough;
pub mod rand;
pub mod stage;
-pub(crate) use fall_through::{DefaultTarget, FallThrough};
-pub use llm_class::{EscalationJudgeConfig, LlmTaskClassifier, TaskClassifierConfig};
-pub use noop::{Noop, NoopDecision};
-pub use passthrough::{Passthrough, PassthroughDecision};
-pub use rand::{Random, RandomClassifier, RandomDecision};
-pub use stage::{LlmFallback, StageRouter, StageRouterConfig};
-pub use util::{
- append_note, AffinityRouter, SubagentOverride, SystemPromptProcessor, TargetPrompts,
-};
-
pub mod util;
#[cfg(test)]
diff --git a/crates/libsy/src/algorithms/fall_through.rs b/crates/libsy/src/algorithms/fall_through.rs
index 489587300..6cd01d7b9 100644
--- a/crates/libsy/src/algorithms/fall_through.rs
+++ b/crates/libsy/src/algorithms/fall_through.rs
@@ -22,12 +22,11 @@ use async_trait::async_trait;
use parking_lot::Mutex;
use tokio::sync::Mutex as AsyncMutex;
-use crate::core::algorithm::{call_llm_with_overflow_fallback, exclude_evicted, SessionEvictions};
-use crate::core::{Classification, Classifier, Event, Processor, Score};
-use crate::{
- Algorithm, Context, Decision, Driver, LibsyError, LlmTarget, LlmTargetSet, Request, Response,
- Result, RoutedLlmClient,
-};
+use crate::core::algorithm::{self, Algorithm, Driver, LlmTarget, LlmTargetSet, SessionEvictions};
+use crate::core::classifier::{Classification, Classifier, Score};
+use crate::core::processor::{Event, Processor};
+use crate::{LibsyError, Result};
+use switchyard_protocol::{Context, Decision, Request, Response, RoutedLlmClient};
type SessionStates<S> = Mutex<HashMap<String, Arc<AsyncMutex<S>>>>;
@@ -176,7 +175,7 @@ where
let mut request = request;
let session = session_id(&request);
let mut ctx = ctx;
- exclude_evicted(
+ algorithm::exclude_evicted(
&mut ctx,
&self.targets,
&self.session_evictions,
@@ -202,7 +201,7 @@ where
match served {
Some(response) => Ok(response),
None => {
- call_llm_with_overflow_fallback(
+ algorithm::call_llm_with_overflow_fallback(
ctx,
&driver,
&self.targets,
@@ -250,7 +249,7 @@ where
ctx: &Context,
driver: &Driver,
request: &mut Request,
- ) -> Result<(crate::LlmTarget, Arc<dyn Decision>, Option<Response>)> {
+ ) -> Result<(LlmTarget, Arc<dyn Decision>, Option<Response>)> {
// 1. Processor chain accumulates request-side facts into the composition's state.
for processor in &self.processors {
processor.process(state, Event::Request(request)).await?;
@@ -352,15 +351,15 @@ where
#[cfg(test)]
mod tests {
use super::*;
- use crate::algorithms::{append_note, SystemPromptProcessor, TargetPrompts};
- use crate::core::Classification;
+ use crate::algorithms::util::prompts;
+ use crate::core::classifier::Classification;
+ use crate::{SystemPromptProcessor, TargetPrompts};
use switchyard_protocol::{
- completion_text, text_request, text_response, LlmRequest, Message, Metadata, Role,
+ completion_text, text_request, text_response, LlmClientError, LlmRequest, LlmResponse,
+ Message, Metadata, Role,
};
- use crate::{LlmClientError, LlmResponse, LlmTarget, RoutedLlmClient};
-
#[derive(Debug, thiserror::Error)]
#[error("{0}")]
struct TestError(&'static str);
@@ -687,7 +686,7 @@ mod tests {
impl Processor for Noting {
async fn process(&self, _state: &mut (), event: Event<'_>) -> Result<()> {
if let Event::Decision { request, .. } = event {
- append_note(request, NOTE);
+ prompts::append_note(request, NOTE);
}
Ok(())
}
diff --git a/crates/libsy/src/algorithms/llm_class.rs b/crates/libsy/src/algorithms/llm_class.rs
index 64bda5984..1b2f1a204 100644
--- a/crates/libsy/src/algorithms/llm_class.rs
+++ b/crates/libsy/src/algorithms/llm_class.rs
@@ -13,16 +13,16 @@ use async_trait::async_trait;
use serde::Deserialize;
use switchyard_protocol::{LlmRequest, Message, OutputParams, Role, SimpleDecision};
-use super::util::escalation::{build_judge, EscalationJudge, EscalationPolicy};
-pub use super::util::EscalationJudgeConfig;
-use super::util::{
- load_judge_config, AffinityRouter, Judge, JudgeClassifier, JudgeConfig, JudgePolicy,
-};
-use super::{DefaultTarget, FallThrough};
-use crate::{
- AggLlmResponse, Algorithm, Classification, Classifier, Context, Driver, LibsyError,
- LlmResponse, LlmTarget, LlmTargetSet, Request, Response, Result, RoutedLlmClient, Score, State,
- StateValue,
+use super::fall_through::{DefaultTarget, FallThrough};
+use super::util::affinity::AffinityRouter;
+use super::util::escalation::{self, EscalationJudge, EscalationJudgeConfig, EscalationPolicy};
+use super::util::llm_judge::{self, Judge, JudgeClassifier, JudgeConfig, JudgePolicy};
+use crate::core::algorithm::{Algorithm, Driver, LlmTarget, LlmTargetSet};
+use crate::core::classifier::{Classification, Classifier, Score};
+use crate::core::state::{State, StateValue};
+use crate::{LibsyError, Result};
+use switchyard_protocol::{
+ AggLlmResponse, Context, LlmResponse, Request, Response, RoutedLlmClient,
};
const PROMPT_TEMPLATE: &str = include_str!("../prompts/capability-classifier/prompt.md");
@@ -484,7 +484,7 @@ impl LlmTaskClassifier {
let efficient_name = efficient_target.semantic_name.clone();
let confirmations = config.confirmations;
let esc = Arc::new(EscalationClassifier {
- judge: build_judge(judge_target, capable_name, efficient_name, config)?,
+ judge: escalation::build_judge(judge_target, capable_name, efficient_name, config)?,
capable: capable_target.clone(),
efficient: efficient_target.clone(),
confirmations,
@@ -501,7 +501,7 @@ impl LlmTaskClassifier {
/// Loads the judge configuration from the packaged prompt and schema.
fn load_judge_config() -> Result<JudgeConfig> {
- load_judge_config(PROMPT_TEMPLATE, SCHEMA_TEMPLATE)
+ llm_judge::load_judge_config(PROMPT_TEMPLATE, SCHEMA_TEMPLATE)
}
}
@@ -573,9 +573,12 @@ mod tests {
use serde_json::Value;
use super::*;
- use switchyard_protocol::{completion_text, text_response, LlmClientError, Metadata};
+ use switchyard_protocol::{
+ completion_text, text_request, text_response, LlmClientError, Metadata,
+ };
- use crate::{Algorithm, Context, LlmResponse, Response, RoutedLlmClient};
+ use crate::core::algorithm::Algorithm;
+ use switchyard_protocol::{Context, LlmResponse, Response, RoutedLlmClient};
const TEST_THRESHOLD: f64 = 0.5;
@@ -637,7 +640,7 @@ mod tests {
&self,
_ctx: Context,
request: Request,
- decision: Arc<dyn crate::Decision>,
+ decision: Arc<dyn Decision>,
) -> std::result::Result<Response, LlmClientError> {
let model = decision.selected_model().to_string();
self.calls.lock().push(model.clone());
@@ -661,7 +664,7 @@ mod tests {
&self,
_ctx: Context,
request: Request,
- decision: Arc<dyn crate::Decision>,
+ decision: Arc<dyn Decision>,
) -> std::result::Result<Response, LlmClientError> {
let model = decision.selected_model().to_string();
if model == "judge" {
@@ -691,10 +694,7 @@ mod tests {
fn classify_request() -> Request {
Request {
- llm_request: switchyard_protocol::text_request(
- Some("auto".to_string()),
- "classify this task",
- ),
+ llm_request: text_request(Some("auto".to_string()), "classify this task"),
raw_request: None,
metadata: None,
}
@@ -1127,7 +1127,7 @@ mod tests {
use switchyard_protocol::LlmClientError as ClientError;
- use crate::Decision;
+ use switchyard_protocol::Decision;
/// Serves each call with the next queued reply.
struct QueuedClient {
diff --git a/crates/libsy/src/algorithms/noop.rs b/crates/libsy/src/algorithms/noop.rs
index 389a1e72a..376c501a8 100644
--- a/crates/libsy/src/algorithms/noop.rs
+++ b/crates/libsy/src/algorithms/noop.rs
@@ -10,7 +10,9 @@ use switchyard_protocol::{
AggLlmResponse, ContentBlock, LlmResponse, Request, Response, ResponseOutput, Role, StopReason,
};
-use crate::{Algorithm, Context, Decision, Driver, Result};
+use crate::core::algorithm::{Algorithm, Driver};
+use crate::Result;
+use switchyard_protocol::{Context, Decision};
/// A routing algorithm that does not route. It returns a hard-coded response.
pub struct Noop {}
diff --git a/crates/libsy/src/algorithms/passthrough.rs b/crates/libsy/src/algorithms/passthrough.rs
index 35022ecd6..4615b4a34 100644
--- a/crates/libsy/src/algorithms/passthrough.rs
+++ b/crates/libsy/src/algorithms/passthrough.rs
@@ -9,7 +9,9 @@ use std::sync::Arc;
use switchyard_protocol::{Request, Response};
-use crate::{Algorithm, Context, Decision, Driver, LlmTarget, Result, RoutedLlmClient};
+use crate::core::algorithm::{Algorithm, Driver, LlmTarget};
+use crate::Result;
+use switchyard_protocol::{Context, Decision, RoutedLlmClient};
/// See module comment
pub struct Passthrough {
@@ -73,10 +75,12 @@ impl Algorithm for Passthrough {
mod tests {
use std::sync::Arc;
- use crate::{
- Algorithm, Context, Decision, LlmResponse, LlmTarget, Request, Response, RoutedLlmClient,
+ use super::Passthrough;
+ use crate::core::algorithm::{Algorithm, LlmTarget};
+ use switchyard_protocol::{
+ completion_text, text_request, text_response, Context, Decision, LlmResponse, Request,
+ Response, RoutedLlmClient,
};
- use switchyard_protocol::{completion_text, text_request, text_response};
/// Echoes the selected target so tests can inspect which target was called.
/// TODO: Duplicated from rand.rs
@@ -98,14 +102,14 @@ mod tests {
}
#[tokio::test]
- async fn test_passthrough() -> crate::error::Result<()> {
+ async fn test_passthrough() -> crate::Result<()> {
const MODEL_ID: &str = "testing/passthrough";
let request = Request {
llm_request: text_request(Some("auto".to_string()), "hi"),
raw_request: None,
metadata: None,
};
- let algorithm: Arc<dyn Algorithm> = Arc::new(super::Passthrough::new(LlmTarget {
+ let algorithm: Arc<dyn Algorithm> = Arc::new(Passthrough::new(LlmTarget {
semantic_name: MODEL_ID.to_string(),
llm_client: Some(Arc::new(EchoClient)),
}));
diff --git a/crates/libsy/src/algorithms/rand.rs b/crates/libsy/src/algorithms/rand.rs
index e7adbd2f2..18f93985e 100644
--- a/crates/libsy/src/algorithms/rand.rs
+++ b/crates/libsy/src/algorithms/rand.rs
@@ -16,10 +16,10 @@ use rand::rngs::StdRng;
use rand::SeedableRng;
use crate::algorithms::fall_through::{FallThrough, FallThroughDecision};
-use crate::{
- Algorithm, Classification, Classifier, Context, Driver, LibsyError, LlmTargetSet, Request,
- Response, Result, RoutedLlmClient, Score,
-};
+use crate::core::algorithm::{Algorithm, Driver, LlmTargetSet};
+use crate::core::classifier::{Classification, Classifier, Score};
+use crate::{LibsyError, Result};
+use switchyard_protocol::{Context, Request, Response, RoutedLlmClient};
/// Compatibility name for the decision produced by [`Random`].
pub type RandomDecision = FallThroughDecision;
@@ -183,8 +183,10 @@ mod tests {
use switchyard_protocol::{completion_text, text_request, text_response, Metadata};
- use crate::algorithms::AffinityRouter;
- use crate::{Decision, LlmResponse, LlmTarget, Request, RoutedLlmClient, Signals};
+ use crate::algorithms::util::affinity::AffinityRouter;
+ use crate::core::algorithm::LlmTarget;
+ use crate::DriverError;
+ use switchyard_protocol::{Decision, LlmResponse, Request, RoutedLlmClient, Signals};
/// Echoes the selected target so tests can inspect which target was called.
struct EchoClient;
@@ -454,7 +456,7 @@ mod tests {
.as_any()
.downcast_ref::<RandomDecision>()
.ok_or_else(|| {
- LibsyError::from(crate::DriverError::TypeMismatch {
+ LibsyError::from(DriverError::TypeMismatch {
expected: "RandomDecision",
})
})?;
diff --git a/crates/libsy/src/algorithms/stage.rs b/crates/libsy/src/algorithms/stage.rs
index da2a69f8f..80734f2f9 100644
--- a/crates/libsy/src/algorithms/stage.rs
+++ b/crates/libsy/src/algorithms/stage.rs
@@ -19,18 +19,19 @@ use std::sync::Arc;
use async_trait::async_trait;
-use super::llm_class::TaskClassifierConfig;
+use super::fall_through::{DefaultTarget, FallThrough};
+use super::llm_class::{LlmTaskClassifier, TaskClassifierConfig};
use super::util::prompts::{SystemPromptProcessor, TargetPrompts};
use super::util::stage::{
record_decision_source, DecisionSource, HandoffNoteConfig, PickerMode, StageClassifier,
StageTargets,
};
-use super::util::tool_signals::ToolSignalProcessor;
-use super::{DefaultTarget, FallThrough, LlmTaskClassifier};
-use crate::{
- Algorithm, Classification, Classifier, Context, Driver, LibsyError, LlmTarget, LlmTargetSet,
- Request, Response, Result, RoutedLlmClient, State, DEFAULT_RECENT_WINDOW,
-};
+use super::util::tool_signals::{ToolSignalProcessor, DEFAULT_RECENT_WINDOW};
+use crate::core::algorithm::{Algorithm, Driver, LlmTarget, LlmTargetSet};
+use crate::core::classifier::{Classification, Classifier};
+use crate::core::state::State;
+use crate::{LibsyError, Result};
+use switchyard_protocol::{Context, Request, Response, RoutedLlmClient};
/// Telemetry name for a router this module assembles.
const STAGE_ROUTER: &str = "stage_router";
@@ -232,9 +233,12 @@ mod tests {
};
use super::*;
- use crate::{
- Algorithm, Context, Decision, LlmResponse, LlmTarget, Metadata, Response, RoutedLlmClient,
- StateValue,
+ use crate::algorithms::util::stage::DECISION_SOURCE_KEY;
+ use crate::core::algorithm::{Algorithm, LlmTarget};
+ use crate::core::classifier::Score;
+ use crate::core::state::StateValue;
+ use switchyard_protocol::{
+ Context, Decision, LlmResponse, Metadata, Response, RoutedLlmClient,
};
fn tier_target(name: &str) -> LlmTarget {
@@ -256,7 +260,7 @@ mod tests {
_driver: Option<&Driver>,
) -> Result<(Classification, Option<Response>)> {
Ok((
- Classification::Scores(vec![crate::Score {
+ Classification::Scores(vec![Score {
target: self.0.to_string(),
confidence: 1.0,
}]),
@@ -289,12 +293,10 @@ mod tests {
stamp
.score(&mut state, &mut Request::default(), None)
.await?;
- Ok(
- match state.extra.get(crate::stage_router::DECISION_SOURCE_KEY) {
- Some(StateValue::String(source)) => Some(source.clone()),
- _ => None,
- },
- )
+ Ok(match state.extra.get(DECISION_SOURCE_KEY) {
+ Some(StateValue::String(source)) => Some(source.clone()),
+ _ => None,
+ })
}
#[tokio::test]
diff --git a/crates/libsy/src/algorithms/subagent_affinity_tests.rs b/crates/libsy/src/algorithms/subagent_affinity_tests.rs
index 4d0395c6d..979d0cd83 100644
--- a/crates/libsy/src/algorithms/subagent_affinity_tests.rs
+++ b/crates/libsy/src/algorithms/subagent_affinity_tests.rs
@@ -13,12 +13,15 @@ use std::sync::Arc;
use async_trait::async_trait;
use super::fall_through::FallThrough;
-use super::{AffinityRouter, SubagentOverride};
-use crate::{
- Algorithm, Classification, Classifier, Context, Decision, Driver, LlmResponse, LlmTarget,
- LlmTargetSet, Metadata, Request, Response, Result, RoutedLlmClient, Score,
+use super::util::affinity::AffinityRouter;
+use super::util::subagent::SubagentOverride;
+use crate::core::algorithm::{Algorithm, Driver, LlmTarget, LlmTargetSet};
+use crate::core::classifier::{Classification, Classifier, Score};
+use crate::Result;
+use switchyard_protocol::{
+ completion_text, text_request, text_response, Context, Decision, LlmResponse, Metadata,
+ Request, Response, RoutedLlmClient,
};
-use switchyard_protocol::{completion_text, text_request, text_response};
/// A client that echoes the routed target name back as the completion.
struct EchoClient;
diff --git a/crates/libsy/src/algorithms/util.rs b/crates/libsy/src/algorithms/util.rs
index 131b72621..2e39ecde9 100644
--- a/crates/libsy/src/algorithms/util.rs
+++ b/crates/libsy/src/algorithms/util.rs
@@ -1,16 +1,10 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
-mod affinity;
+pub mod affinity;
pub mod escalation;
-mod llm_judge;
+pub(crate) mod llm_judge;
pub(crate) mod prompts;
pub(crate) mod stage;
-mod subagent;
+pub mod subagent;
pub(crate) mod tool_signals;
-
-pub use affinity::AffinityRouter;
-pub use escalation::EscalationJudgeConfig;
-pub(crate) use llm_judge::{load_judge_config, Judge, JudgeClassifier, JudgeConfig, JudgePolicy};
-pub use prompts::{append_note, SystemPromptProcessor, TargetPrompts};
-pub use subagent::SubagentOverride;
diff --git a/crates/libsy/src/algorithms/util/affinity.rs b/crates/libsy/src/algorithms/util/affinity.rs
index 82283d041..66e6bad1e 100644
--- a/crates/libsy/src/algorithms/util/affinity.rs
+++ b/crates/libsy/src/algorithms/util/affinity.rs
@@ -24,7 +24,9 @@ use async_trait::async_trait;
use parking_lot::Mutex;
use switchyard_protocol::{Request, Role};
-use crate::{Classification, Classifier, Event, Processor, Score};
+use crate::core::algorithm::Driver;
+use crate::core::classifier::{Classification, Classifier, Score};
+use crate::core::processor::{Event, Processor};
/// Upper bound on retained assignments, keeping the process-local map from growing
/// without limit; the oldest entry is evicted once the bound is reached.
@@ -179,8 +181,8 @@ where
&self,
_state: &mut S,
request: &mut Request,
- _driver: Option<&crate::Driver>,
- ) -> crate::Result<(Classification, Option<crate::Response>)> {
+ _driver: Option<&Driver>,
+ ) -> crate::Result<(Classification, Option<switchyard_protocol::Response>)> {
let Some(key) = self.affinity_key(request) else {
return Ok((Classification::Scores(Vec::new()), None));
};
diff --git a/crates/libsy/src/algorithms/util/escalation.rs b/crates/libsy/src/algorithms/util/escalation.rs
index f71a8054c..81e82d412 100644
--- a/crates/libsy/src/algorithms/util/escalation.rs
+++ b/crates/libsy/src/algorithms/util/escalation.rs
@@ -10,8 +10,12 @@
use serde::Deserialize;
use switchyard_protocol::{ContentBlock, LlmRequest, Message, OutputParams, Role};
-use super::{load_judge_config, Judge, JudgeClassifier, JudgeConfig, JudgePolicy};
-use crate::{Classification, LlmTarget, Request, Result, Score, State};
+use super::llm_judge::{self, Judge, JudgeClassifier, JudgeConfig, JudgePolicy};
+use crate::core::algorithm::LlmTarget;
+use crate::core::classifier::{Classification, Score};
+use crate::core::state::State;
+use crate::{LibsyError, Result};
+use switchyard_protocol::Request;
const PROMPT_TEMPLATE: &str = include_str!("../../prompts/escalation/prompt.md");
const SCHEMA_TEMPLATE: &str = include_str!("../../prompts/escalation/schema.json");
@@ -62,7 +66,7 @@ pub struct EscalationJudgeConfig {
impl EscalationJudgeConfig {
/// Rejects settings that would leave the judge with nothing useful to read.
fn validate(&self) -> Result<()> {
- let reject = |message: String| Err(crate::LibsyError::AlgorithmError { message });
+ let reject = |message: String| Err(LibsyError::AlgorithmError { message });
if self.confirmations == 0 {
return reject("confirmations must be at least 1".to_string());
}
@@ -169,7 +173,7 @@ pub(crate) fn build_judge(
config: EscalationJudgeConfig,
) -> Result<JudgeClassifier<EscalationJudge, EscalationPolicy>> {
config.validate()?;
- let rubric = load_judge_config(PROMPT_TEMPLATE, SCHEMA_TEMPLATE)?;
+ let rubric = llm_judge::load_judge_config(PROMPT_TEMPLATE, SCHEMA_TEMPLATE)?;
Ok(JudgeClassifier::new(
EscalationJudge { rubric, config },
judge_target,
@@ -360,7 +364,7 @@ mod tests {
#[test]
fn judge_request_is_rubric_plus_summary_under_a_completion_cap() -> Result<()> {
let judge = EscalationJudge {
- rubric: load_judge_config(PROMPT_TEMPLATE, SCHEMA_TEMPLATE)?,
+ rubric: llm_judge::load_judge_config(PROMPT_TEMPLATE, SCHEMA_TEMPLATE)?,
config: EscalationJudgeConfig::default(),
};
diff --git a/crates/libsy/src/algorithms/util/llm_judge.rs b/crates/libsy/src/algorithms/util/llm_judge.rs
index 4fc594ae7..ec72566e2 100644
--- a/crates/libsy/src/algorithms/util/llm_judge.rs
+++ b/crates/libsy/src/algorithms/util/llm_judge.rs
@@ -14,10 +14,11 @@ use serde::de::DeserializeOwned;
use serde_json::Value;
use switchyard_protocol::{completion_text, AggLlmResponse};
-use crate::{
- Classification, Classifier, Context, Decision, Driver, LibsyError, LlmTarget, Request,
- Response, Result, State,
-};
+use crate::core::algorithm::{Driver, LlmTarget};
+use crate::core::classifier::{Classification, Classifier};
+use crate::core::state::State;
+use crate::{LibsyError, Result};
+use switchyard_protocol::{Context, Decision, Request, Response};
#[derive(Clone, Debug, Default)]
/// Prompt and structured-output contract for one judge.
@@ -223,7 +224,9 @@ mod tests {
use serde::Deserialize;
use switchyard_protocol::{text_request, text_response, ContentBlock, LlmClientError};
- use crate::{LlmResponse, LlmResponseChunk, Response, Score, Step};
+ use crate::core::algorithm::Step;
+ use crate::core::classifier::Score;
+ use switchyard_protocol::{LlmResponse, LlmResponseChunk, Response};
const VERDICT: &str = r#"{"ok":true}"#;
diff --git a/crates/libsy/src/algorithms/util/prompts.rs b/crates/libsy/src/algorithms/util/prompts.rs
index deb1c1b9d..b42d751f5 100644
--- a/crates/libsy/src/algorithms/util/prompts.rs
+++ b/crates/libsy/src/algorithms/util/prompts.rs
@@ -20,7 +20,8 @@ use std::collections::BTreeMap;
use async_trait::async_trait;
use switchyard_protocol::{ContentBlock, InstructionBlock, Message, Request, Role};
-use crate::{Event, Processor, Result};
+use crate::core::processor::{Event, Processor};
+use crate::Result;
/// Appends `note` to the request as conversation text.
///
@@ -191,7 +192,7 @@ mod tests {
/// A decision routed to `target`.
struct RoutedTo(&'static str);
- impl crate::Decision for RoutedTo {
+ impl switchyard_protocol::Decision for RoutedTo {
fn selected_model(&self) -> &str {
self.0
}
diff --git a/crates/libsy/src/algorithms/util/stage.rs b/crates/libsy/src/algorithms/util/stage.rs
index 3ed296cb1..495f2a7ad 100644
--- a/crates/libsy/src/algorithms/util/stage.rs
+++ b/crates/libsy/src/algorithms/util/stage.rs
@@ -22,10 +22,13 @@
use async_trait::async_trait;
use serde::Deserialize;
-use super::prompts::append_note;
-use crate::{
- Classification, Classifier, Driver, Request, Result, Score, State, StateValue, ToolSignals,
-};
+use super::prompts;
+use super::tool_signals::ToolSignals;
+use crate::core::algorithm::Driver;
+use crate::core::classifier::{Classification, Classifier, Score};
+use crate::core::state::{State, StateValue};
+use crate::Result;
+use switchyard_protocol::Request;
/// Turn depth below which stall signals stay quiet — early no-write turns are
/// normal exploration, not a stall.
@@ -468,7 +471,7 @@ impl StageClassifier {
return;
};
if let Some(note) = config.note_for(tier, source) {
- append_note(request, note);
+ prompts::append_note(request, note);
}
}
}
@@ -484,7 +487,7 @@ impl Classifier<State> for StageClassifier {
state: &mut State,
request: &mut Request,
_driver: Option<&Driver>,
- ) -> Result<(Classification, Option<crate::Response>)> {
+ ) -> Result<(Classification, Option<switchyard_protocol::Response>)> {
let tool_signals = &state.tool_signals;
let Some(signal) = tool_signals else {
// No tool activity yet — nothing to score, so the signals have no
@@ -524,7 +527,7 @@ impl Classifier<State> for StageClassifier {
mod tests {
use super::*;
use serde_json::json;
- use switchyard_protocol::{Metadata, Request, WireFormat};
+ use switchyard_protocol::{text_request, Metadata, Request, WireFormat};
fn signal_from(messages: serde_json::Value) -> ToolSignals {
let raw_request = Some(json!({"model": "m", "messages": messages}));
@@ -762,7 +765,7 @@ mod tests {
/// A one-user-turn request, the thing a note gets spliced into.
fn request() -> Request {
Request {
- llm_request: switchyard_protocol::text_request(Some("auto".to_string()), "hi"),
+ llm_request: text_request(Some("auto".to_string()), "hi"),
raw_request: None,
metadata: None,
}
diff --git a/crates/libsy/src/algorithms/util/subagent.rs b/crates/libsy/src/algorithms/util/subagent.rs
index b80543e5c..285ff782d 100644
--- a/crates/libsy/src/algorithms/util/subagent.rs
+++ b/crates/libsy/src/algorithms/util/subagent.rs
@@ -17,7 +17,10 @@
use async_trait::async_trait;
-use crate::{Classification, Classifier, Driver, Metadata, Request, Response, Result, Score};
+use crate::core::algorithm::Driver;
+use crate::core::classifier::{Classification, Classifier, Score};
+use crate::Result;
+use switchyard_protocol::{Metadata, Request, Response};
/// Scores a fixed worker target for delegated sub-agent work; abstains otherwise.
pub struct SubagentOverride {
@@ -72,7 +75,6 @@ where
mod tests {
use super::*;
use std::collections::BTreeMap;
-
use switchyard_protocol::text_request;
fn request(headers: &[(&str, &str)]) -> Request {
diff --git a/crates/libsy/src/algorithms/util/tool_signals.rs b/crates/libsy/src/algorithms/util/tool_signals.rs
index 969564d58..2bc6d1fd5 100644
--- a/crates/libsy/src/algorithms/util/tool_signals.rs
+++ b/crates/libsy/src/algorithms/util/tool_signals.rs
@@ -19,7 +19,8 @@ use switchyard_protocol::{ContentBlock, Request};
use crate::Result;
-use crate::{Event, Processor, State};
+use crate::core::processor::{Event, Processor};
+use crate::core::state::State;
// ─── severity constants ───────────────────────────────────────────────────────
diff --git a/crates/libsy/src/core.rs b/crates/libsy/src/core.rs
index e3499ae10..b5655269e 100644
--- a/crates/libsy/src/core.rs
+++ b/crates/libsy/src/core.rs
@@ -1,10 +1,9 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
-//! Core orchestration: the [`Algorithm`] trait and its [`Driver`], built on the
-//! type-erased promise-over-a-stream pump in [`driver`]. Its public items are
-//! re-exported at the crate root; algorithm implementations live in
-//! [`crate::algorithms`].
+//! Core orchestration: the [`Algorithm`](algorithm::Algorithm) trait and its
+//! [`Driver`](algorithm::Driver), built on the type-erased promise-over-a-stream
+//! pump in [`driver`]. Algorithm implementations live in [`crate::algorithms`].
mod driver;
@@ -12,8 +11,3 @@ pub mod algorithm;
pub mod classifier;
pub mod processor;
pub mod state;
-
-pub use algorithm::*;
-pub use classifier::*;
-pub use processor::*;
-pub use state::*;
diff --git a/crates/libsy/src/core/algorithm.rs b/crates/libsy/src/core/algorithm.rs
index 8f1bb877f..45e925801 100644
--- a/crates/libsy/src/core/algorithm.rs
+++ b/crates/libsy/src/core/algorithm.rs
@@ -21,9 +21,8 @@ use tracing::Instrument;
/// [`LlmRequest`] is the normalized request; [`AggLlmResponse`] is the buffered response;
/// [`LlmResponseChunk`] is one streaming event; [`LlmResponse`] is the streamed response
/// (a live [`LlmResponseStream`] or the terminal aggregate).
-pub use switchyard_protocol::{
- AggLlmResponse, Context, Decision, LlmClientError, LlmRequest, LlmResponse, LlmResponseChunk,
- LlmResponseStream, Metadata, Request, Response, RoutedLlmClient, Signals, Usage,
+use switchyard_protocol::{
+ Context, Decision, LlmClientError, Request, Response, RoutedLlmClient, Signals, Usage,
};
use super::driver::{DriverRequest, DriverStep, TypeErasedDriver};
@@ -786,7 +785,9 @@ pub trait Algorithm: Send + Sync + 'static {
mod tests {
use super::*;
use futures::StreamExt;
- use switchyard_protocol::{completion_text, text_request, text_response};
+ use switchyard_protocol::{
+ completion_text, text_request, text_response, LlmResponse, LlmResponseChunk,
+ };
#[derive(Debug, thiserror::Error)]
#[error("{0}")]
diff --git a/crates/libsy/src/core/classifier.rs b/crates/libsy/src/core/classifier.rs
index 863c5dedd..c417622eb 100644
--- a/crates/libsy/src/core/classifier.rs
+++ b/crates/libsy/src/core/classifier.rs
@@ -1,9 +1,10 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
-use crate::{Driver, LibsyError, Response, Result};
+use crate::core::algorithm::Driver;
+use crate::{LibsyError, Result};
use async_trait::async_trait;
-use switchyard_protocol::Request;
+use switchyard_protocol::{Request, Response};
/// One classifier's recommendation of a routing `target`, with a `[0.0, 1.0]` confidence.
#[derive(Debug, Clone, PartialEq)]
diff --git a/crates/libsy/src/core/driver.rs b/crates/libsy/src/core/driver.rs
index 9ae4b496e..10641ed1c 100644
--- a/crates/libsy/src/core/driver.rs
+++ b/crates/libsy/src/core/driver.rs
@@ -49,10 +49,11 @@
use std::{any::Any, sync::Arc};
-use crate::{Context, DriverError, LibsyError, Result};
+use crate::{DriverError, LibsyError, Result};
use parking_lot::Mutex;
use futures::{Stream, StreamExt};
+use switchyard_protocol::Context;
use tokio::sync::{mpsc, oneshot};
use tokio::time::{timeout, Duration};
use tokio_stream::wrappers::ReceiverStream;
diff --git a/crates/libsy/src/core/state.rs b/crates/libsy/src/core/state.rs
index b6be3e4ca..f35d4d73b 100644
--- a/crates/libsy/src/core/state.rs
+++ b/crates/libsy/src/core/state.rs
@@ -5,7 +5,7 @@
use std::collections::HashMap;
-use crate::ToolSignals;
+use crate::algorithms::util::tool_signals::ToolSignals;
/// A value in a session's [`State`].
#[derive(Debug, Clone)]
diff --git a/crates/libsy/src/lib.rs b/crates/libsy/src/lib.rs
index 8ddfe1be2..54d33b58e 100644
--- a/crates/libsy/src/lib.rs
+++ b/crates/libsy/src/lib.rs
@@ -15,14 +15,14 @@
//! - An [`Algorithm`] is the optimization *algorithm*. Its
//! [`create_run_task`](Algorithm::create_run_task) runs once per request
//! and makes as many model calls as it needs — via [`Driver::call_llm_target`], which look
-//! like ordinary calls — publishes its [`Decision`]s with [`Driver::info`], and
-//! returns the final [`Response`]. The provided
+//! like ordinary calls — publishes its [`Decision`](switchyard_protocol::Decision)s with [`Driver::info`], and
+//! returns the final [`Response`](switchyard_protocol::Response). The provided
//! [`run_stream`](Algorithm::run_stream) drives that on its own task and hands
//! back a stream of [`Step`]s; [`run`](Algorithm::run) runs
//! it to completion with the targets' default clients.
//! - An [`LlmTarget`] names a routing target by its [`semantic_name`](LlmTarget::semantic_name).
//! Every call is *offloaded* to the request's stream as a [`Step::CallLlm`]; the
-//! target's [`RoutedLlmClient`], if any, rides along as
+//! target's [`RoutedLlmClient`](switchyard_protocol::RoutedLlmClient), if any, rides along as
//! [`RoutedRequest::default_client`] so the host can serve it by default or
//! override it (see below).
//!
@@ -32,7 +32,7 @@
//!
//! - [`run`](Algorithm::run) — run to completion, serving each
//! offloaded call via its [`RoutedRequest::default_client`], and return the decision
-//! trace plus the final [`Response`]. The simplest integration; use it when the
+//! trace plus the final [`Response`](switchyard_protocol::Response). The simplest integration; use it when the
//! algorithm holds the model clients (it errors if a routed target has no client).
//! - [`run_stream`](Algorithm::run_stream) — return a stream of [`Step`]s. Each
//! model call is offloaded: the stream yields a [`Step::CallLlm`] carrying a promise;
@@ -55,9 +55,9 @@
//! ## Observability
//!
//! The provided run methods instrument every algorithm from the outside — at the
-//! [`Decision`] hook and the offload boundary — so algorithms carry no telemetry
+//! [`Decision`](switchyard_protocol::Decision) hook and the offload boundary — so algorithms carry no telemetry
//! code. Each run gets a `libsy.run` tracing span (correlation ids from
-//! [`Metadata`] attached) with a child `libsy.llm_call` span per model call
+//! [`Metadata`](switchyard_protocol::Metadata) attached) with a child `libsy.llm_call` span per model call
//! (fulfillment time as the algorithm observes it) plus a `libsy.client_call`
//! span around the actual API call when [`run`](Algorithm::run) serves it;
//! each [`Driver::info`] decision is logged with its reasoning; and OpenTelemetry
@@ -77,15 +77,38 @@
//! [`algorithms::LlmTaskClassifier`] uses one model to classify and route to its selected target.
mod core;
-pub use core::*;
+pub use core::algorithm::{
+ Algorithm, CallLlmRequest, Driver, LlmCallObservation, LlmTarget, LlmTargetSet, RoutedRequest,
+ RunObservation, RunObserver, Step, StepStream,
+};
+pub use core::classifier::{Classification, Classifier, Score};
+pub use core::processor::{Event, Processor};
+pub use core::state::{State, StateValue};
mod error;
pub use error::{DriverError, LibsyError, Result};
-pub mod algorithms;
+mod algorithms;
+pub use algorithms::llm_class::{LlmTaskClassifier, TaskClassifierConfig};
+pub use algorithms::noop::{Noop, NoopDecision};
+pub use algorithms::passthrough::{Passthrough, PassthroughDecision};
+pub use algorithms::rand::{Random, RandomClassifier, RandomDecision};
+pub use algorithms::stage::{LlmFallback, StageRouter, StageRouterConfig};
+pub use algorithms::util::affinity::AffinityRouter;
+pub use algorithms::util::escalation::EscalationJudgeConfig;
+pub use algorithms::util::prompts::{append_note, SystemPromptProcessor, TargetPrompts};
+pub use algorithms::util::subagent::SubagentOverride;
+pub use algorithms::util::tool_signals::{ToolSignals, DEFAULT_RECENT_WINDOW};
+
+// Stage-router scoring and tier selection — the shared signal-driven routing
+// core (scorer, picker, and the `StageClassifier`).
+pub use algorithms::util::stage::{
+ dimensions_from_signal, pick_tier, score_signal, CodingAgentDimensions, DecisionSource,
+ HandoffNoteConfig, PickOutcome, PickerMode, ScoreResult, StageClassifier, StageTargets, Tier,
+ DECISION_SOURCE_KEY,
+};
mod observability;
-pub use algorithms::util::tool_signals::{ToolSignals, DEFAULT_RECENT_WINDOW};
/// Registers process-wide compatibility gauges with the global meter provider.
///
@@ -93,16 +116,3 @@ pub use algorithms::util::tool_signals::{ToolSignals, DEFAULT_RECENT_WINDOW};
pub fn initialize_metrics() {
observability::initialize_metrics();
}
-
-/// Stage-router scoring and tier selection — the shared signal-driven routing
-/// core (scorer, picker, and the `StageClassifier`).
-// TODO cleanup once switchyard-components is removed
-pub mod stage_router {
- pub use crate::algorithms::stage::{LlmFallback, StageRouter, StageRouterConfig};
-
- pub use crate::algorithms::util::stage::{
- dimensions_from_signal, pick_tier, score_signal, CodingAgentDimensions, DecisionSource,
- HandoffNoteConfig, PickOutcome, PickerMode, ScoreResult, StageClassifier, StageTargets,
- Tier, DECISION_SOURCE_KEY,
- };
-}
diff --git a/crates/libsy/src/observability.rs b/crates/libsy/src/observability.rs
index 61f0b01a8..aa7fe3627 100644
--- a/crates/libsy/src/observability.rs
+++ b/crates/libsy/src/observability.rs
@@ -45,9 +45,10 @@ use switchyard_protocol::StopReason;
use tracing::Span;
use tracing_opentelemetry::OpenTelemetrySpanExt;
-use crate::{
- AggLlmResponse, Context, Decision, Driver, LibsyError, LlmClientError, LlmRequest, LlmResponse,
- LlmResponseChunk, LlmResponseStream, Request, Response, Result, Usage,
+use crate::{Driver, LibsyError, Result};
+use switchyard_protocol::{
+ AggLlmResponse, Context, Decision, LlmClientError, LlmRequest, LlmResponse, LlmResponseChunk,
+ LlmResponseStream, Request, Response, Usage,
};
const METRICS_SCOPE: &str = "switchyard";
@@ -105,9 +106,9 @@ fn outcome_value<T>(result: &Result<T>) -> &'static str {
/// Span covering one algorithm run (the whole `create_run_task` execution).
///
-/// Correlation ids from the request [`crate::Metadata`] are recorded as span fields
+/// Correlation ids from the request [`switchyard_protocol::Metadata`] are recorded as span fields
/// when present. `tracing` spans cannot grow field names at runtime, so
-/// arbitrary host labels ride in via [`crate::Metadata::extra_metadata`], recorded
+/// arbitrary host labels ride in via [`switchyard_protocol::Metadata::extra_metadata`], recorded
/// whole into the `extra_metadata` field. `outcome` and `error` are filled in
/// by [`record_run`] when the run ends.
pub(crate) fn run_span(algorithm: &str, request: &Request) -> Span {
diff --git a/crates/libsy/tests/observability.rs b/crates/libsy/tests/observability.rs
index a7a218104..269651e2e 100644
--- a/crates/libsy/tests/observability.rs
+++ b/crates/libsy/tests/observability.rs
@@ -32,12 +32,16 @@ use tracing_subscriber::layer::{Context as LayerContext, SubscriberExt};
use tracing_subscriber::registry::LookupSpan;
use tracing_subscriber::Layer;
-use switchyard_libsy::algorithms::{LlmTaskClassifier, TaskClassifierConfig};
use switchyard_libsy::{
- Algorithm, Context, Decision, Driver, LibsyError, LlmResponse, LlmResponseChunk, LlmTarget,
- LlmTargetSet, Metadata, Request, Response, RoutedLlmClient, Step, Usage,
+ Algorithm, Driver, LibsyError, LlmTarget, LlmTargetSet, LlmTaskClassifier, Step,
+ TaskClassifierConfig,
+};
+use switchyard_protocol::{
+ text_request, text_response, LlmClientError, LlmResponseChunk, StopReason,
+};
+use switchyard_protocol::{
+ Context, Decision, LlmResponse, Metadata, Request, Response, RoutedLlmClient, Usage,
};
-use switchyard_protocol::{text_request, text_response, LlmClientError, StopReason};
#[derive(Debug, thiserror::Error)]
#[error("{0}")]
diff --git a/crates/switchyard-components/src/stage_router.rs b/crates/switchyard-components/src/stage_router.rs
index f961fcf0e..4a473da2d 100644
--- a/crates/switchyard-components/src/stage_router.rs
+++ b/crates/switchyard-components/src/stage_router.rs
@@ -9,7 +9,7 @@
//! module simply re-exports the API so the crate's processors decide a turn's tier
//! through the same implementation the libsy profile uses.
-pub use switchyard_libsy::stage_router::{
+pub use switchyard_libsy::{
dimensions_from_signal, pick_tier, score_signal, CodingAgentDimensions, DecisionSource,
PickOutcome, PickerMode, ScoreResult, StageClassifier, Tier,
};
diff --git a/crates/switchyard-py/src/libsy_bindings.rs b/crates/switchyard-py/src/libsy_bindings.rs
index a50380fd7..8b599cd79 100644
--- a/crates/switchyard-py/src/libsy_bindings.rs
+++ b/crates/switchyard-py/src/libsy_bindings.rs
@@ -9,14 +9,14 @@ use async_trait::async_trait;
use pyo3::exceptions::{PyTypeError, PyValueError};
use pyo3::prelude::*;
use serde_json::{json, Value};
-use switchyard_libsy::algorithms::{
- LlmFallback, LlmTaskClassifier, Noop, Random, StageRouter, StageRouterConfig,
+use switchyard_libsy::{
+ Algorithm, HandoffNoteConfig, LibsyError as RustLibsyError, LlmFallback, LlmTarget,
+ LlmTargetSet, LlmTaskClassifier, Noop, PickerMode, Random, StageRouter, StageRouterConfig,
TaskClassifierConfig,
};
-use switchyard_libsy::stage_router::{HandoffNoteConfig, PickerMode};
-use switchyard_libsy::{
- AggLlmResponse, Algorithm, Context, Decision, LibsyError as RustLibsyError, LlmClientError,
- LlmResponse, LlmTarget, LlmTargetSet, Metadata, Request, Response, RoutedLlmClient,
+use switchyard_protocol::{
+ AggLlmResponse, Context, Decision, LlmClientError, LlmResponse, Metadata, Request, Response,
+ RoutedLlmClient,
};
use crate::errors::py_libsy_error;
diff --git a/crates/switchyard-server/Cargo.toml b/crates/switchyard-server/Cargo.toml
index c0d1b52c7..7833a5cfb 100644
--- a/crates/switchyard-server/Cargo.toml
+++ b/crates/switchyard-server/Cargo.toml
@@ -29,6 +29,7 @@ prometheus = "0.14"
serde.workspace = true
toml = "1.1"
switchyard-llm-client.workspace = true
+switchyard-protocol.workspace = true
serde_json.workspace = true
switchyard-translation.workspace = true
humantime = "2.4"
diff --git a/crates/switchyard-server/src/config.rs b/crates/switchyard-server/src/config.rs
index 351f122ea..c0c03a478 100644
--- a/crates/switchyard-server/src/config.rs
+++ b/crates/switchyard-server/src/config.rs
@@ -8,17 +8,17 @@ use std::fs;
use std::path::Path;
use std::sync::Arc;
-use libsy::algorithms::{
- EscalationJudgeConfig, LlmTaskClassifier, Noop, Passthrough, Random, StageRouter,
- StageRouterConfig, TargetPrompts, TaskClassifierConfig,
+use libsy::{
+ Algorithm, EscalationJudgeConfig, HandoffNoteConfig, LlmFallback, LlmTarget, LlmTargetSet,
+ LlmTaskClassifier, Noop, Passthrough, PickerMode, Random, StageRouter, StageRouterConfig,
+ TargetPrompts, TaskClassifierConfig,
};
-use libsy::stage_router::{HandoffNoteConfig, LlmFallback, PickerMode};
-use libsy::{Algorithm, LlmTarget, LlmTargetSet, RoutedLlmClient};
use serde::Deserialize;
use serde_json::Value;
use switchyard_llm_client::{
Backend, HttpBackendConfig, ModelConfig, TranslatingLlmClient, DEFAULT_MAX_RETRIES,
};
+use switchyard_protocol::RoutedLlmClient;
use crate::{ServerError, ServerResult, ServerState};
diff --git a/crates/switchyard-server/src/lib.rs b/crates/switchyard-server/src/lib.rs
index d90ed6465..b566aadad 100644
--- a/crates/switchyard-server/src/lib.rs
+++ b/crates/switchyard-server/src/lib.rs
@@ -31,13 +31,11 @@ use axum::response::{IntoResponse, Response};
use axum::routing::{get, post};
use axum::{Extension, Json, Router};
use axum_server::tls_rustls::RustlsConfig;
-use libsy::{
- Algorithm, Context, Decision, LibsyError, LlmClientError, Metadata, Request, RunObservation,
- RunObserver, Usage,
-};
+use libsy::{Algorithm, LibsyError, RunObservation, RunObserver};
use parking_lot::Mutex;
use serde::Deserialize;
use serde_json::{json, Value};
+use switchyard_protocol::{Context, Decision, LlmClientError, Metadata, Request, Usage};
use tokio::net::{TcpListener, TcpSocket};
use tokio::task;
use tracing::{Instrument, Level};
diff --git a/crates/switchyard-server/src/response.rs b/crates/switchyard-server/src/response.rs
index b03deeea9..3cf0500bb 100644
--- a/crates/switchyard-server/src/response.rs
+++ b/crates/switchyard-server/src/response.rs
@@ -7,7 +7,7 @@ use std::error::Error;
use axum::response::{IntoResponse, Response as HttpResponse};
use axum::Json;
-use libsy::{LlmResponse, Response as AlgorithmResponse};
+use switchyard_protocol::{LlmResponse, Response as AlgorithmResponse};
use switchyard_translation::{encode_aggregated_response, encode_stream, WireFormat};
use crate::sse::frame_stream;
diff --git a/crates/switchyard-server/src/routing_log.rs b/crates/switchyard-server/src/routing_log.rs
index fcc851c83..58ab4ae3f 100644
--- a/crates/switchyard-server/src/routing_log.rs
+++ b/crates/switchyard-server/src/routing_log.rs
@@ -11,8 +11,8 @@ use std::path::{Path, PathBuf};
use std::time::SystemTime;
use humantime::format_rfc3339_millis;
-use libsy::Usage;
use serde::{Deserialize, Serialize};
+use switchyard_protocol::Usage;
use crate::usage_metrics::token_usage;
use crate::{ServerError, ServerResult};
diff --git a/crates/switchyard-server/src/usage_metrics.rs b/crates/switchyard-server/src/usage_metrics.rs
index 6937b585f..007733953 100644
--- a/crates/switchyard-server/src/usage_metrics.rs
+++ b/crates/switchyard-server/src/usage_metrics.rs
@@ -6,8 +6,8 @@
use std::time::{Duration, Instant};
use futures_util::StreamExt;
-use libsy::{LlmResponse, LlmResponseChunk, Response, Usage};
use opentelemetry::{global, KeyValue};
+use switchyard_protocol::{LlmResponse, LlmResponseChunk, Response, Usage};
use crate::routing_log::RoutingLogContext;
use crate::stats::{StatsAccumulator, TokenUsage};
diff --git a/crates/switchyard-server/tests/server.rs b/crates/switchyard-server/tests/server.rs
index 2a5cea95b..703124649 100644
--- a/crates/switchyard-server/tests/server.rs
+++ b/crates/switchyard-server/tests/server.rs
@@ -17,10 +17,10 @@ use axum::response::{IntoResponse, Response as HttpResponse};
use axum::routing::post;
use axum::{Json, Router};
use http_body_util::BodyExt;
-use libsy::algorithms::Random;
-use libsy::{Algorithm, LlmTarget, LlmTargetSet, RoutedLlmClient};
+use libsy::{Algorithm, LlmTarget, LlmTargetSet, Random};
use serde_json::{json, Value};
use switchyard_llm_client::{Backend, HttpBackendConfig, ModelConfig, TranslatingLlmClient};
+use switchyard_protocol::RoutedLlmClient;
use switchyard_server::config::load_server_state;
use switchyard_server::{build_switchyard_router, ServerState};
use tokio::net::TcpListener;