Skip to main content

LlmTaskClassifier

Struct LlmTaskClassifier 

Source
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

Source

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.

Source

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.

Source

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

Source§

fn name(&self) -> &str

Stable, low-cardinality name identifying this algorithm — the 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>>

The client 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 more
Source§

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,

Run one request to completion: make model calls with 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,

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.
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,

Count the tokens 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

Process a request to completion, returning a stream of Steps. Read more
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,

Process a request to completion, returning the final Response and the trace of Decisions the algorithm made along the way.
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,

Process a request to completion while reporting each model call to observer.
Source§

impl Classifier<State> for LlmTaskClassifier

Source§

fn routing_tier(&self, selected_model: &str) -> Option<&'static str>

Stable tier represented by selected_model, when this classifier defines one.
Source§

fn score<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, state: &'life1 mut State, request: &'life2 mut Request, driver: Option<&'life3 Driver>, ) -> Pin<Box<dyn Future<Output = Result<(Classification, Option<Response>)>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Score the classifier’s targets given the current state and request. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more