pub struct AiRuntime { /* private fields */ }Expand description
The per-generation compiled AI table (DW-075): the provider pool with resolved credentials plus the model alias map. Built at dataplane refresh from the published config; immutable once built.
Implementations§
Source§impl AiRuntime
impl AiRuntime
Sourcepub fn compile(cfg: Option<&AiConfig>, gateway: &Gateway) -> Option<AiRuntime>
pub fn compile(cfg: Option<&AiConfig>, gateway: &Gateway) -> Option<AiRuntime>
Compile from the ai: config block. None when the block is
absent (no AI surface). Secret references that fail to resolve
here (a validate-vs-build race with the environment, or a file
deleted since publish) fail the PROVIDER closed: the provider
compiles without its auth header and every call to it will
surface the provider’s own 401 — the loud, attributable
failure — while an error log records why.
Sourcepub fn mcp(&self) -> Option<&Arc<CompiledMcp>>
pub fn mcp(&self) -> Option<&Arc<CompiledMcp>>
The compiled MCP gateway (DW-087); None when no ai.mcp block.
Sourcepub fn a2a(&self) -> Option<&Arc<CompiledA2a>>
pub fn a2a(&self) -> Option<&Arc<CompiledA2a>>
The compiled A2A surface (DW-114); None when no ai.a2a block
or the block is inert (feature off / disabled).
Sourcepub fn experiments_config(&self) -> Option<&AiExperiments>
pub fn experiments_config(&self) -> Option<&AiExperiments>
AI-14 (#202): The experiments config (prompt versioning, A/B
tests, evals). None when no ai.experiments block.
Sourcepub fn prompt_overrides(&self) -> &[(String, String)]
pub fn prompt_overrides(&self) -> &[(String, String)]
AI-14 (#202): Runtime prompt overrides (prompt_name -> version).
Sourcepub fn resolve<'a>(
&'a self,
alias: &str,
) -> Option<(&'a CompiledProvider, &'a str)>
pub fn resolve<'a>( &'a self, alias: &str, ) -> Option<(&'a CompiledProvider, &'a str)>
Resolve a model alias to its provider and provider model id (the DW-075 single-target view; failover lists and canary splits resolve to the same primary).
Sourcepub fn model(&self, alias: &str) -> Option<&CompiledModel>
pub fn model(&self, alias: &str) -> Option<&CompiledModel>
The compiled model entry for an alias (routing introspection and tests).
Sourcepub fn route<'a>(&'a self, alias: &str, pick_key: &str) -> Vec<&'a RouteTarget>
pub fn route<'a>(&'a self, alias: &str, pick_key: &str) -> Vec<&'a RouteTarget>
Route one request (DW-076): the ordered candidate list to try.
A canary alias yields exactly ONE candidate — the deterministic
weighted pick for pick_key (the request id); a failover alias
yields [primary, alternates...]. An empty result means the
alias does not exist. Policy aliases (DW-085) and experiment
aliases (DW-086) return an empty list here — they need the
async route_with_policy path (the
classifier call is async for policies; the experiment pick is
sync but returns an experiments::ExperimentDecision the dataplane
records). The sync route stays for tests and the non-policy
dataplane path.
Sourcepub fn route_with_canary_index<'a>(
&'a self,
alias: &str,
pick_key: &str,
) -> (Vec<&'a RouteTarget>, Option<usize>)
pub fn route_with_canary_index<'a>( &'a self, alias: &str, pick_key: &str, ) -> (Vec<&'a RouteTarget>, Option<usize>)
DW-091: like route but for canary aliases the
single picked candidate carries its INDEX (0 = baseline, 1 =
canary for a 2-version canary split). The auto-canary
controller needs the index to record the outcome on the
correct side. Returns (candidates, canary_index) where
canary_index is Some(idx) only for canary aliases.
Sourcepub async fn route_with_policy(
&self,
alias: &str,
pick_key: &str,
prompt_text: &str,
) -> (Vec<RouteTarget>, Option<PolicyDecision>)
pub async fn route_with_policy( &self, alias: &str, pick_key: &str, prompt_text: &str, ) -> (Vec<RouteTarget>, Option<PolicyDecision>)
Route one request with policy/experiment evaluation (DW-085 /
DW-086). Like route but handles Policy
variants by calling the async
evaluate method,
and Experiment variants by doing the deterministic weighted
pick. Returns owned RouteTargets plus an optional
PolicyDecision the dataplane
records as a metric (None for non-policy models). For
experiment models, the experiments::ExperimentDecision is returned
separately via route_experiment.
For non-policy/non-experiment models, delegates to the sync
routing logic. An empty result means the alias does not exist.
Sourcepub async fn route_with_policy_and_canary_index(
&self,
alias: &str,
pick_key: &str,
prompt_text: &str,
) -> (Vec<RouteTarget>, Option<PolicyDecision>, Option<usize>)
pub async fn route_with_policy_and_canary_index( &self, alias: &str, pick_key: &str, prompt_text: &str, ) -> (Vec<RouteTarget>, Option<PolicyDecision>, Option<usize>)
DW-091: like route_with_policy but
also returns the canary index (0 = baseline, 1 = canary for a
2-version canary split) when the alias is a canary alias. The
auto-canary controller needs the index to record the outcome
on the correct side. Returns (candidates, policy_decision, canary_index).
Sourcepub fn route_experiment(
&self,
alias: &str,
pick_key: &str,
) -> Option<(RouteTarget, ExperimentDecision)>
pub fn route_experiment( &self, alias: &str, pick_key: &str, ) -> Option<(RouteTarget, ExperimentDecision)>
Route one request for an experiment alias (DW-086): the
deterministic weighted pick selects a variant, returning the
RouteTarget and the experiments::ExperimentDecision for analytics
attribution. Returns None when the alias is not an experiment
alias or does not exist.
Sourcepub fn experiment(&self, alias: &str) -> Option<&Arc<CompiledAbTest>>
pub fn experiment(&self, alias: &str) -> Option<&Arc<CompiledAbTest>>
The compiled experiment for an alias (introspection/tests).
Sourcepub fn provider(&self, name: &str) -> Option<&CompiledProvider>
pub fn provider(&self, name: &str) -> Option<&CompiledProvider>
The compiled provider by name.
Sourcepub fn provider_names(&self) -> Vec<String>
pub fn provider_names(&self) -> Vec<String>
DW-080: the names of all compiled providers (for admin API credential pool status enumeration).
Sourcepub fn provider_count(&self) -> usize
pub fn provider_count(&self) -> usize
Number of compiled providers (config introspection/tests).
Sourcepub fn model_count(&self) -> usize
pub fn model_count(&self) -> usize
Number of model aliases (config introspection/tests).
Sourcepub fn with_rebuilt_canary(
&self,
alias: &str,
new_weights: &[u32],
) -> Option<AiRuntime>
pub fn with_rebuilt_canary( &self, alias: &str, new_weights: &[u32], ) -> Option<AiRuntime>
DW-091: rebuild the canary split for alias with new weights
and return a new runtime with the replacement. The providers
and other models are shared (Arc bump / clone). new_weights
is the new weight per canary version in config order (baseline
first, canary second for a 2-version canary). The total weight
MUST stay constant (the caller enforces this). Returns None
when the alias is not a canary alias or the weight count does
not match the version count.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for AiRuntime
impl RefUnwindSafe for AiRuntime
impl Send for AiRuntime
impl Sync for AiRuntime
impl Unpin for AiRuntime
impl UnwindSafe for AiRuntime
Blanket Implementations§
§impl<T> AnyExt for T
impl<T> AnyExt for T
§fn downcast_ref<T>(this: &Self) -> Option<&T>where
T: Any,
fn downcast_ref<T>(this: &Self) -> Option<&T>where
T: Any,
T behind reference§fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>where
T: Any,
fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>where
T: Any,
T behind mutable reference§fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Any,
fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Any,
T behind Rc pointer§fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Any,
fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Any,
T behind Arc pointer§fn downcast_box<T>(this: Box<Self>) -> Result<Box<T>, Box<Self>>where
T: Any,
fn downcast_box<T>(this: Box<Self>) -> Result<Box<T>, Box<Self>>where
T: Any,
T behind Box pointer§fn downcast_move<T>(this: Self) -> Option<T>
fn downcast_move<T>(this: Self) -> Option<T>
Self to T,
useful only in generic context as a workaround for specializationSource§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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T, X> CoerceTo<T> for Xwhere
T: CoerceFrom<X> + ?Sized,
impl<T, X> CoerceTo<T> for Xwhere
T: CoerceFrom<X> + ?Sized,
fn coerce_rc_to(self: Rc<X>) -> Rc<T>
fn coerce_box_to(self: Box<X>) -> Box<T>
fn coerce_ref_to(&self) -> &T
fn coerce_mut_to(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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