pub struct ToolContext {
pub session_id: SessionId,
pub user_event_tx: UnboundedSender<UserEvent>,
pub llm_client: Option<Arc<dyn LlmProvider>>,
pub session_store: Option<Arc<dyn SessionStore>>,
pub language: Language,
pub cancel_token: CancellationToken,
pub max_output_chars: Option<usize>,
pub exec_clock: ExecClock,
/* private fields */
}Fields§
§session_id: SessionId§user_event_tx: UnboundedSender<UserEvent>Channel for sending user-space events (progress, sub-agent, structured).
Tools should use emit_user_event() or emit_progress().
llm_client: Option<Arc<dyn LlmProvider>>§session_store: Option<Arc<dyn SessionStore>>§language: LanguageLanguage preference for tool output.
Defaults to Language::En if not set.
cancel_token: CancellationTokenCancellation token for checking if the operation should be cancelled.
max_output_chars: Option<usize>Output budget for this call, in characters (set from the engine’s
max_tool_output_chars). Tools that can return large results (e.g.
read_file) should self-truncate to this bound and mark the cut, so
the engine’s hard reject (§6.5) never fires for a paginated read.
exec_clock: ExecClockExecution clock for this call — see ExecClock. Pause it while the
tool waits on a human (ToolContext::pause_execution_clock).
Implementations§
Source§impl ToolContext
impl ToolContext
Sourcepub fn pause_execution_clock(&self) -> ExecPauseGuard
pub fn pause_execution_clock(&self) -> ExecPauseGuard
Pause this call’s execution clock for as long as the guard lives.
Call this while waiting on a human (a confirmation popup, a login): the pipeline’s tool timeout does not count the paused stretch.
Sourcepub fn emit_user_event(&self, event: UserEvent)
pub fn emit_user_event(&self, event: UserEvent)
Send a user-space event (progress, sub-agent forwarding, structured data).
Dual-write: the event goes to user_event_tx (the tool select arm
renders it in real time) and to the event bus for external subscribers
(bridge remote clients, persistence). The bus copy carries agent_id: None — the self-echo marker — so bus loopback drops it instead of
re-rendering (see crate::engine::runtime::is_self_echo_user_event).
Sourcepub fn emit_progress(&self, text: impl Into<String>)
pub fn emit_progress(&self, text: impl Into<String>)
Convenience: send a progress event with text.
Sourcepub fn emit_partial_result(
&self,
tool_call_id: &str,
content: impl Into<String>,
is_partial: bool,
)
pub fn emit_partial_result( &self, tool_call_id: &str, content: impl Into<String>, is_partial: bool, )
Convenience: emit a partial result during long-running tool execution.
is_partial: true means more output is coming; false means final.
Sourcepub fn for_test() -> Self
pub fn for_test() -> Self
Test-only constructor: a ToolContext with a disconnected event
channel and no LLM/session backends. Lets downstream tests drop their
bespoke dummy_ctx() helpers.
Sourcepub fn new(
session_id: SessionId,
llm_client: Option<Arc<dyn LlmProvider>>,
session_store: Option<Arc<dyn SessionStore>>,
cancel_token: CancellationToken,
) -> Self
pub fn new( session_id: SessionId, llm_client: Option<Arc<dyn LlmProvider>>, session_store: Option<Arc<dyn SessionStore>>, cancel_token: CancellationToken, ) -> Self
Host-side constructor for host-initiated tool execution outside the engine loop (e.g. a REPL driving a tool through the same approval path as the engine). User events are accepted but dropped — there is no engine event loop to render them.