pub struct ToolContext {
pub working_dir: PathBuf,
pub session_id: SessionId,
pub tool_call_id: String,
pub frontend: Arc<dyn Frontend>,
pub extensions: HashMap<String, Arc<dyn Any + Send + Sync>>,
pub supports_images: bool,
pub async_runner: AsyncTaskRunner,
pub cancel_token: CancellationToken,
pub task_registry: TaskRegistry,
}Expand description
Runtime context passed to tools during execution.
Fields§
§working_dir: PathBufCurrent working directory.
session_id: SessionIdCurrent session ID.
tool_call_id: StringThe tool call id this execution was triggered by. Needed by async tools to correlate their background task with the originating call.
frontend: Arc<dyn Frontend>Frontend for user interaction (e.g., asking for input during tool execution).
extensions: HashMap<String, Arc<dyn Any + Send + Sync>>Platform-specific extensions, keyed by extension ID.
Chatbot platforms populate this; GUI/TUI leave it empty.
Keys like “chatbot.platform_ext” map to Arc
supports_images: boolWhether the configured LLM supports image inputs.
Tools (e.g. read) use this to decide whether to encode images.
async_runner: AsyncTaskRunnerHandle for submitting async background work. A tool that decides (at
runtime) a call should run async calls async_runner.submit(..) and
returns ToolResult::pending(..). Cheap to clone.
cancel_token: CancellationTokenCancellation token for this tool call. Async tools pass a clone into
async_runner.submit so the Agent can cancel the background work.
Sync tools ignore it.
task_registry: TaskRegistryShared registry tracking all async tasks for the current Agent. The
query_task tool reads this; async tools register themselves here via
the Agent when they submit. Cheap to clone (shared Arc).