From cdad7faad4f1cd0f4e592532a417d5a9d2f5e610 Mon Sep 17 00:00:00 2001 From: Meleki Date: Mon, 9 Mar 2026 09:40:30 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20tool=5Fend=20SSE-Event=20nicht=20mehr=20?= =?UTF-8?q?auf=20500=20Zeichen=20k=C3=BCrzen=20+=20tool=5Fresult=20History?= =?UTF-8?q?-Truncation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - tool_end SSE-Event: 500-Zeichen-Limit entfernt (2 Stellen), damit todo_write und andere Tools beim Streaming vollständig angezeigt werden - BuildHistoryFromDb: TruncateToolResult (20k) auf tool_result-Messages angewendet, um Token-Overflow bei History-Rebuild zu verhindern (609k Tokens > 200k Limit nach awaiting_user_choice) - TruncateToolResult/MaxToolResultChars auf internal geändert - TODO.md: todo_write-Bug als erledigt markiert --- Services/AnthropicService.cs | 8 ++++---- Services/ChatService.cs | 4 ++-- TODO.md | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Services/AnthropicService.cs b/Services/AnthropicService.cs index 5df2681..c9be2bf 100644 --- a/Services/AnthropicService.cs +++ b/Services/AnthropicService.cs @@ -741,7 +741,7 @@ public class AnthropicService toolName, toolId, input = toolInput.ToString(), - result = toolResult.Length > 500 ? toolResult[..500] + "..." : toolResult, + result = toolResult, isError, agentName }, cancellationToken); @@ -1195,7 +1195,7 @@ public class AnthropicService { name = currentToolName, input = currentToolInputJson.ToString(), - result = toolResult.Length > 500 ? toolResult[..500] + "..." : toolResult, + result = toolResult, isError }, cancellationToken); } @@ -1293,9 +1293,9 @@ public class AnthropicService // ── Shared Helpers ── - private const int MaxToolResultChars = 20_000; + internal const int MaxToolResultChars = 20_000; - private static string TruncateToolResult(string result) + internal static string TruncateToolResult(string result) { return result.Length > MaxToolResultChars ? result[..MaxToolResultChars] + $"\n\n[... gekürzt, {result.Length - MaxToolResultChars} weitere Zeichen ...]" diff --git a/Services/ChatService.cs b/Services/ChatService.cs index 037d29f..aa60b24 100644 --- a/Services/ChatService.cs +++ b/Services/ChatService.cs @@ -370,7 +370,7 @@ Für welche Plattform soll die App entwickelt werden? Web, Mobile oder Desktop? dict.TryGetValue("role", out var role) && role.ToString() == "user" && dict.TryGetValue("content", out var existingContent) && existingContent is List contentList) { - contentList.Add(new { type = "tool_result", tool_use_id = msg.ToolCallId, content = msg.Content ?? "", is_error = msg.IsError }); + contentList.Add(new { type = "tool_result", tool_use_id = msg.ToolCallId, content = AnthropicService.TruncateToolResult(msg.Content ?? ""), is_error = msg.IsError }); } else { @@ -379,7 +379,7 @@ Für welche Plattform soll die App entwickelt werden? Web, Mobile oder Desktop? ["role"] = "user", ["content"] = new List { - new { type = "tool_result", tool_use_id = msg.ToolCallId, content = msg.Content ?? "", is_error = msg.IsError } + new { type = "tool_result", tool_use_id = msg.ToolCallId, content = AnthropicService.TruncateToolResult(msg.Content ?? ""), is_error = msg.IsError } } }); } diff --git a/TODO.md b/TODO.md index d93054f..f2c9291 100644 --- a/TODO.md +++ b/TODO.md @@ -23,7 +23,7 @@ - [x] Größere Tasks brechen irgendwann ab, könnte an der Limitierung von Antrophic/Claude liegen. Jedoch sollte wird es scheinbar nicht behandelt: Der Status bleibt auf "Streaming..." aber es passiert nichts mehr - [x] Session -> Chat öffnen im Frontend soll nicht möglich sein, wenn kein Agent gesetzt ist - [x] Falsche Nachrichtenanzahl im Dashboard (tool uses werden fälschicherweise mitgezählt) - dasselbe bei "Ältere Nachrichten laden" im Chat -- [ ] Beim Benutzen vom Tool "todo_write": beim streamen ist der text abgeschnitten (limitiert), nach dem poll (history laden) passt es wieder. es soll beim stream auch vollständig angezeigt werden und nicht mit "..." enden +- [x] Beim Benutzen vom Tool "todo_write": beim streamen ist der text abgeschnitten (limitiert), nach dem poll (history laden) passt es wieder. es soll beim stream auch vollständig angezeigt werden und nicht mit "..." enden - [ ] Manchmal passiert es wenn ein Agent die Memory-Funktion hat, dass er sich selbst Memories einträgt - das ist auch ok so, aber, manchmal werden "dumme" erinnerungen gesetzt, die nur session-bezogen sind (und nicht agent-bezogen) und diese sind dann fast immer einfach nur copy&paste aus dem session system-prompt. Woran kann das liegen bzw. wie kann man das optimieren? ## Backend