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
impl FnTool
Sourcepub 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
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.
Sourcepub fn side_effecting(self) -> Self
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
impl Tool for FnTool
fn name(&self) -> &str
fn description(&self) -> &str
Source§fn side_effecting(&self) -> bool
fn side_effecting(&self) -> bool
True if invoking the tool causes an external side effect (gated by approvals).
Source§fn parameters(&self) -> Value
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>
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
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
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>
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>
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>
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>
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>
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 run(&self, call: &ToolCall, ctx: &ToolContext) -> ToolResult
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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