Skip to main content

ToolContext

Struct ToolContext 

Source
pub struct ToolContext<'a> {
    pub agent_id: String,
    pub tool_call_id: String,
    pub tool_name: String,
    /* private fields */
}
Expand description

Execution context made available to a running tool.

Fields§

§agent_id: String§tool_call_id: String§tool_name: String

Implementations§

Source§

impl ToolContext<'_>

Source

pub fn working_directory(&self) -> &Path

Source

pub fn child_run_options(&self) -> RunOptions

RunOptions for a run this tool spawns, derived from the options of the run this tool is executing under — see RunOptions::child for what a child inherits and what it resets.

Thread these into the spawned run’s own Agent::run call. A subagent driven on RunOptions::default() instead gets a fresh, unbounded token counter, so its spend escapes the parent’s token_budget and a parent cancel, stop, or deadline never reaches it.

Source

pub fn emit_progress(&self, progress: String)

Emit a progress event for the currently executing tool.

Source

pub fn agent_name(&self) -> &str

Source

pub fn model(&self) -> &str

Source

pub fn history_len(&self) -> usize

Source

pub fn tasks(&self) -> &[TaskItem]

Source

pub fn resolve_working_directory( &self, working_directory: Option<&str>, ) -> Result<PathBuf, String>

Source

pub fn load_skill(&self, name: &str) -> Result<String, String>

Source

pub fn skill_descriptions(&self) -> Option<String>

Source

pub fn app_context<T>(&self) -> Result<Arc<T>, String>
where T: Any + Send + Sync + 'static,

Source

pub async fn execute_shell_command( &self, command: String, justification: Option<String>, requested_timeout: Option<Duration>, cwd: PathBuf, ) -> Result<ExecOutput, String>

Runs one command on the local executor.

Source

pub async fn execute_shell_command_on( &self, target: Option<String>, command: String, justification: Option<String>, requested_timeout: Option<Duration>, cwd: PathBuf, ) -> Result<ExecOutput, String>

Runs one command on the executor the host named.

A tool that lets its caller say where a command runs passes the name here; None is the local executor. The name reaches the installed crate::runtime::RuntimeExecutor on the request and is interpreted only there, so a tool can route a command without gaining any way to route around the policy that authorized it.

Source

pub fn start_background_task( &self, command: String, justification: Option<String>, requested_timeout: Option<Duration>, cwd: PathBuf, ) -> Result<BackgroundTaskSummary, String>

Source

pub fn check_background_task( &self, task_id: Option<&str>, ) -> Result<String, String>

Source

pub fn request_idle(&mut self)

Source

pub async fn compact_history( &mut self, ) -> Result<Option<CompactionDetails>, RuntimeError>

Source

pub fn execute_task_tool( &self, tool: &TaskIntrinsicTool, input: Value, ) -> Result<String, String>

Source

pub fn refresh_tasks(&mut self) -> Result<(), RuntimeError>

Source

pub async fn read_file( &self, path: &str, max_lines: Option<usize>, ) -> Result<String, String>

Source

pub fn spawn_subagent(&self) -> Result<Agent, RuntimeError>

Source

pub fn disposable_subagent_template(&self) -> DisposableSubagentTemplate

A template cloned from this agent’s own config exactly as it stands at this call — the same snapshot spawn_subagent takes when it is called — for a caller that wants to override the child’s tool profile, model, or system prompt before spawning it via spawn_subagent_from. A later change to this agent (e.g. set_model) does not reach back into a template already taken.

Source

pub async fn spawn_subagent_from( &self, template: DisposableSubagentTemplate, ) -> Result<Agent, RuntimeError>

Spawns through the agent’s source-verifying template path.

Source

pub fn register_subagent(&mut self, agent: &Agent) -> SpawnedAgentSummary

Records a spawned subagent and announces it on the parent’s stream.

Emitting is part of registering here, where for the task intrinsic the two are separate calls: a tool that registered a child without announcing it left the child in the parent’s snapshot and absent from every observer’s view of it, and there is no reason a caller would want that. The event is the same SubagentSpawned the intrinsic emits.

Source

pub fn finish_subagent( &mut self, id: &str, status: SpawnedAgentStatus, ) -> Option<SpawnedAgentSummary>

Marks a subagent finished and announces it on the parent’s stream.

The other half of register_subagent. Returns None — and announces nothing — when no subagent under id was registered.

Source

pub fn relay_subagent_usage(&self, child: &Agent) -> AgentEventTapGuard

Relays a child agent’s token usage onto this agent’s event stream.

A subagent has its own event bus, so an observer watching the parent sees none of what a delegated run spent — while that spend still counts against the parent’s token_budget. Relaying UsageReport keeps the parent’s stream summing to the same total the accounting reports.

The returned guard must outlive the child’s run: dropping it stops the relay, so binding it to _ ends it immediately.

Source

pub fn relay_subagent_events( &self, child: &Agent, filter: impl Fn(&AgentEvent) -> bool + Send + Sync + 'static, ) -> AgentEventTapGuard

Relays the child agent’s events that filter accepts onto this agent’s stream.

The general form of relay_subagent_usage, for a tool that wants a delegated run’s tool calls or text visible to whoever is watching the parent. Relaying everything means a parent’s observer sees two interleaved runs, so the filter is the parameter rather than a default.

The returned guard must outlive the child’s run.

Source

pub fn record_delegation_request( &mut self, content: impl Into<String>, delegation: DelegationArtifact, edge: Option<DelegationEdge>, ) -> Result<(), RuntimeError>

Records a delegation this tool performed in the parent’s transcript.

Delegation entries are what a transcript reader follows to reconstruct who asked whom for what. Only the task intrinsic could write them, so a tool that delegated work its own way left no trace of the delegation — the result appeared in the transcript with nothing saying where it came from.

Source

pub fn record_delegation_result( &mut self, content: impl Into<String>, delegation: DelegationArtifact, edge: Option<DelegationEdge>, ) -> Result<(), RuntimeError>

Records the outcome of a delegation this tool performed.

The other half of record_delegation_request: the request says what was asked and this says what came back, and a reader following the edges needs both.

Source

pub async fn spawn_teammate( &mut self, name: impl Into<String>, role: impl Into<String>, prompt: Option<String>, ) -> Result<TeamMemberSummary, RuntimeError>

Source

pub fn send_team_message( &self, to: &str, content: impl Into<String>, ) -> Result<TeamDispatch, RuntimeError>

Source

pub fn broadcast_team_message( &self, content: impl Into<String>, ) -> Result<Vec<TeamDispatch>, RuntimeError>

Source

pub fn read_team_inbox(&self) -> Result<Vec<TeamMessage>, RuntimeError>

Source

pub fn request_team_protocol( &self, to: &str, protocol: impl Into<String>, content: impl Into<String>, ) -> Result<TeamProtocolRequestSummary, RuntimeError>

Source

pub fn respond_team_protocol( &self, request_id: &str, approve: bool, reason: Option<String>, ) -> Result<TeamProtocolRequestSummary, RuntimeError>

Trait Implementations§

Source§

impl From<ToolContext<'_>> for ParallelToolContext

Source§

fn from(ctx: ToolContext<'_>) -> ParallelToolContext

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for ToolContext<'a>

§

impl<'a> !UnwindSafe for ToolContext<'a>

§

impl<'a> Freeze for ToolContext<'a>

§

impl<'a> Send for ToolContext<'a>

§

impl<'a> Sync for ToolContext<'a>

§

impl<'a> Unpin for ToolContext<'a>

§

impl<'a> UnsafeUnpin for ToolContext<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more