Skip to main content

ToolExecutionContext

Struct ToolExecutionContext 

Source
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 str

Tool 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: bool

When 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: bool

When 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>

Source

pub fn none(tool_call_id: &'a str) -> ToolExecutionContext<'a>

Source

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.

Source

pub fn cloned_sender(&self) -> Option<Sender<AgentEvent>>

Clone the sender (when present) for use in spawned tasks.

Source

pub async fn emit(&self, event: AgentEvent)

Best-effort emit of an event (ignored if no sender).

Source

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>

Source§

fn clone(&self) -> ToolExecutionContext<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for ToolExecutionContext<'a>

Source§

impl<'a> Debug for ToolExecutionContext<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more