pub struct ToolContext {
pub state: Arc<AgentStateSnapshot>,
pub state_handle: Option<Arc<RwLock<AgentStateSnapshot>>>,
pub tool_call_id: Option<String>,
}
Expand description
Context provided to tool implementations for accessing agent state and utilities
Fields§
§state: Arc<AgentStateSnapshot>
Current agent state snapshot (immutable view)
state_handle: Option<Arc<RwLock<AgentStateSnapshot>>>
Optional mutable state handle for tools that need to modify state
tool_call_id: Option<String>
Tool invocation metadata (call ID for responses)
Implementations§
Source§impl ToolContext
impl ToolContext
Sourcepub fn new(state: Arc<AgentStateSnapshot>) -> ToolContext
pub fn new(state: Arc<AgentStateSnapshot>) -> ToolContext
Create a context with immutable state only
Sourcepub fn with_mutable_state(
state: Arc<AgentStateSnapshot>,
state_handle: Arc<RwLock<AgentStateSnapshot>>,
) -> ToolContext
pub fn with_mutable_state( state: Arc<AgentStateSnapshot>, state_handle: Arc<RwLock<AgentStateSnapshot>>, ) -> ToolContext
Create a context with mutable state access
Sourcepub fn with_call_id(self, call_id: Option<String>) -> ToolContext
pub fn with_call_id(self, call_id: Option<String>) -> ToolContext
Set the tool call ID for response correlation
Sourcepub fn text_response(&self, content: impl Into<String>) -> AgentMessage
pub fn text_response(&self, content: impl Into<String>) -> AgentMessage
Create a tool response message with proper metadata
Sourcepub fn json_response(&self, content: Value) -> AgentMessage
pub fn json_response(&self, content: Value) -> AgentMessage
Create a JSON tool response
Trait Implementations§
Source§impl Clone for ToolContext
impl Clone for ToolContext
Source§fn clone(&self) -> ToolContext
fn clone(&self) -> ToolContext
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for ToolContext
impl RefUnwindSafe for ToolContext
impl Send for ToolContext
impl Sync for ToolContext
impl Unpin for ToolContext
impl UnwindSafe for ToolContext
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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>
Converts
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>
Converts
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 moreCreates a shared type from an unshared type.