diff --git a/pkg/tools/registry.go b/pkg/tools/registry.go index d37a093a8..f44c4f70f 100644 --- a/pkg/tools/registry.go +++ b/pkg/tools/registry.go @@ -7,6 +7,7 @@ import ( "sync" "time" + "github.com/sipeed/picoclaw/pkg/audit" "github.com/sipeed/picoclaw/pkg/logger" "github.com/sipeed/picoclaw/pkg/providers" ) @@ -61,6 +62,8 @@ func (r *ToolRegistry) ExecuteWithContext( map[string]any{ "tool": name, }) + // Audit the error + audit.LogError(ctx, "tool_not_found", fmt.Sprintf("tool %q not found", name), true) return ErrorResult(fmt.Sprintf("tool %q not found", name)).WithError(fmt.Errorf("tool not found")) } @@ -105,6 +108,17 @@ func (r *ToolRegistry) ExecuteWithContext( }) } + // Audit logging + ctx = audit.WithChannelContext(ctx, channel, chatID, "") + audit.LogToolCall(ctx, &audit.ToolCallData{ + ToolID: name, + Name: name, + Arguments: args, + Result: result.ForLLM, + IsError: result.IsError, + IsAsync: result.Async, + }, duration.Milliseconds()) + return result }