From 4e8508649eff8e17c9158181082408f15a063cec Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 30 Nov 2025 15:28:09 +0800 Subject: [PATCH] Add automatic ChunkID generation for messages in Send method - Implemented logic to auto-generate ChunkID for messages when not provided, enhancing message tracking. - Utilized IDGenerator if available; otherwise, fallback to message.GenerateNanoID for unique identification. - Improved message handling consistency by ensuring ChunkID is always set for non-event messages. --- agent/context/output.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/agent/context/output.go b/agent/context/output.go index e4534c4a..23683a60 100644 --- a/agent/context/output.go +++ b/agent/context/output.go @@ -39,6 +39,15 @@ func (ctx *Context) Send(msg *message.Message) error { } } + // === Auto-generate ChunkID (always) === + if msg.ChunkID == "" && !isEventMessage { + if ctx.IDGenerator != nil { + msg.ChunkID = ctx.IDGenerator.GenerateChunkID() + } else { + msg.ChunkID = message.GenerateNanoID() + } + } + // === Non-delta operations: New message logic === if !msg.Delta && !isEventMessage { // Auto-set ThreadID for non-root Stack (nested agent calls)