pub struct ToolContext {
pub working_dir: PathBuf,
pub is_subagent: bool,
pub session_id: Option<String>,
pub values: HashMap<String, Value>,
pub timeout_config: Option<ToolTimeoutConfig>,
pub cancel_token: Option<CancellationToken>,
pub diagnostic_provider: Option<Arc<dyn DiagnosticProvider>>,
pub shared_state: Option<Arc<Mutex<HashMap<String, Value>>>>,
}Expand description
Execution context passed to tool handlers.
Carries session state, configuration, and working directory so tools can resolve paths, check permissions, and access shared resources.
Fields§
§working_dir: PathBufWorking directory for path resolution.
is_subagent: boolWhether the caller is a subagent (may restrict some operations).
session_id: Option<String>Optional session ID for session-scoped operations.
values: HashMap<String, Value>Arbitrary context values for tool-specific needs.
timeout_config: Option<ToolTimeoutConfig>Optional per-tool timeout overrides.
cancel_token: Option<CancellationToken>Cancellation token for cooperative interrupt from the UI.
diagnostic_provider: Option<Arc<dyn DiagnosticProvider>>Optional LSP diagnostic provider for post-edit feedback.
Shared mutable state across tool executions within a react loop. Used for cross-iteration state like planning phase transitions.
Implementations§
Source§impl ToolContext
impl ToolContext
Sourcepub fn new(working_dir: impl Into<PathBuf>) -> Self
pub fn new(working_dir: impl Into<PathBuf>) -> Self
Create a new tool context with a working directory.
Relative paths (including .) are resolved to absolute paths using
std::env::current_dir() and then canonicalized. Absolute paths
are stored as-is to avoid changing paths in tests.
Sourcepub fn with_cancel_token(self, token: CancellationToken) -> Self
pub fn with_cancel_token(self, token: CancellationToken) -> Self
Set a cancellation token for cooperative interrupt.
Sourcepub fn with_subagent(self, is_subagent: bool) -> Self
pub fn with_subagent(self, is_subagent: bool) -> Self
Set the subagent flag.
Sourcepub fn with_session_id(self, session_id: impl Into<String>) -> Self
pub fn with_session_id(self, session_id: impl Into<String>) -> Self
Set the session ID.
Sourcepub fn with_value(self, key: impl Into<String>, value: Value) -> Self
pub fn with_value(self, key: impl Into<String>, value: Value) -> Self
Insert a context value.
Sourcepub fn with_diagnostic_provider(
self,
provider: Arc<dyn DiagnosticProvider>,
) -> Self
pub fn with_diagnostic_provider( self, provider: Arc<dyn DiagnosticProvider>, ) -> Self
Set a diagnostic provider for post-edit LSP feedback.
Sourcepub fn with_timeout_config(self, config: ToolTimeoutConfig) -> Self
pub fn with_timeout_config(self, config: ToolTimeoutConfig) -> Self
Set timeout configuration.
Set shared mutable state for cross-iteration communication.
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