Skip to main content

ToolContext

Struct ToolContext 

Source
pub struct ToolContext {
Show 17 fields pub policy: SandboxPolicy, pub executor: Executor, pub web: WebSettings, pub memory: Option<SessionStore>, pub skills: Arc<Skills>, pub secrets: SecretVault, pub editor: Option<Arc<dyn EditorFiles>>, pub specialties: Arc<Specialties>, pub scope: Option<Arc<ToolScope>>, pub can_delegate: bool, pub fanout: Option<Arc<FanOut>>, pub fresh_clients: bool, pub worktree: Option<Arc<Worktree>>, pub card: Option<Arc<Card>>, pub subagent: Option<Arc<SubagentRun>>, pub asker: Asker, pub ui: Option<Arc<UiSession>>, /* private fields */
}
Expand description

Ambient state handed to every tool at execution time.

Fields§

§policy: SandboxPolicy§executor: Executor

Where commands and Python snippets run.

§web: WebSettings

web_fetch settings.

§memory: Option<SessionStore>

Long-term memory for remember and recall; None when memory is off.

§skills: Arc<Skills>

The discovered skills, for use_skill.

§secrets: SecretVault

Secrets the user entered (beyond Python): set in tool processes’ environment, and redacted from every result. Shared by clones and sub-agent forks.

§editor: Option<Arc<dyn EditorFiles>>

The editor’s files, when an editor drives the agent. Shared by clones and sub-agent forks.

§specialties: Arc<Specialties>

The specialist sub-agents (beyond Python), for delegate and use_skill.

§scope: Option<Arc<ToolScope>>

What narrows this context (beyond Python): the specialty it runs, or one it was delegated from. Set once when a sub-agent is spawned (or for run --agent), never by the model, and checked with the active skill’s list.

§can_delegate: bool

Whether a use_skill hand-off to a specialty could be made from here: the harness delegates, delegate is offered at this depth, and this context may call it. Set by the harness.

§fanout: Option<Arc<FanOut>>

The fan-out this context’s sub-agent belongs to (beyond Python): siblings running at once share its spend and its stop. Inherited by forks, so a sibling’s own delegations stop with it.

§fresh_clients: bool

On a fan-out thread: every sub-agent here calls a provider copy with an HTTP client of its own (crate::provider::Provider::fresh).

§worktree: Option<Arc<Worktree>>

The git worktree this context is jailed to, when a specialty runs isolated; a delegation from inside asking for isolation is served by the same one.

§card: Option<Arc<Card>>

The card a sub-agent’s progress is reported on (beyond Python): the top-level delegation’s, which nested runs share.

§subagent: Option<Arc<SubagentRun>>

The sub-agent run this context belongs to (beyond Python), with its progress, so a question it asks can say who asks. Set when a sub-agent is spawned.

§asker: Asker

The hook ask_user asks the user through (beyond Python; ADR 0006), once a surface installs one. Shared by clones; sub-agent forks get an empty one, since only the main loop asks.

§ui: Option<Arc<UiSession>>

The renderer the embedder declared (beyond Python; ADR 0005), for render_ui: its catalogs and the surfaces drawn. Shared by clones; sub-agent forks have none, since only the main loop draws.

Implementations§

Source§

impl ToolContext

Source

pub fn new(workspace: &Path) -> Result<Self>

A context jailed to workspace.

Source

pub fn activate_skill(&self, skill: &Arc<Skill>)

Make skill the active one, replacing (never stacking on) any other.

Source

pub fn clear_skill(&self)

Lift the active skill’s restriction, as the end of a turn does.

Source

pub fn fork(&self) -> Self

A copy for a sub-agent: the same tools and jail, and its own active skill, starting as this context’s, so what it activates restricts only itself. It draws no UI and asks the user nothing: only the main loop has the renderer and the ask_user hook.

Source

pub fn active_skill(&self) -> Option<Arc<Skill>>

Source

pub fn scope_allows(&self, name: &str) -> bool

Whether the specialty this context runs under (if any) permits name.

Source

pub fn allowed_tool(&self, name: &str) -> bool

Whether name may be called now, given the active skill’s allowed-tools. use_skill always may: it is how the model switches skills, and a skill that forgot to list it would otherwise be a one-way door.

Trait Implementations§

Source§

impl Clone for ToolContext

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ToolContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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, !>

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