You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
func (t*MyTool) InvokableRun(ctx context.Context, argsstring) (string, error) {
order, err:=t.db.GetOrder(ctx, id)
iferr!=nil {
returntoolutil.Fail("ORDER_NOT_FOUND", "order does not exist", false,
"Confirm the order ID with the user or call list_orders")
}
returntoolutil.OK(order)
}
LLM 收到的是可直接用于决策的结构化内容:
{
"success": false,
"error": {
"code": "ORDER_NOT_FOUND",
"message": "order ORD-999 does not exist",
"retryable": false,
"suggestion": "Confirm the order ID with the user or call list_orders"
}
}
问题描述
当前
InvokableTool接口返回(string, error),对字符串结果没有任何结构约束。这意味着 Tool 的错误信息是非结构化的自由文本,LLM 无法据此做出可靠的决策。
社区中已有真实案例(见 #432):当 Tool 返回 Go
error时,react Agent 直接停止,报错如下:LLM 完全看不到这个错误——它在框架层就被终止了。
即便错误以字符串形式传回给 LLM,LLM 也无法判断:
问题根因
这个问题分两层:
InvokableRun返回 Goerror导致 Agent 直接中止(相关:Is it possible to make react Agent to go on calling other tools or end with a summary when tool calling returns an error? #432)本提案解决第二层——提供一个标准结构化返回格式,
让 Tool 开发者能够写出对 LLM 友好的错误信息。
提案
在
eino-ext中新增toolutil包,提供标准结构体和 helper 函数。不修改任何现有接口,纯粹向后兼容的新增。
结构定义
Helper 函数
Tool 使用示例
LLM 收到的是可直接用于决策的结构化内容:
{ "success": false, "error": { "code": "ORDER_NOT_FOUND", "message": "order ORD-999 does not exist", "retryable": false, "suggestion": "Confirm the order ID with the user or call list_orders" } }动机
Tool 的错误信息应该是为 LLM 设计的,而不是为开发者设计的。
retryable和suggestion字段让 Agent 拥有足够的上下文做出正确决策,而不是凭空猜测恢复路径。
实现范围
eino-ext/components/tool/util如果 maintainer 认可这个方向,我可以负责实现。
相关 Issue