fix: fix title generation

Kujtim Hoxha created

Change summary

internal/llm/agent/agent.go | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)

Detailed changes

internal/llm/agent/agent.go 🔗

@@ -163,7 +163,9 @@ func (a *agent) generateTitle(ctx context.Context, sessionID string, content str
 		return err
 	}
 	parts := []message.ContentPart{message.TextContent{Text: content}}
-	response, err := a.titleProvider.SendMessages(
+
+	// Use streaming approach like summarization
+	response := a.titleProvider.StreamResponse(
 		ctx,
 		[]message.Message{
 			{
@@ -173,11 +175,20 @@ func (a *agent) generateTitle(ctx context.Context, sessionID string, content str
 		},
 		make([]tools.BaseTool, 0),
 	)
-	if err != nil {
-		return err
+
+	var finalResponse *provider.ProviderResponse
+	for r := range response {
+		if r.Error != nil {
+			return r.Error
+		}
+		finalResponse = r.Response
+	}
+
+	if finalResponse == nil {
+		return fmt.Errorf("no response received from title provider")
 	}
 
-	title := strings.TrimSpace(strings.ReplaceAll(response.Content, "\n", " "))
+	title := strings.TrimSpace(strings.ReplaceAll(finalResponse.Content, "\n", " "))
 	if title == "" {
 		return nil
 	}