pub struct AgentWeights {
pub states: HashMap<String, RateLimitState>,
pub base_weights: HashMap<String, f64>,
}Expand description
Tracks per-agent weights for weighted round-robin routing.
Fields§
§states: HashMap<String, RateLimitState>§base_weights: HashMap<String, f64>Configured base weights per agent (from config.yml). Used as the recovery ceiling instead of DEFAULT_WEIGHT.
Implementations§
Source§impl AgentWeights
impl AgentWeights
Sourcepub fn ensure_agents(&mut self, agents: &[String])
pub fn ensure_agents(&mut self, agents: &[String])
Ensure all available agents have an entry, using configured base weights.
Sourcepub fn ensure_agents_with_weights(
&mut self,
agents: &[String],
configured_weights: &HashMap<String, f64>,
)
pub fn ensure_agents_with_weights( &mut self, agents: &[String], configured_weights: &HashMap<String, f64>, )
Ensure all available agents have an entry, applying configured base weights.
Agents with an explicit weight in config.yml use that as their base.
Agents without a configured weight default to the minimum of the
explicitly configured weights (see default_missing_weight), so an
omission never outranks an agent the operator actually configured.
Sourcepub fn record_rate_limit(&mut self, agent: &str)
pub fn record_rate_limit(&mut self, agent: &str)
Record a rate limit event for an agent.
Sourcepub fn record_success(&mut self, agent: &str)
pub fn record_success(&mut self, agent: &str)
Record a successful task completion for an agent.
Sourcepub fn tick_recovery(&mut self)
pub fn tick_recovery(&mut self)
Tick recovery for all agents.
Sourcepub fn weighted_select(
&self,
agents: &[String],
task_id: &str,
) -> Option<String>
pub fn weighted_select( &self, agents: &[String], task_id: &str, ) -> Option<String>
Select an agent by weighted probability from the given list.
Uses a simple weighted random selection: each agent’s probability is proportional to its weight. If all weights are zero (shouldn’t happen due to MIN_WEIGHT), falls back to uniform selection.
Sourcepub fn get_weight(&self, agent: &str) -> f64
pub fn get_weight(&self, agent: &str) -> f64
Get the current weight for an agent.
Trait Implementations§
Source§impl Clone for AgentWeights
impl Clone for AgentWeights
Source§impl Debug for AgentWeights
impl Debug for AgentWeights
Auto Trait Implementations§
impl Freeze for AgentWeights
impl RefUnwindSafe for AgentWeights
impl Send for AgentWeights
impl Sync for AgentWeights
impl Unpin for AgentWeights
impl UnsafeUnpin for AgentWeights
impl UnwindSafe for AgentWeights
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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