v1.3 Registry 实现重构 + 第一把真实工具

- Registry 从纯接口升级为完整实现:Register/Execute/路由查找/错误自愈
- 新增 BaseTool 接口,统一工具契约
- 新增 ReadFileTool,首个真实工具实现(路径防穿越 + 截断保护)
- 新增 String() 方法,Registry/Engine 调试可视化
- 新增 ToolCall 执行状态日志
- cmd/claw 切换为真实 Registry + ReadFileTool
This commit is contained in:
zhuyongxin
2026-05-15 11:24:42 +08:00
parent daa89531f5
commit b94460083a
6 changed files with 240 additions and 53 deletions
+10
View File
@@ -29,6 +29,10 @@ func NewAgentEngine(p provider.LLMProvider, r tools.Registry, workDir string, en
}
}
func (e *AgentEngine) String() string {
return fmt.Sprintf("AgentEngine{workDir: %s, thinking: %v, registry: %s}", e.WorkDir, e.EnableThinking, e.registry)
}
// dumpMessages 打印当前上下文中的所有消息 (调试用)
func dumpMessages(msgs []schema.Message) {
for i, msg := range msgs {
@@ -142,6 +146,12 @@ func (e *AgentEngine) Run(ctx context.Context, userPrompt string) error {
result := e.registry.Execute(ctx, toolCall)
status := "✅ 成功"
if result.IsError {
status = "❌ 失败"
}
log.Printf(" -> 📋 ToolCall %s: %s, 结果: %s\n", toolCall.ID, status, result.Output)
if result.IsError {
log.Printf(" -> ❌ 工具执行报错: %s\n", result.Output)
} else {