Skip to main content

ExecutableTool

Struct ExecutableTool 

Source
pub struct ExecutableTool {
    pub definition: ToolDefinition,
    pub safety: ParallelSafety,
    pub category: Option<ToolCategory>,
    /* private fields */
}
Expand description

可执行的工具 — 定义 + 安全元数据 + 执行器。

ToolDefinition 的区别:

  • ToolDefinition:纯数据,Provider 序列化发送给 LLM
  • ExecutableTool:可执行,Agent 调用时查找并执行

与运行时(lellm-agent)的区别:

  • ExecutableTool:描述“这个工具能做什么 + 怎么执行“,但不负责调度
  • ToolExecutor / ToolCatalog / ToolSnapshot:负责 lookup, dispatch, retry, parallel

用户通过 ExecutableTool::safe() 等工厂方法构造, 或由 #[tool] 宏自动生成。

Fields§

§definition: ToolDefinition

工具定义(纯元数据,可被 Provider 序列化)

§safety: ParallelSafety

并行安全级别

§category: Option<ToolCategory>

工具类别(仅 CategoryExclusive 时使用)

Implementations§

Source§

impl ExecutableTool

Source

pub fn definition(&self) -> &ToolDefinition

获取工具定义的引用。

Source

pub fn safety(&self) -> &ParallelSafety

获取并行安全级别。

Source

pub fn category(&self) -> Option<&ToolCategory>

获取工具类别(如果有)。

Source

pub fn execute( &self, args: &Value, ) -> Pin<Box<dyn Future<Output = ToolResult> + Send>>

执行工具调用,返回未来对象。

Source

pub fn from_fn( def: ToolDefinition, safety: ParallelSafety, category: Option<ToolCategory>, f: ToolFn, ) -> Self

从原始执行函数构造。

用于 MCP bridge 等需要直接控制执行函数的场景。

Source

pub fn safe<F, Fut>(def: ToolDefinition, f: F) -> Self
where F: Fn(&Value) -> Fut + Send + Sync + 'static, Fut: Future<Output = ToolResult> + Send + 'static,

并行安全(Safe)工具注册。

Source

pub fn category_exclusive<F, Fut>( def: ToolDefinition, category: ToolCategory, f: F, ) -> Self
where F: Fn(&Value) -> Fut + Send + Sync + 'static, Fut: Future<Output = ToolResult> + Send + 'static,

分类内互斥(CategoryExclusive)工具注册。

Source

pub fn exclusive<F, Fut>(def: ToolDefinition, f: F) -> Self
where F: Fn(&Value) -> Fut + Send + Sync + 'static, Fut: Future<Output = ToolResult> + Send + 'static,

全局互斥(Exclusive)工具注册。

Source

pub fn safe_fn<T, F, Fut>(def: ToolDefinition, f: F) -> Self
where T: ToolArgs + Send + 'static, F: Fn(T) -> Fut + Send + Sync + 'static, Fut: Future<Output = ToolResult> + Send + 'static,

强类型便捷构造 — 自动反序列化参数(Safe)。

闭包接收反序列化后的 T,而非原始 serde_json::Value。 反序列化失败时返回 ToolErrorKind::InvalidInput

Source

pub fn category_exclusive_fn<T, F, Fut>( def: ToolDefinition, category: ToolCategory, f: F, ) -> Self
where T: ToolArgs + Send + 'static, F: Fn(T) -> Fut + Send + Sync + 'static, Fut: Future<Output = ToolResult> + Send + 'static,

强类型便捷构造 — 自动反序列化参数(CategoryExclusive)。

Source

pub fn exclusive_fn<T, F, Fut>(def: ToolDefinition, f: F) -> Self
where T: ToolArgs + Send + 'static, F: Fn(T) -> Fut + Send + Sync + 'static, Fut: Future<Output = ToolResult> + Send + 'static,

强类型便捷构造 — 自动反序列化参数(Exclusive)。

Trait Implementations§

Source§

impl Clone for ExecutableTool

Source§

fn clone(&self) -> ExecutableTool

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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