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<AgentEventEnvelope>,
seq: SequenceCounter,
) -> Self
pub fn with_event_tx( self, tx: Sender<AgentEventEnvelope>, seq: SequenceCounter, ) -> Self
Set the event channel and sequence counter 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).
The event is wrapped in an AgentEventEnvelope with a unique ID,
sequence number, and timestamp before sending.
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<AgentEventEnvelope>>
pub fn event_tx(&self) -> Option<Sender<AgentEventEnvelope>>
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.
Sourcepub fn event_seq(&self) -> Option<SequenceCounter>
pub fn event_seq(&self) -> Option<SequenceCounter>
Get a clone of the sequence counter (if set).
This is useful for tools that spawn subprocesses (like subagents) and need to assign sequence numbers to events sent to the parent’s stream.