pub struct ToolCtx { /* private fields */ }Expand description
What the runtime hands a tool for one execution attempt.
This type is kept deliberately small. The only thing a handler clearly
needs is the idempotency key for the current
attempt: an Idempotent tool uses it so
that a retried attempt reuses the same key and the provider collapses the
duplicate into one effect. Everything else a tool might want (recorded
clock, randomness, model calls) belongs to RunCtx in the orchestration
layer, not to a single tool call, so it stays out of here.
The type is designed for additive growth. Fields are private and reached
through accessors, so run identity, the current sequence number, or a
tracing span can be added later without breaking a tool’s call signature.
It is constructed by the runtime, not by tools. The runtime builds
one ToolCtx per dispatch from the idempotency key the replay cursor
carries for that tool call; tests construct it directly.
Implementations§
Source§impl ToolCtx
impl ToolCtx
Sourcepub fn new(idempotency_key: Option<String>) -> Self
pub fn new(idempotency_key: Option<String>) -> Self
Builds a context carrying the idempotency key for this attempt.
Pass None for a tool call that has no key (a Read, or a call the
runtime chose not to key); pass Some(key) for the keyed retry of an
Idempotent tool.
Sourcepub fn idempotency_key(&self) -> Option<&str>
pub fn idempotency_key(&self) -> Option<&str>
The idempotency key for the current attempt, if the runtime set one.
An idempotent tool that talks to a provider passes this through as the provider’s idempotency key so that a retry reuses it and does not create a second effect.
Trait Implementations§
impl Eq for ToolCtx
impl StructuralPartialEq for ToolCtx
Auto Trait Implementations§
impl Freeze for ToolCtx
impl RefUnwindSafe for ToolCtx
impl Send for ToolCtx
impl Sync for ToolCtx
impl Unpin for ToolCtx
impl UnsafeUnpin for ToolCtx
impl UnwindSafe for ToolCtx
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.