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.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for UtilityScorer
impl RefUnwindSafe for UtilityScorer
impl Send for UtilityScorer
impl Sync for UtilityScorer
impl Unpin for UtilityScorer
impl UnsafeUnpin for UtilityScorer
impl UnwindSafe for UtilityScorer
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> 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