5.1 工具抽象层设计
5.1.1 Tool.Info 接口
Tool.Info 接口export interface Info<
Parameters extends z.ZodType = z.ZodType,
M extends Metadata = Metadata
> {
id: string // 工具的唯一标识符(如 "bash", "edit", "read")
init: (ctx?: InitContext) => Promise<{
description: string // 工具的功能描述(发送给 LLM)
parameters: Parameters // 参数的 Zod Schema
execute( // 执行函数
args: z.infer<Parameters>,
ctx: Context,
): Promise<{
title: string // 执行结果的简短标题
metadata: M // 元数据(如是否被截断)
output: string // 输出文本
attachments?: MessageV2.FilePart[] // 文件附件
}>
formatValidationError?(error: z.ZodError): string // 自定义参数错误信息
}>
}5.1.2 Tool.Context 上下文
Tool.Context 上下文5.1.3 Tool.define() 工厂函数
Tool.define() 工厂函数5.1.4 工具输出截断机制
Last updated
