pub struct ToolContext<Ctx> {
pub app: Ctx,
pub metadata: HashMap<String, Value>,
/* private fields */
}Expand description
Context passed to tool execution
Fields§
§app: CtxApplication-specific context (e.g., user_id, db connection)
metadata: HashMap<String, Value>Tool-specific metadata
Implementations§
Source§impl<Ctx> ToolContext<Ctx>
impl<Ctx> ToolContext<Ctx>
pub fn new(app: Ctx) -> Self
pub fn with_metadata(self, key: impl Into<String>, value: Value) -> Self
Sourcepub fn with_event_tx(self, tx: Sender<AgentEvent>) -> Self
pub fn with_event_tx(self, tx: Sender<AgentEvent>) -> Self
Set the event channel for tools that need to emit events during execution.
Sourcepub fn emit_event(&self, event: AgentEvent)
pub fn emit_event(&self, event: AgentEvent)
Emit an event through the event channel (if set).
This uses try_send to avoid blocking and to ensure the future is Send.
The event is silently dropped if the channel is full.
Sourcepub fn event_tx(&self) -> Option<Sender<AgentEvent>>
pub fn event_tx(&self) -> Option<Sender<AgentEvent>>
Get a clone of the event channel sender (if set).
This is useful for tools that spawn subprocesses (like subagents) and need to forward events to the parent’s event stream.
Auto Trait Implementations§
impl<Ctx> Freeze for ToolContext<Ctx>where
Ctx: Freeze,
impl<Ctx> RefUnwindSafe for ToolContext<Ctx>where
Ctx: RefUnwindSafe,
impl<Ctx> Send for ToolContext<Ctx>where
Ctx: Send,
impl<Ctx> Sync for ToolContext<Ctx>where
Ctx: Sync,
impl<Ctx> Unpin for ToolContext<Ctx>where
Ctx: Unpin,
impl<Ctx> UnwindSafe for ToolContext<Ctx>where
Ctx: UnwindSafe,
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