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>,
/* 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.
Implementations§
Source§impl ToolContext
impl ToolContext
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() -> ToolContext
pub fn for_test() -> ToolContext
Test-only constructor: a ToolContext with a disconnected event
channel and no LLM/session backends. Lets downstream tests drop their
bespoke dummy_ctx() helpers.
Trait Implementations§
Source§impl Clone for ToolContext
impl Clone for ToolContext
Source§fn clone(&self) -> ToolContext
fn clone(&self) -> ToolContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more