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
+13 -2
View File
@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"net"
"net/http"
"net/url"
"os"
@@ -40,8 +41,18 @@ func GetOllamaService() (*OllamaService, error) {
return nil, fmt.Errorf("invalid Ollama service URL: %w", err)
}
// Create official client
client := api.NewClient(parsedURL, http.DefaultClient)
// Dedicated HTTP client for Ollama instead of http.DefaultClient.
// - Dial timeout prevents hanging when Ollama process is down or port unreachable
// - No overall Timeout so long-running streaming calls are controlled by context cancellation
ollamaHTTPClient := &http.Client{
Transport: &http.Transport{
DialContext: (&net.Dialer{Timeout: 10 * time.Second}).DialContext,
TLSHandshakeTimeout: 10 * time.Second,
IdleConnTimeout: 90 * time.Second,
MaxIdleConns: 10,
},
}
client := api.NewClient(parsedURL, ollamaHTTPClient)
// Check if Ollama is set as optional
isOptional := false