pub struct KeywordRouter { /* private fields */ }Expand description
A keyword-based router with configurable rules and a default fallback.
Rules map keyword patterns (matched case-insensitively against the prompt)
to a preferred BackendType. The first matching rule wins. If no rules
match, the default backend is used.
By default, keywords are matched as substrings. Enable word_boundary
to require that keywords appear as whole words (e.g., “test” won’t match “testing”).
§Example
use agent_teams::backend::router::KeywordRouter;
use agent_teams::BackendType;
let router = KeywordRouter::new(BackendType::ClaudeCode)
.word_boundary(true)
.rule("review", BackendType::GeminiCli)
.rule("analyze", BackendType::GeminiCli)
.rule("implement", BackendType::ClaudeCode)
.rule("test", BackendType::Codex);Implementations§
Source§impl KeywordRouter
impl KeywordRouter
Sourcepub fn new(default: BackendType) -> Self
pub fn new(default: BackendType) -> Self
Create a new keyword router with a default backend.
Sourcepub fn word_boundary(self, enable: bool) -> Self
pub fn word_boundary(self, enable: bool) -> Self
Enable or disable word-boundary matching.
When enabled, “test” matches “test this code” but NOT “testing this code”.
Default is false (substring matching) for backward compatibility.
Sourcepub fn rule(self, keyword: impl Into<String>, backend: BackendType) -> Self
pub fn rule(self, keyword: impl Into<String>, backend: BackendType) -> Self
Add a keyword → backend rule. Keywords are matched case-insensitively
against the SpawnConfig::prompt field.
Sourcepub fn rules(
self,
rules: impl IntoIterator<Item = (String, BackendType)>,
) -> Self
pub fn rules( self, rules: impl IntoIterator<Item = (String, BackendType)>, ) -> Self
Add multiple rules from an iterator of (keyword, backend) pairs.
Trait Implementations§
Source§impl BackendRouter for KeywordRouter
impl BackendRouter for KeywordRouter
Source§fn route<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
config: &'life1 SpawnConfig,
available: &'life2 [BackendType],
) -> Pin<Box<dyn Future<Output = Option<BackendType>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn route<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
config: &'life1 SpawnConfig,
available: &'life2 [BackendType],
) -> Pin<Box<dyn Future<Output = Option<BackendType>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Auto Trait Implementations§
impl Freeze for KeywordRouter
impl RefUnwindSafe for KeywordRouter
impl Send for KeywordRouter
impl Sync for KeywordRouter
impl Unpin for KeywordRouter
impl UnwindSafe for KeywordRouter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more