feat(chat): implement orphan alias detection and logging in chat completion and streaming

Add functionality to detect unresolvable resource aliases emitted by the model during chat completion and streaming. Introduce logging for these orphan aliases to aid in debugging and improve the handling of resource references. Update the stream processing to ensure held aliases are flushed upon cancellation, preventing data loss. Include tests to verify the correct reporting of orphan aliases.
This commit is contained in:
wizardchen
2026-07-15 16:49:43 +08:00
committed by lyingbug
parent 6d14cc3536
commit 38c594aec3
6 changed files with 210 additions and 16 deletions
+4
View File
@@ -106,6 +106,10 @@ func (e *AgentEngine) streamLLMToEventBus(
// accumulated call in the final chunk. Decode once more after assembly so
// aliases split across provider chunks cannot leak into tool execution.
e.resourceRefs.DecodeToolCalls(result.ToolCalls)
if orphans := e.resourceRefs.OrphanAliases(result.Content); len(orphans) > 0 {
logger.Warnf(ctx, "[Agent][Stream] Model emitted %d unresolvable resource alias(es): %v",
len(orphans), orphans)
}
// Stream diagnostic summary: helps identify non-streaming patterns
streamDuration := time.Duration(0)