pub struct SpeculationEngine { /* private fields */ }Expand description
Speculative execution engine.
Holds a reference to the underlying executor, the shared cache, and the active
configuration. Create one instance per agent session and share via Arc.
§Examples
use std::sync::Arc;
use zeph_config::tools::SpeculativeConfig;
use zeph_core::agent::speculative::SpeculationEngine;
let config = SpeculativeConfig::default(); // mode = off
let engine = SpeculationEngine::new(executor, config);Implementations§
Source§impl SpeculationEngine
impl SpeculationEngine
Sourcepub fn new(
executor: Arc<dyn ErasedToolExecutor>,
config: SpeculativeConfig,
) -> Self
pub fn new( executor: Arc<dyn ErasedToolExecutor>, config: SpeculativeConfig, ) -> Self
Create a new engine with the given executor and config.
Sourcepub fn new_with_supervisor(
executor: Arc<dyn ErasedToolExecutor>,
config: SpeculativeConfig,
supervisor: Option<Arc<TaskSupervisor>>,
) -> Self
pub fn new_with_supervisor( executor: Arc<dyn ErasedToolExecutor>, config: SpeculativeConfig, supervisor: Option<Arc<TaskSupervisor>>, ) -> Self
Create a new engine with an optional session-level supervisor for task registration.
When supervisor is Some, the background sweeper and speculative dispatch tasks are
registered for observability and graceful shutdown. Pass None in test harnesses.
Sourcepub fn mode(&self) -> SpeculationMode
pub fn mode(&self) -> SpeculationMode
Current speculation mode.
Sourcepub fn try_dispatch(
&self,
prediction: &Prediction,
trust_level: SkillTrustLevel,
) -> bool
pub fn try_dispatch( &self, prediction: &Prediction, trust_level: SkillTrustLevel, ) -> bool
Try to dispatch prediction speculatively.
Returns false when the call is skipped (not speculatable, trust gate, confirmation
gate, or circuit-breaker). Returns true when the handle was inserted in the cache.
The confirmation check is performed via requires_confirmation_erased — a pure policy
query that does not execute the tool (fixes C1: no double side-effects).
Sourcepub async fn try_commit(
&self,
call: &ToolCall,
) -> Option<Result<Option<ToolOutput>, ToolError>>
pub async fn try_commit( &self, call: &ToolCall, ) -> Option<Result<Option<ToolOutput>, ToolError>>
Attempt to commit a speculative handle for call.
If a matching handle exists (same tool_id + args_hash), awaits its result and
returns it. If no match, returns None — caller should fall through to normal dispatch.
Sourcepub fn cancel_for(&self, tool_id: &ToolName)
pub fn cancel_for(&self, tool_id: &ToolName)
Cancel and remove the in-flight handle for tool_id, if any.
Performs an actual cache lookup and task abort (fixes C3: was metrics-only no-op).
Sourcepub fn end_turn(&self) -> SpeculativeMetrics
pub fn end_turn(&self) -> SpeculativeMetrics
Cancel all in-flight handles at turn boundary and return metrics snapshot.
Sourcepub fn metrics_snapshot(&self) -> SpeculativeMetrics
pub fn metrics_snapshot(&self) -> SpeculativeMetrics
Snapshot current metrics without resetting.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for SpeculationEngine
impl !RefUnwindSafe for SpeculationEngine
impl Send for SpeculationEngine
impl Sync for SpeculationEngine
impl Unpin for SpeculationEngine
impl UnsafeUnpin for SpeculationEngine
impl !UnwindSafe for SpeculationEngine
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request