pub struct LlmTaskClassifier { /* private fields */ }Expand description
Routes each task between an efficient and capable target using an LLM judge.
The judge is consulted before the routed model call. Valid, confident output selects a tier; invalid output, abstention, or a judge failure falls back to the capable target. Optional session affinity can retain a prior assignment and skip the judge on later turns.
Implementations§
Source§impl LlmTaskClassifier
impl LlmTaskClassifier
Sourcepub fn new(
judge_target: LlmTarget,
efficient_target: LlmTarget,
capable_target: LlmTarget,
config: TaskClassifierConfig,
) -> Result<Self>
pub fn new( judge_target: LlmTarget, efficient_target: LlmTarget, capable_target: LlmTarget, config: TaskClassifierConfig, ) -> Result<Self>
Builds task-level capability routing over efficient_target and capable_target.
judge_target serves the classification call and is not itself a routing
destination. When enabled, session affinity runs before the judge and can
short-circuit it with a retained assignment.
§Errors
Returns an error when thresholds are outside [0, 1], the elevated floor is
not above the base threshold, the output-token budget is zero, message-hash
fallback is enabled without affinity, or the packaged judge prompt/schema
cannot be loaded.
Sourcepub fn new_with_escalation(
judge_target: LlmTarget,
efficient_target: LlmTarget,
capable_target: LlmTarget,
config: EscalationJudgeConfig,
max_output_tokens: u64,
) -> Result<Self>
pub fn new_with_escalation( judge_target: LlmTarget, efficient_target: LlmTarget, capable_target: LlmTarget, config: EscalationJudgeConfig, max_output_tokens: u64, ) -> Result<Self>
Constructs an escalation variant that calls the efficient model each turn, judges its response, and latches to the capable tier once the streak confirms.
Every unlatched turn calls the efficient model, buffers its reply, and consults the
trajectory judge. Once config.confirmations consecutive escalate verdicts accumulate
the session latches to the capable tier for its remainder. A judge outage always stays
efficient.
Sourcepub fn new_with_escalation_contract(
judge_target: LlmTarget,
efficient_target: LlmTarget,
capable_target: LlmTarget,
contract_config: ClassifierContractConfig,
config: EscalationJudgeConfig,
max_output_tokens: u64,
) -> Result<Self>
pub fn new_with_escalation_contract( judge_target: LlmTarget, efficient_target: LlmTarget, capable_target: LlmTarget, contract_config: ClassifierContractConfig, config: EscalationJudgeConfig, max_output_tokens: u64, ) -> Result<Self>
Constructs an escalation variant with a configurable classifier contract.
Trait Implementations§
Source§impl Algorithm for LlmTaskClassifier
impl Algorithm for LlmTaskClassifier
Source§fn name(&self) -> &str
fn name(&self) -> &str
algorithm attribute on every span, metric, and log line the crate
emits for its runs.Source§fn count_tokens_client(&self) -> Option<Arc<dyn RoutedLlmClient>>
fn count_tokens_client(&self) -> Option<Arc<dyn RoutedLlmClient>>
count_tokens forwards to: the first of
this algorithm’s targets whose client can count tokens (an Anthropic
upstream). The default is None — an algorithm with no Anthropic target
does not support token counting. Read moreSource§fn create_run_task<'async_trait>(
self: Arc<Self>,
ctx: Context,
driver: Driver,
request: Request,
) -> Pin<Box<dyn Future<Output = Result<Response>> + Send + 'async_trait>>where
Self: 'async_trait,
fn create_run_task<'async_trait>(
self: Arc<Self>,
ctx: Context,
driver: Driver,
request: Request,
) -> Pin<Box<dyn Future<Output = Result<Response>> + Send + 'async_trait>>where
Self: 'async_trait,
Driver::call_llm_target,
publish Decisions with Driver::info, and return the final Response.
The method an algorithm implements; run / run_stream
drive it. ctx carries the request’s cross-cutting values (today: the
algorithm’s telemetry label in Context::values).Source§fn process_signals<'async_trait>(
self: Arc<Self>,
signals: Signals,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
fn process_signals<'async_trait>(
self: Arc<Self>,
signals: Signals,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
self: Arc<Self> like the other run methods.Source§fn count_tokens<'life0, 'async_trait>(
&'life0 self,
request: Request,
) -> Pin<Box<dyn Future<Output = Result<Value>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn count_tokens<'life0, 'async_trait>(
&'life0 self,
request: Request,
) -> Pin<Box<dyn Future<Output = Result<Value>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
request would use — a direct passthrough to this
algorithm’s Anthropic target (via
count_tokens_client), not a routed
call. Token counting is a pre-flight estimate with no routing decision,
so it deliberately bypasses the classifier cascade (which runs only for
completions via run). Returns the upstream’s JSON
verbatim. Errors when the algorithm has no Anthropic target.Source§fn run_stream(
self: Arc<Self>,
ctx: Context,
request: Request,
observer: Option<RunObserver>,
) -> StepStream
fn run_stream( self: Arc<Self>, ctx: Context, request: Request, observer: Option<RunObserver>, ) -> StepStream
Source§fn run<'async_trait>(
self: Arc<Self>,
ctx: Context,
request: Request,
) -> Pin<Box<dyn Future<Output = Result<(Vec<Arc<dyn Decision>>, Response)>> + Send + 'async_trait>>where
Self: 'async_trait,
fn run<'async_trait>(
self: Arc<Self>,
ctx: Context,
request: Request,
) -> Pin<Box<dyn Future<Output = Result<(Vec<Arc<dyn Decision>>, Response)>> + Send + 'async_trait>>where
Self: 'async_trait,
Source§fn run_observed<'async_trait>(
self: Arc<Self>,
ctx: Context,
request: Request,
observer: Option<RunObserver>,
) -> Pin<Box<dyn Future<Output = Result<(Vec<Arc<dyn Decision>>, Response)>> + Send + 'async_trait>>where
Self: 'async_trait,
fn run_observed<'async_trait>(
self: Arc<Self>,
ctx: Context,
request: Request,
observer: Option<RunObserver>,
) -> Pin<Box<dyn Future<Output = Result<(Vec<Arc<dyn Decision>>, Response)>> + Send + 'async_trait>>where
Self: 'async_trait,
observer.Source§impl Classifier<State> for LlmTaskClassifier
impl Classifier<State> for LlmTaskClassifier
Source§fn routing_tier(&self, selected_model: &str) -> Option<&'static str>
fn routing_tier(&self, selected_model: &str) -> Option<&'static str>
selected_model, when this classifier defines one.