pub struct ToolContext {
pub working_directory: String,
pub user_id: Option<String>,
pub metadata: HashMap<String, String>,
pub capabilities: Option<Value>,
pub idempotency_registry: Option<IdempotencyRegistry>,
pub staging_backend: Option<Arc<dyn StagingBackend>>,
}Expand description
Execution context for a tool.
Provides the working directory, optional metadata, and permission capabilities to tool implementations.
Fields§
§working_directory: StringCurrent working directory for resolving relative paths
user_id: Option<String>User ID (if authenticated)
metadata: HashMap<String, String>Additional context data (application-specific key-value pairs)
capabilities: Option<Value>Agent capabilities for permission checks (serialized as JSON value).
Consumers should serialize their concrete capability types into this field and deserialize when reading. This keeps the core crate free of capability type definitions.
idempotency_registry: Option<IdempotencyRegistry>Per-run idempotency registry for mutating file operations.
When Some, write/delete/edit operations derive a content-addressed key
and skip re-execution if the same key has already been processed in this
run. None disables idempotency tracking (useful for tests or simple
single-call use cases).
staging_backend: Option<Arc<dyn StagingBackend>>Optional two-phase commit staging backend.
When Some, mutating file operations (write_file, edit_file,
patch_file) stage their writes instead of applying them immediately.
The caller is responsible for calling backend.commit() to finalize the
writes, or backend.rollback() to discard them.
Staging is checked after the idempotency registry: if the same operation key is already cached, the cached result is returned without staging again.
Implementations§
Source§impl ToolContext
impl ToolContext
Sourcepub fn with_idempotency_registry(self) -> Self
pub fn with_idempotency_registry(self) -> Self
Attach a fresh idempotency registry to this context (builder pattern).
Sourcepub fn with_staging_backend(self, backend: Arc<dyn StagingBackend>) -> Self
pub fn with_staging_backend(self, backend: Arc<dyn StagingBackend>) -> Self
Attach a staging backend for two-phase commit file writes (builder pattern).
Trait Implementations§
Source§impl Clone for ToolContext
impl Clone for ToolContext
Source§fn clone(&self) -> ToolContext
fn clone(&self) -> ToolContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more