pub struct ToolExecutionContext<'a> {
pub session_id: Option<&'a str>,
pub tool_call_id: &'a str,
pub event_tx: Option<&'a Sender<AgentEvent>>,
pub available_tool_schemas: Option<&'a [ToolSchema]>,
pub bypass_permissions: bool,
pub can_async_resume: bool,
pub pre_parsed_args: Option<&'a Value>,
}Expand description
Context passed to tools during execution.
All fields are optional and should be treated as best-effort hints.
⚠️ Real tool dispatch must build this via ToolExecutionContext::for_dispatch
(both agent loops do), NOT a struct literal — that routes every per-session
flag through ToolExecutionSessionFlags so a new flag can’t be wired into
one loop and silently skipped in the other. Struct literals are for tests
and tools that synthesize a child context.
Fields§
§session_id: Option<&'a str>Bamboo session id that is executing the tool.
tool_call_id: &'a strTool call id from the model (ToolCall.id).
event_tx: Option<&'a Sender<AgentEvent>>Event sender for streaming progress to clients (agent SSE stream).
available_tool_schemas: Option<&'a [ToolSchema]>Snapshot of tools currently available to the executing session.
bypass_permissions: boolWhen true, the executing session is in “bypass permissions” mode, so
tool permission checks are skipped. Sourced per-session from the
session’s runtime state (runtime.json), not the global checker.
can_async_resume: boolWhen true, the executing agent loop can suspend the current turn for a
backgrounded shell and self-resume once it finishes (i.e. a
bash_resume_hook AND persistence are wired). The Bash tool uses this to
decide whether its auto path (run_in_background omitted) may promote a
long command to background: when false, the auto path stays purely
synchronous so the command’s output is never orphaned on a loop that
can’t resume it (issue #84, phase 2d). Derived from the loop config at
the dispatch site — NOT session-derived — so it is a direct
for_dispatch parameter rather than a ToolExecutionSessionFlags field.
pre_parsed_args: Option<&'a Value>The tool call’s function.arguments JSON string, already parsed once by
the dispatching agent loop (which also parses it to populate the
ToolStart event). When Some, downstream executors should reuse this
instead of calling parse_tool_args_best_effort on the raw string a
second time — the value here is the exact output of that same parser on
the same input, so reuse is behavior-preserving (issue #106, deferred B1
from #17). When None (e.g. none() contexts, tests, or executors that
synthesize a child call), executors parse the raw string themselves,
preserving the original single-parse-per-consumer behavior.
Implementations§
Source§impl<'a> ToolExecutionContext<'a>
impl<'a> ToolExecutionContext<'a>
pub fn none(tool_call_id: &'a str) -> ToolExecutionContext<'a>
Sourcepub fn for_dispatch(
session_id: &'a str,
tool_call_id: &'a str,
event_tx: &'a Sender<AgentEvent>,
available_tool_schemas: &'a [ToolSchema],
flags: ToolExecutionSessionFlags,
can_async_resume: bool,
pre_parsed_args: Option<&'a Value>,
) -> ToolExecutionContext<'a>
pub fn for_dispatch( session_id: &'a str, tool_call_id: &'a str, event_tx: &'a Sender<AgentEvent>, available_tool_schemas: &'a [ToolSchema], flags: ToolExecutionSessionFlags, can_async_resume: bool, pre_parsed_args: Option<&'a Value>, ) -> ToolExecutionContext<'a>
Build a context for a real tool dispatch, applying every per-session flag
from ToolExecutionSessionFlags. This is the SINGLE place that maps
session flags onto the context, and the only constructor the agent loops
use — keep both loops (per_call.rs, result_handler.rs) on it so a new
per-session field reaches all dispatch paths without per-site edits.
Sourcepub fn cloned_sender(&self) -> Option<Sender<AgentEvent>>
pub fn cloned_sender(&self) -> Option<Sender<AgentEvent>>
Clone the sender (when present) for use in spawned tasks.
Sourcepub async fn emit(&self, event: AgentEvent)
pub async fn emit(&self, event: AgentEvent)
Best-effort emit of an event (ignored if no sender).
Sourcepub async fn emit_tool_token(&self, content: impl Into<String>)
pub async fn emit_tool_token(&self, content: impl Into<String>)
Convenience helper for streaming tool-scoped output.
Trait Implementations§
Source§impl<'a> Clone for ToolExecutionContext<'a>
impl<'a> Clone for ToolExecutionContext<'a>
Source§fn clone(&self) -> ToolExecutionContext<'a>
fn clone(&self) -> ToolExecutionContext<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more