Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 3 additions & 27 deletions crates/libsy/src/algorithms/fall_through.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ impl<S: Send> Classifier<S> for DefaultTarget {
/// The generic state type is shared by every processor and classifier in the composition.
pub struct FallThrough<S = ()> {
name: String,
decision_reason: fn(&str, &Score) -> String,
processors: Vec<Arc<dyn Processor<S>>>,
classifiers: Vec<Arc<dyn Classifier<S>>>,
targets: Vec<ModelId>,
Expand All @@ -104,7 +103,6 @@ impl FallThrough<()> {
pub fn new(targets: Vec<ModelId>) -> Self {
Self {
name: "fall_through".to_string(),
decision_reason: default_decision_reason,
processors: Vec::new(),
classifiers: Vec::new(),
targets,
Expand All @@ -122,7 +120,6 @@ where
pub fn new_with_state(targets: Vec<ModelId>) -> Self {
Self {
name: "fall_through".to_string(),
decision_reason: default_decision_reason,
processors: Vec::new(),
classifiers: Vec::new(),
targets,
Expand All @@ -137,12 +134,6 @@ where
self
}

/// Sets the decision log message for an algorithm assembled from this cascade.
pub(crate) fn with_decision_reason(mut self, reason: fn(&str, &Score) -> String) -> Self {
self.decision_reason = reason;
self
}

/// Appends a processor to the head-of-request chain.
pub fn with_processor(mut self, processor: Arc<dyn Processor<S>>) -> Self {
self.processors.push(processor);
Expand Down Expand Up @@ -273,9 +264,9 @@ where
// 3. Resolve the target and log the choice.
algorithm::ensure_model_is_target(&self.targets, &score.target)?;
let target = score.target.clone();
let message = (self.decision_reason)(&self.name, &score);
let message = with_routing_tier(message, deciding.routing_tier(&target));
tracing::info!("{message}");
let tier = deciding.routing_tier(&target);
tracing::info!(algorithm=self.name, target=%score.target, confidence=score.confidence, tier = ?tier, "Model selected");

// 4. Post-decision replay: every processor sees the selection so stateful ones
// can bind it, and may rewrite the outbound request (e.g. add a target prompt).
for processor in &self.processors {
Expand Down Expand Up @@ -325,21 +316,6 @@ fn session_id(request: &Request) -> Option<String> {
.map(str::to_string)
}

fn default_decision_reason(_name: &str, winner: &Score) -> String {
format!(
"fall-through selected {} (confidence {:.3})",
winner.target, winner.confidence
)
}

/// Appends the routing tier to a decision log message when the classifier supplies one.
fn with_routing_tier(message: String, tier: Option<&str>) -> String {
match tier {
Some(tier) => format!("{message}; routing tier: {tier}"),
None => message,
}
}

#[async_trait]
impl<S> Algorithm for FallThrough<S>
where
Expand Down
5 changes: 0 additions & 5 deletions crates/libsy/src/algorithms/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,11 @@ impl Random {
let classifier = Arc::new(RandomClassifier::new(targets.clone(), weights, seed)?);
let inner = FallThrough::<()>::new(targets)
.with_name("random")
.with_decision_reason(random_decision_reason)
.with_classifier(classifier);
Ok(Self { inner })
}
}

fn random_decision_reason(_name: &str, winner: &Score) -> String {
format!("random routing selected target '{}'", winner.target)
}

#[async_trait]
impl Algorithm for Random {
fn name(&self) -> &str {
Expand Down
2 changes: 1 addition & 1 deletion crates/switchyard-server/src/observability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use tracing_subscriber::{EnvFilter, Layer as _};

use crate::{ServerError, ServerResult, metrics};

const DEFAULT_LOG_FILTER: &str = "switchyard_server=info,libsy=info,opentelemetry=warn";
const DEFAULT_LOG_FILTER: &str = "info,opentelemetry=warn";
const DEFAULT_SERVICE_NAME: &str = "switchyard-server";

struct Observability {
Expand Down
Loading