Skip to main content

FnTool

Struct FnTool 

Source
pub struct FnTool { /* private fields */ }
Expand description

A tool from a closure, for the common case where implementing Tool is more than needed. Read-only unless FnTool::side_effecting says otherwise.

Implementations§

Source§

impl FnTool

Source

pub fn new( name: impl Into<String>, description: impl Into<String>, parameters: Value, run: impl Fn(&Map<String, Value>, &ToolContext) -> Result<String, String> + Send + Sync + 'static, ) -> Self

A tool named name (letters, digits, _, -), described to the model by description, taking arguments matching the JSON Schema parameters.

Source

pub fn side_effecting(self) -> Self

Mark the tool as having effects outside the conversation, so every call goes through the approval gate.

Trait Implementations§

Source§

impl Tool for FnTool

Source§

fn name(&self) -> &str

Source§

fn description(&self) -> &str

Source§

fn side_effecting(&self) -> bool

True if invoking the tool causes an external side effect (gated by approvals).
Source§

fn parameters(&self) -> Value

The JSON Schema of the arguments, exactly as Python’s pydantic models advertise it.
Source§

fn execute( &self, args: &Map<String, Value>, ctx: &ToolContext, ) -> Result<ToolResult, ToolError>

Run the tool. ToolResult::call_id may be left empty; Tool::run fills it in.
Source§

fn parallel_safe(&self) -> bool

False for a tool that must not share a parallel batch even though it is read-only, such as one that can reach the approval prompt.
Source§

fn expands_secrets(&self) -> bool

Beyond Python: whether ${secret:NAME} in this tool’s string arguments is replaced by the user’s secret when it runs (crate::vault). Only for tools that put a value where the user can see and approve it (a file write), never one that would carry it onto a command line or to a server.
Source§

fn retry_hint(&self) -> Option<&str>

Beyond Python (ADR 0006): what to tell a model whose calls to this tool have twice in a row sent arguments that did not parse, after the loop’s own advice. For a tool whose arguments can grow large, how to send them in smaller pieces.
Source§

fn preview( &self, _args: &Map<String, Value>, _ctx: &ToolContext, ) -> Option<String>

What this call would do, shown in the approval prompt before it runs (a unified diff for a file write). Receives the raw, unvalidated arguments and must never fail; None means the argument summary says it all.
Source§

fn guarded_target( &self, _args: &Map<String, Value>, _ctx: &ToolContext, ) -> Option<String>

Beyond Python: the path this call would write if it is agent86’s own configuration or skills ([SandboxPolicy::guarded]), as the model gave it. Such a write changes what agent86 runs from then on, so the approval gate asks about it even in auto mode, and declines it with nobody to ask. Receives the raw arguments and must never fail.
Source§

fn change( &self, _args: &Map<String, Value>, _ctx: &ToolContext, ) -> Option<FileChange>

Beyond Python: the file text this call would change, before and after, for a surface that shows a reviewable diff (an editor over ACP). Receives the raw arguments (already expanded, for a tool that Tool::expands_secrets) and must never fail; None when the call would not change a text file, or when either side is over [MAX_CHANGE_TEXT_BYTES].
Source§

fn preview_lexer(&self) -> Option<&'static str>

What Tool::preview is written in (diff, bash, python), as Python’s preview_lexer, so the interface can colour it.
Source§

fn spec(&self) -> ToolSpec

Advertise this tool to the model.
Source§

fn run(&self, call: &ToolCall, ctx: &ToolContext) -> ToolResult

Execute call, translating every failure into a structured result.

Auto Trait Implementations§

§

impl !RefUnwindSafe for FnTool

§

impl !UnwindSafe for FnTool

§

impl Forget for FnTool

§

impl Freeze for FnTool

§

impl Move for FnTool

§

impl Send for FnTool

§

impl Sync for FnTool

§

impl Unpin for FnTool

§

impl UnsafeUnpin for FnTool

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> 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, 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