pub struct UtilityScorer { /* private fields */ }Expand description
Computes utility scores for tool calls before dispatch.
Not Send + Sync — lives on the agent’s single-threaded tool loop (same lifecycle as
ToolResultCache and recent_tool_calls).
Implementations§
Source§impl UtilityScorer
impl UtilityScorer
Sourcepub fn new(config: UtilityScoringConfig) -> Self
pub fn new(config: UtilityScoringConfig) -> Self
Create a new scorer from the given config.
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Whether utility scoring is enabled.
Sourcepub fn score(
&self,
call: &ToolCall,
ctx: &UtilityContext,
) -> Option<UtilityScore>
pub fn score( &self, call: &ToolCall, ctx: &UtilityContext, ) -> Option<UtilityScore>
Score a candidate tool call.
Returns None when scoring is disabled. When scoring produces a non-finite
result (misconfigured weights), returns None — the caller treats None as
fail-closed (skip the tool call) unless user_requested is set.
Sourcepub fn should_execute(
&self,
score: Option<&UtilityScore>,
user_requested: bool,
) -> bool
pub fn should_execute( &self, score: Option<&UtilityScore>, user_requested: bool, ) -> bool
Returns true when the tool call should be executed based on its score.
user_requested tools bypass the gate unconditionally.
When score is None (scoring disabled or produced invalid result) and
user_requested is false, the tool is skipped (fail-closed).
Sourcepub fn record_call(&mut self, call: &ToolCall)
pub fn record_call(&mut self, call: &ToolCall)
Record a call as executed for redundancy tracking.
Must be called after score() and before the next call to score() for the
same tool in the same turn.