feat(audit): Phase 3 - Integrate audit logging with tools registry
Add audit logging to ExecuteWithContext: - Log all tool executions with args, result, duration - Log tool not found errors - Include channel context for request tracing - Works alongside existing structured logging The audit logs capture: - Tool name and ID - Arguments (JSON-serializable) - Result content - Error status and async status - Execution duration in milliseconds
This commit is contained in:
parent
ecfe936b1b
commit
19018a3107
1 changed files with 14 additions and 0 deletions
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue