feat(agent): enhance streaming diagnostics and event tracking

- Added diagnostics for streaming events in the AgentEngine, including chunk counts and response type distributions.
- Implemented logging for emitted event types during the thinking process to aid in debugging and performance analysis.
- Updated the session handler to provide more informative warnings when fallback answers are emitted due to non-streaming behavior.
- Introduced a dedicated HTTP client for Ollama to improve connection handling and timeout management during streaming calls.
This commit is contained in:
wizardchen
2026-03-24 16:26:23 +08:00
committed by lyingbug
parent 1c9503b063
commit 2b56c4fbac
5 changed files with 78 additions and 12 deletions
+11 -1
View File
@@ -227,7 +227,17 @@ func (c *OllamaChat) ChatStream(
Done: false,
}
// Extract and stream content from special tools (complete, not incremental)
// Ollama returns tool calls as complete objects (not incremental deltas).
// Log this so we can trace non-streaming answer delivery.
for _, tc := range resp.Message.ToolCalls {
if tc.Function.Name == "final_answer" || tc.Function.Name == "thinking" {
argsBytes, _ := json.Marshal(tc.Function.Arguments)
logger.Warnf(ctx, "[Ollama Stream] Tool %q arrived non-incrementally (%d bytes args), "+
"answer will not be token-streamed to frontend",
tc.Function.Name, len(argsBytes))
}
}
for _, tc := range resp.Message.ToolCalls {
switch tc.Function.Name {
case "final_answer":