pub trait RoutingStrategy:
Send
+ Sync
+ 'static {
// Required method
fn select<'life0, 'life1, 'async_trait>(
&'life0 self,
context: &'life1 RoutingContext,
) -> Pin<Box<dyn Future<Output = Result<Option<RoutingCandidate>, BoxError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
// Provided method
fn name(&self) -> &'static str { ... }
}Expand description
Chooses a configured candidate (RoutingStrategy).
The router asks before the first model call, with no attempts, and after each failure no hook
claimed, until routing stops. Return one of context.candidates (compared by identity) or
None to decline.
Declining the opening selection serves the router’s default model; declining after a failure ends routing and the model error surfaces. At the opening selection, errors and foreign candidates propagate; after a failure they end routing without replacing the model error. Each failure round uses a candidate once: naming one already used this round ends routing, and a nested router that cannot resolve uses up its slot while the strategy is asked again.
use strands::models::routing::{RoutingCandidate, RoutingContext, RoutingStrategy};
struct Last;
#[strands::async_trait]
impl RoutingStrategy for Last {
async fn select(&self, context: &RoutingContext) -> Result<Option<RoutingCandidate>, strands::BoxError> {
Ok(context.candidates.last().cloned())
}
}Required Methods§
Sourcefn select<'life0, 'life1, 'async_trait>(
&'life0 self,
context: &'life1 RoutingContext,
) -> Pin<Box<dyn Future<Output = Result<Option<RoutingCandidate>, BoxError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn select<'life0, 'life1, 'async_trait>(
&'life0 self,
context: &'life1 RoutingContext,
) -> Pin<Box<dyn Future<Output = Result<Option<RoutingCandidate>, BoxError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Selects a candidate from context.candidates, or None to decline.
§Errors
Any error; see the trait docs for how the router treats it.
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".