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: Provide a default impl for `process_signals`. (#80)

Graham Kingac5ecf763bc1
diff --git a/crates/libsy-examples/src/ensemble.rs b/crates/libsy-examples/src/ensemble.rs
index d12f16e2e..333c8e596 100644
--- a/crates/libsy-examples/src/ensemble.rs
+++ b/crates/libsy-examples/src/ensemble.rs
@@ -22,7 +22,7 @@ use std::sync::{Arc, Mutex};
use async_trait::async_trait;
-use libsy::{Algorithm, Context, Decision, Driver, LlmTargetSet, Request, Response, Signals};
+use libsy::{Algorithm, Context, Decision, Driver, LlmTargetSet, Request, Response};
use switchyard_protocol::{completion_text, prompt_text, text_request};
/// Which step of the ensemble flow produced a decision.
@@ -390,20 +390,12 @@ impl Algorithm for EnsembleOrchAlgo {
}
Ok(response)
}
-
- async fn process_signals(
- self: Arc<Self>,
- _signals: Signals,
- ) -> Result<(), Box<dyn Error + Send + Sync>> {
- // Success is measured by the judge, not agent-system signals.
- Ok(())
- }
}
#[cfg(test)]
mod tests {
use super::*;
- use libsy::{LlmClient, LlmResponse, LlmTarget, Response, RoutedRequest};
+ use libsy::{LlmClient, LlmResponse, LlmTarget, Response, RoutedRequest, Signals};
use std::sync::Mutex as StdMutex;
use switchyard_protocol::text_response;
diff --git a/crates/libsy-examples/src/llm_class.rs b/crates/libsy-examples/src/llm_class.rs
index a6a82dff8..a0612dd6a 100644
--- a/crates/libsy-examples/src/llm_class.rs
+++ b/crates/libsy-examples/src/llm_class.rs
@@ -15,7 +15,7 @@ use std::sync::Arc;
use async_trait::async_trait;
-use libsy::{Algorithm, Context, Decision, Driver, LlmTargetSet, Request, Response, Signals};
+use libsy::{Algorithm, Context, Decision, Driver, LlmTargetSet, Request, Response};
use switchyard_protocol::{completion_text, prompt_text, text_request};
/// Preamble prepended to the user prompt when asking the classifier target for a
@@ -170,14 +170,6 @@ impl Algorithm for LlmClassifierOrchAlgo {
.call_llm_target(ctx, &routed_target, routed_request, route_decision)
.await
}
-
- async fn process_signals(
- self: Arc<Self>,
- _signals: Signals,
- ) -> Result<(), Box<dyn Error + Send + Sync>> {
- // Stateless classification; agent-system signals are ignored.
- Ok(())
- }
}
#[cfg(test)]
diff --git a/crates/libsy-examples/src/rand.rs b/crates/libsy-examples/src/rand.rs
index ef28205d2..faf95cf1b 100644
--- a/crates/libsy-examples/src/rand.rs
+++ b/crates/libsy-examples/src/rand.rs
@@ -14,7 +14,7 @@ use std::sync::Arc;
use async_trait::async_trait;
use rand::seq::SliceRandom;
-use libsy::{Algorithm, Context, Decision, Driver, LlmTargetSet, Request, Response, Signals};
+use libsy::{Algorithm, Context, Decision, Driver, LlmTargetSet, Request, Response};
/// Decision produced by [`RandomOrchAlgo`]: which target was chosen and why.
pub struct RandomDecision {
@@ -85,20 +85,12 @@ impl Algorithm for RandomOrchAlgo {
.call_llm_target(ctx, &target, request, decision)
.await
}
-
- async fn process_signals(
- self: Arc<Self>,
- _signals: Signals,
- ) -> Result<(), Box<dyn Error + Send + Sync>> {
- // Random routing is stateless, so agent-system signals are ignored.
- Ok(())
- }
}
#[cfg(test)]
mod tests {
use super::*;
- use libsy::{LlmClient, LlmResponse, LlmTarget, Response, RoutedRequest};
+ use libsy::{LlmClient, LlmResponse, LlmTarget, Response, RoutedRequest, Signals};
use std::collections::HashSet;
use switchyard_protocol::{completion_text, text_request, text_response};
diff --git a/crates/libsy/src/algorithms/noop.rs b/crates/libsy/src/algorithms/noop.rs
index 4c509dc4b..cefab1165 100644
--- a/crates/libsy/src/algorithms/noop.rs
+++ b/crates/libsy/src/algorithms/noop.rs
@@ -10,7 +10,7 @@ use switchyard_protocol::{
AggLlmResponse, ContentBlock, LlmResponse, Request, Response, ResponseOutput, Role, StopReason,
};
-use crate::{Algorithm, Context, Decision, Driver, Signals};
+use crate::{Algorithm, Context, Decision, Driver};
/// A routing algorithm that does not route. It returns a hard-coded response.
pub struct NoopAlgo {}
@@ -68,13 +68,6 @@ impl Algorithm for NoopAlgo {
};
Ok(response)
}
-
- async fn process_signals(
- self: Arc<Self>,
- _signals: Signals,
- ) -> Result<(), Box<dyn Error + Send + Sync>> {
- Ok(())
- }
}
#[cfg(test)]
diff --git a/crates/libsy/src/lib.rs b/crates/libsy/src/lib.rs
index b75961183..26259c832 100644
--- a/crates/libsy/src/lib.rs
+++ b/crates/libsy/src/lib.rs
@@ -369,10 +369,13 @@ pub trait Algorithm: Send + Sync + 'static {
/// Feed the algorithm agentic-stack events (tool results, budgets, etc.). The
/// reference algorithms ignore signals; a stateful algorithm updates its own
/// (interior-mutable) state. Takes `self: Arc<Self>` like the other run methods.
+ #[allow(unused_variables)]
async fn process_signals(
self: Arc<Self>,
signals: Signals,
- ) -> Result<(), Box<dyn Error + Send + Sync>>;
+ ) -> Result<(), Box<dyn Error + Send + Sync>> {
+ Ok(())
+ }
/// Run one request as a stream of [`Step`]s (provided). The algorithm runs on its
/// own task; drive the stream: serve each [`Step::CallLlm`] (via its
@@ -535,13 +538,6 @@ mod tests {
.call_llm_target(ctx, &target, request, decision)
.await
}
-
- async fn process_signals(
- self: Arc<Self>,
- _signals: Signals,
- ) -> Result<(), Box<dyn Error + Send + Sync>> {
- Ok(())
- }
}
/// Build a shared `TestAlgo` over the given target set.
@@ -948,13 +944,6 @@ mod tests {
metadata: None,
})
}
-
- async fn process_signals(
- self: Arc<Self>,
- _signals: Signals,
- ) -> Result<(), Box<dyn Error + Send + Sync>> {
- Ok(())
- }
}
let current = Arc::new(AtomicUsize::new(0));