From aedaea274d4824a7e60b473b47696dadfd8f0542 Mon Sep 17 00:00:00 2001 From: wizardchen Date: Tue, 24 Mar 2026 19:05:51 +0800 Subject: [PATCH] feat(agent): improve logging of LLM call messages to enhance clarity and reduce redundancy - Updated logging in the callLLMWithRetry function to summarize message details, limiting the output to the last few messages to avoid repetition. - Introduced a constant to define the maximum number of detailed messages logged, improving the readability of logs during LLM calls. --- internal/agent/think.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/agent/think.go b/internal/agent/think.go index 5cefda8d..621bf757 100644 --- a/internal/agent/think.go +++ b/internal/agent/think.go @@ -226,10 +226,18 @@ func (e *AgentEngine) callLLMWithRetry( ) (*types.ChatResponse, error) { round := iteration + 1 - // Log message summary at Debug level (per-message detail is noisy at Info) + // Log message summary; only detail the tail messages to avoid repeating what prior rounds already logged + const maxDetailMsgs = 4 logger.Infof(ctx, "[Agent][Round-%d] Calling LLM: %d messages, %d tools", round, len(messages), len(tools)) - for i, msg := range messages { + startIdx := 0 + if len(messages) > maxDetailMsgs { + startIdx = len(messages) - maxDetailMsgs + logger.Debugf(ctx, "[Agent][Round-%d] (skipping msg[0..%d], already logged in prior rounds)", + round, startIdx-1) + } + for i := startIdx; i < len(messages); i++ { + msg := messages[i] if msg.Role == "tool" { logger.Debugf(ctx, "[Agent][Round-%d] msg[%d]: role=tool, name=%s, len=%d", round, i, msg.Name, len(msg.Content))