Skip to main content

FnTool

Struct FnTool 

Source
pub struct FnTool<F, Fut> { /* private fields */ }
Expand description

Build a tool from a closure. Handy for tests and small integrations.

use aidaemon_core::{FnTool, ToolAnnotations, ToolOutput, ToolSpec};
use serde_json::{json, Value};

let spec = ToolSpec {
    name: "echo".into(),
    description: "Echo the text back".into(),
    parameters: json!({"type": "object", "required": ["text"]}),
};
let echo = FnTool::new(spec, ToolAnnotations::READ_ONLY, |args: Value| async move {
    Ok(ToolOutput::text(args["text"].as_str().unwrap_or_default().to_string()))
});

Implementations§

Source§

impl<F, Fut> FnTool<F, Fut>
where F: Fn(Value) -> Fut + Send + Sync, Fut: Future<Output = Result<ToolOutput, ToolError>> + Send,

Source

pub fn new( spec: ToolSpec, annotations: ToolAnnotations, func: F, ) -> FnTool<F, Fut>

Source

pub fn with_trust(self, trust: SourceTrust) -> FnTool<F, Fut>

Declare the trust class of this tool’s output (default Untrusted).

Trait Implementations§

Source§

impl<F, Fut> Tool for FnTool<F, Fut>
where F: Fn(Value) -> Fut + Send + Sync, Fut: Future<Output = Result<ToolOutput, ToolError>> + Send,

Source§

fn spec(&self) -> ToolSpec

Source§

fn annotations(&self) -> ToolAnnotations

Source§

fn source_trust(&self, _arguments: &Value) -> SourceTrust

Who authored what this call returns. The default is Untrusted; a tool whose output is the owner’s own (a workspace file, the kernel’s bookkeeping) returns Trusted. A result may override this with ToolOutput::with_trust.
Source§

fn call<'life0, 'life1, 'async_trait>( &'life0 self, arguments: Value, _ctx: &'life1 ToolContext, ) -> Pin<Box<dyn Future<Output = Result<ToolOutput, ToolError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, FnTool<F, Fut>: 'async_trait,

Source§

fn annotations_for(&self, _arguments: &Value) -> ToolAnnotations

Annotations for one call. Tools whose effect depends on the arguments (a shell running ls versus rm) override this; the default is the tool-wide Tool::annotations. Read more
Source§

fn outbound(&self, _arguments: &Value) -> Outbound

What this call carries out of the machine if it only reads. The default says nothing does.
Source§

fn validate(&self, arguments: &Value) -> Result<(), String>

Deterministic argument checks, run before any policy or I/O. The kernel checks the arguments against the declared schema (check_arguments: required keys, types, enums, nested objects and array items) before calling this, whatever a tool does here, so an override only adds checks. The default is that schema check.
Source§

fn timeout(&self) -> Option<Duration>

How long this tool may run, overriding Limits::tool_timeout. Tools that take their own timeout argument (such as a shell) return a value at least as long as their own maximum.
Source§

fn access(&self, _arguments: &Value) -> AccessManifest

Declare what this call will touch. Optional; policies treat an empty manifest as undeclared.
Source§

fn effects(&self, arguments: &Value) -> CallEffects

The typed effects of this call (effect class and normalized target). The default is CallEffects::none for a call that is read-only and not egress (per Tool::annotations_for). Otherwise it is what the call’s declared Tool::access implies (CallEffects::from_access: a written path is a write effect, a host an egress effect), so an owner’s denial of the call binds the rest of the run; and CallEffects::unknown when it declares no access: a read from another host still sends the request off the machine, so a tool annotated egress should declare its host or its EffectKey::egress target. Recomputed after a hook rewrites the arguments.
Source§

fn concurrent_peers(&self) -> usize

How many calls of this tool may run together in one batch although the tool is not read-only: 0 (the default) runs each call alone. A tool returns more only when it coordinates the shared state its concurrent calls touch itself (sub-agents whose writes a coordination ledger arbitrates). Calls queued this way still run after every earlier call in the batch has been judged, and before any later call that is not concurrent-safe.
Source§

fn suspends(&self) -> bool

Whether this tool may answer with ToolOutput::suspended. A call of such a tool always runs alone, because a run pauses on one call at a time.
Source§

fn resume_child<'life0, 'life1, 'async_trait>( &'life0 self, _child: RunState, _resolution: Resolution, _ctx: &'life1 ToolContext, ) -> Pin<Box<dyn Future<Output = Result<ToolOutput, ToolError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Continue the child run this tool suspended, with the answer to its interruption, and return what Tool::call would have returned: a result, or ToolOutput::suspended if the child paused again. Read more

Auto Trait Implementations§

§

impl<F, Fut> Forget for FnTool<F, Fut>

§

impl<F, Fut> Freeze for FnTool<F, Fut>
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze, PhantomData<Value>: Freeze, *const LeafNode<String, Value> is !null: Freeze, PhantomData<(Owned, LeafOrInternal)>: Freeze, PhantomData<Box<(String, Value)>>: Freeze, F: Freeze, PhantomData<fn() -> Fut>: Freeze,

§

impl<F, Fut> Move for FnTool<F, Fut>

§

impl<F, Fut> RefUnwindSafe for FnTool<F, Fut>
where F: RefUnwindSafe,

§

impl<F, Fut> Send for FnTool<F, Fut>
where F: Send, RawVecInner: Send, NodeRef<Owned, String, Value, LeafOrInternal>: Send, BoxRaw<(String, Value)>: Send,

§

impl<F, Fut> Sync for FnTool<F, Fut>
where F: Sync, RawVecInner: Sync, NodeRef<Owned, String, Value, LeafOrInternal>: Sync, BoxRaw<(String, Value)>: Sync,

§

impl<F, Fut> Unpin for FnTool<F, Fut>
where F: Unpin, *const u8 is !null: Unpin, *const LeafNode<String, Value> is !null: Unpin, Box<(String, Value)>: Unpin,

§

impl<F, Fut> UnsafeUnpin for FnTool<F, Fut>

§

impl<F, Fut> UnwindSafe for FnTool<F, Fut>
where RawVecInner: UnwindSafe, BTreeMap<String, Value>: UnwindSafe, F: UnwindSafe,

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