Skip to main content

AgentToolState

Struct AgentToolState 

Source
pub struct AgentToolState {
Show 25 fields pub writes: Arc<WriteBudget>, pub builtins: Arc<BuiltinTools>, pub mcp: Arc<Mutex<ToolExecutor>>, pub builtin_names: HashSet<String>, pub launch_overrides: Arc<HashMap<String, ToolPolicy>>, pub safe_keys: Arc<HashSet<String>>, pub run_allows: Arc<Mutex<HashSet<String>>>, pub stage_allows: Arc<Mutex<HashSet<String>>>, pub stage_allows_index: Arc<Mutex<Option<usize>>>, pub stage_perms: Arc<Mutex<HashMap<String, String>>>, pub stage_perms_by_index: Arc<Vec<HashMap<String, String>>>, pub stage_required: Arc<Mutex<HashSet<String>>>, pub stage_required_by_index: Arc<Vec<HashSet<String>>>, pub agent_perms: Arc<HashMap<String, String>>, pub global_perms: Arc<HashMap<String, ToolPolicy>>, pub blueprint_may_loosen: bool, pub interaction: HubInteractionBackend, pub unattended: bool, pub stage_name: Arc<Mutex<String>>, pub subagent: Option<SubAgentHandle>, pub sandbox: Option<Arc<SandboxManager>>, pub script_tools: Arc<Mutex<ScriptToolSet>>, pub script_tool_names: Arc<Mutex<HashSet<String>>>, pub script_host: Arc<dyn ScriptHost>, pub dynamic: Option<Arc<DynamicToolCtx>>,
}
Expand description

Everything one agent needs to execute a tool call: the executors, its policy layers, and its interaction backend. All fields are cheap Arcs so a clone is moved into each exec_for closure. The stage-scoped fields (stage_perms/stage_name) are shared handles the host updates as the agent changes stage.

Fields§

§writes: Arc<WriteBudget>

The write ceilings in effect, and what this run has spent of them.

Shared rather than copied because the running total has to survive across every batch this run makes - a per-run budget that reset per batch would bound nothing.

§builtins: Arc<BuiltinTools>

Built-in tool executor (holds the agent’s workdir).

§mcp: Arc<Mutex<ToolExecutor>>

MCP tool executor.

§builtin_names: HashSet<String>

Names of the built-in tools (dispatch routes builtin vs MCP).

§launch_overrides: Arc<HashMap<String, ToolPolicy>>

--yolo / --allow / --ask / --deny launch overrides.

§safe_keys: Arc<HashSet<String>>

Keys that need no prompt at all: the shipped safe list plus whatever the user’s [safe_commands] adds. Resolved once at spawn and never mutated, so reading it needs no lock.

Unlike a grant, a safe entry matches by program as well as exactly: naming cat covers cat notes.md, because otherwise it would cover nothing anybody runs. See crate::shell_keys::program_of.

§run_allows: Arc<Mutex<HashSet<String>>>

Grant keys the user allowed for the rest of the run.

§stage_allows: Arc<Mutex<HashSet<String>>>

Grant keys the user allowed for the current stage only, cleared by sync_stage when the run moves to a different stage.

A std mutex rather than the async one run_allows uses, because sync_stage is synchronous and clearing a grant must happen on the same tick the stage changes. Every read here is a contains with no await held, so the two lock kinds never contend for longer than a lookup.

§stage_allows_index: Arc<Mutex<Option<usize>>>

The stage index stage_allows was granted under, so re-entering the same stage (a plan -> plan revision loop) keeps its grants while moving on drops them.

§stage_perms: Arc<Mutex<HashMap<String, String>>>

The current stage’s tool_permissions - re-synced by sync_stage on each stage change (a std mutex so the sync system can update it synchronously).

§stage_perms_by_index: Arc<Vec<HashMap<String, String>>>

Every stage’s tool_permissions, indexed by stage index; sync_stage copies the entered stage’s map into stage_perms.

§stage_required: Arc<Mutex<HashSet<String>>>

The current stage’s required_tools - the human-in-the-loop tools it keeps through an unattended run. Re-synced by sync_stage, and read on every interaction so a kept tool reaches a real person instead of UnattendedInteraction. Empty for an attended run, where nothing is dropped and nothing needs keeping.

§stage_required_by_index: Arc<Vec<HashSet<String>>>

Every stage’s required_tools, indexed by stage index.

§agent_perms: Arc<HashMap<String, String>>

Blueprint-level [tool_permissions].

§global_perms: Arc<HashMap<String, ToolPolicy>>

Config-level tool permissions.

§blueprint_may_loosen: bool

[security] allow_blueprint_permissions: whether this manifest’s [tool_permissions] may exceed the built-in default for a tool the user has not configured. See BLUEPRINT_LOOSENABLE in crate::tools.

§interaction: HubInteractionBackend

The agent’s interaction backend (ask_user + tool approvals).

§unattended: bool

--yolo: nobody is watching this run, so the tools that block on a person are not advertised at all. Should one be called anyway, it is answered by UnattendedInteraction rather than parked on the hub for ever - unless the stage kept it in required_tools, in which case a real prompt is exactly what the blueprint asked for.

§stage_name: Arc<Mutex<String>>

The current stage name, for tagging interactions (re-synced on stage change).

§subagent: Option<SubAgentHandle>

Handle for the sub-agent tools (spawn/check/wait/send/kill), or None when this agent can’t reach the host (e.g. in unit tests).

§sandbox: Option<Arc<SandboxManager>>

The agent’s sandbox manager, or None when no stage is sandboxed. Held here so sync_stage can point it at the entered stage’s sandbox; the same Arc is also an ECS component (for teardown at reap) and is wired into builtins as the shell tool’s executor.

§script_tools: Arc<Mutex<ScriptToolSet>>

The agent’s discovered Rhai script tools, compiled at spawn. Behind a mutex so a dynamic_tools agent’s mid-run re-scan can swap the set in place; static agents never mutate it.

§script_tool_names: Arc<Mutex<HashSet<String>>>

Names of the script tools, for routing dispatch to the Rhai executor. Mutable alongside script_tools on a dynamic re-scan.

§script_host: Arc<dyn ScriptHost>

The host functions script tools call, with [tool_script_permissions] enforcement (Layer 3) already baked in.

§dynamic: Option<Arc<DynamicToolCtx>>

Present only for dynamic_tools agents: everything needed to re-discover and re-advertise this agent’s tools mid-run.

Trait Implementations§

Source§

impl Clone for AgentToolState

Source§

fn clone(&self) -> AgentToolState

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

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> ConditionalSend for T
where T: Send,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
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> IntoResult<T> for T

Source§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
Source§

impl<A> Is for A
where A: Any,

Source§

fn is<T>() -> bool
where T: Any,

Checks if the current type “is” another type, using a TypeId equality comparison. This is most useful in the context of generic logic. 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 = Infallible

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<T> TypeData for T
where T: 'static + Send + Sync + Clone,

Source§

fn clone_type_data(&self) -> Box<dyn TypeData>

Creates a type-erased clone of this value.
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