pub struct ToolRegistry { /* private fields */ }Implementations§
Source§impl ToolRegistry
impl ToolRegistry
pub fn new() -> Self
Sourcepub fn register<A, F, Fut>(
&mut self,
name: &str,
description: &str,
read_only: bool,
handler: F,
)where
A: DeserializeOwned + JsonSchema + Send + 'static,
F: Fn(Arc<dyn Sandbox>, A) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<ToolOutcome, String>> + Send + 'static,
pub fn register<A, F, Fut>(
&mut self,
name: &str,
description: &str,
read_only: bool,
handler: F,
)where
A: DeserializeOwned + JsonSchema + Send + 'static,
F: Fn(Arc<dyn Sandbox>, A) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<ToolOutcome, String>> + Send + 'static,
注册一个工具。read_only 标记它是否无副作用 —— 只读工具之间可被并发调度
(见 core::tool_execution 的分段执行),任何会改动 sandbox 的工具都必须传 false。
handler 统一返回 ToolOutcome(普通完成用 Value.into(),需要用户交互用 NeedsUserInteraction)。
pub fn register_tool<A, F, Fut>(&mut self, spec: ToolSpec, handler: F)where
A: DeserializeOwned + JsonSchema + Send + 'static,
F: Fn(Arc<dyn Sandbox>, A) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<ToolOutcome, String>> + Send + 'static,
Sourcepub fn register_with_ctx<A, F, Fut>(
&mut self,
name: &str,
description: &str,
read_only: bool,
handler: F,
)where
A: DeserializeOwned + JsonSchema + Send + 'static,
F: Fn(Arc<dyn Sandbox>, A, ToolCtx) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<ToolOutcome, String>> + Send + 'static,
pub fn register_with_ctx<A, F, Fut>(
&mut self,
name: &str,
description: &str,
read_only: bool,
handler: F,
)where
A: DeserializeOwned + JsonSchema + Send + 'static,
F: Fn(Arc<dyn Sandbox>, A, ToolCtx) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<ToolOutcome, String>> + Send + 'static,
pub fn register_with_ctx_tool<A, F, Fut>(&mut self, spec: ToolSpec, handler: F)where
A: DeserializeOwned + JsonSchema + Send + 'static,
F: Fn(Arc<dyn Sandbox>, A, ToolCtx) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<ToolOutcome, String>> + Send + 'static,
Sourcepub fn is_read_only(&self, name: &str) -> bool
pub fn is_read_only(&self, name: &str) -> bool
工具是否声明为只读。未知工具按非只读处理(最保守,强制串行)。
Sourcepub fn subset<S: AsRef<str>>(&self, names: &[S]) -> ToolRegistry
pub fn subset<S: AsRef<str>>(&self, names: &[S]) -> ToolRegistry
派生一个只含给定名字的子集 registry,完整保留各工具的 callable/schema/异步策略。
未知名字静默忽略——调用方若需校验可先用 contains。
用于按能力边界裁剪某个(子)agent 可见的工具集。
Sourcepub async fn call(
&self,
name: &str,
args: Value,
sandbox: Arc<dyn Sandbox>,
ctx: ToolCtx,
) -> Result<ToolOutcome, String>
pub async fn call( &self, name: &str, args: Value, sandbox: Arc<dyn Sandbox>, ctx: ToolCtx, ) -> Result<ToolOutcome, String>
按名字调度执行,执行时注入该会话绑定的 sandbox 与 ToolCtx。
Sourcepub fn definitions(&self) -> Vec<ToolDefinition>
pub fn definitions(&self) -> Vec<ToolDefinition>
将工具 struct 转成 ToolDefinition 列表
Trait Implementations§
Source§impl Clone for ToolRegistry
impl Clone for ToolRegistry
Source§fn clone(&self) -> ToolRegistry
fn clone(&self) -> ToolRegistry
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for ToolRegistry
impl !UnwindSafe for ToolRegistry
impl Freeze for ToolRegistry
impl Send for ToolRegistry
impl Sync for ToolRegistry
impl Unpin for ToolRegistry
impl UnsafeUnpin for ToolRegistry
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