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 recommend_action(
&self,
score: Option<&UtilityScore>,
ctx: &UtilityContext,
) -> UtilityAction
pub fn recommend_action( &self, score: Option<&UtilityScore>, ctx: &UtilityContext, ) -> UtilityAction
Recommend an action based on the utility score and turn context.
Decision tree (thresholds from arXiv:2603.19896):
user_requested→ alwaysToolCall(bypass policy).- Scoring disabled → always
ToolCall. scoreisNone(invalid score, scoring enabled) →Stop(fail-closed).cost > 0.9(budget nearly exhausted) →Stop.redundancy == 1.0(duplicate call) →Respond.gain >= 0.7 && total >= threshold→ToolCall.gain >= 0.5 && uncertainty > 0.5→Retrieve.total < threshold && tool_calls_this_turn > 0→Verify.total >= threshold→ToolCall.- Default →
Respond.
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.