From 632424fb7386c2c9b1cbe89da7611e0e2c43f20b Mon Sep 17 00:00:00 2001 From: Meleki Date: Sun, 1 Mar 2026 15:19:56 +0100 Subject: [PATCH] =?UTF-8?q?Memory-Tools=20unabh=C3=A4ngig=20vom=20Workspac?= =?UTF-8?q?e=20verf=C3=BCgbar=20machen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Tools werden jetzt auch gesendet wenn kein Workspace aber useMemory=true - GetToolDefinitions(includeFileTools, includeMemory) für granulare Steuerung - File-Tools geben saubere Fehlermeldung wenn workspace null --- Services/AnthropicService.cs | 8 +++++--- Services/ToolService.cs | 28 ++++++++++++++++++---------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/Services/AnthropicService.cs b/Services/AnthropicService.cs index d9f0af0..f52c4e8 100644 --- a/Services/AnthropicService.cs +++ b/Services/AnthropicService.cs @@ -71,10 +71,12 @@ public class AnthropicService ["stream"] = true }; - if (!string.IsNullOrEmpty(workspace)) + var hasWorkspace = !string.IsNullOrEmpty(workspace); + var includeMemory = useMemory && _memoryService != null && !string.IsNullOrEmpty(agentId); + + if (hasWorkspace || includeMemory) { - var includeMemory = useMemory && _memoryService != null && !string.IsNullOrEmpty(agentId); - payload["tools"] = _toolService.GetToolDefinitions(includeMemory); + payload["tools"] = _toolService.GetToolDefinitions(includeFileTools: hasWorkspace, includeMemory: includeMemory); // "any" erzwingt Tool-Nutzung, aber nur in der ersten Iteration, // damit Claude nicht endlos Tools aufruft wenn die Aufgabe erledigt ist. var effectiveChoice = (toolChoice == "any" && iterations == 1) ? "any" : "auto"; diff --git a/Services/ToolService.cs b/Services/ToolService.cs index f785047..aae7328 100644 --- a/Services/ToolService.cs +++ b/Services/ToolService.cs @@ -11,18 +11,14 @@ namespace Gott.Services; public class ToolService { - public object[] GetToolDefinitions(bool includeMemory = false) + public object[] GetToolDefinitions(bool includeFileTools = false, bool includeMemory = false) { - var tools = GetFileTools(); + var allTools = new List(); + if (includeFileTools) + allTools.AddRange(GetFileTools()); if (includeMemory) - { - var memTools = GetMemoryToolDefinitions(); - var all = new object[tools.Length + memTools.Length]; - tools.CopyTo(all, 0); - memTools.CopyTo(all, tools.Length); - return all; - } - return tools; + allTools.AddRange(GetMemoryToolDefinitions()); + return allTools.ToArray(); } private object[] GetFileTools() @@ -176,6 +172,8 @@ public class ToolService { case "read_file": { + if (string.IsNullOrEmpty(workspace)) + return "Fehler: Kein Workspace konfiguriert"; var path = ResolvePath(input.GetProperty("path").GetString() ?? "", workspace); if (!File.Exists(path)) return $"Fehler: Datei nicht gefunden: {Path.GetRelativePath(workspace, path)}"; @@ -183,6 +181,8 @@ public class ToolService } case "write_file": { + if (string.IsNullOrEmpty(workspace)) + return "Fehler: Kein Workspace konfiguriert"; var path = ResolvePath(input.GetProperty("path").GetString() ?? "", workspace); var dir = Path.GetDirectoryName(path); if (dir != null) Directory.CreateDirectory(dir); @@ -192,6 +192,8 @@ public class ToolService } case "edit_file": { + if (string.IsNullOrEmpty(workspace)) + return "Fehler: Kein Workspace konfiguriert"; var path = ResolvePath(input.GetProperty("path").GetString() ?? "", workspace); if (!File.Exists(path)) return $"Fehler: Datei nicht gefunden: {Path.GetRelativePath(workspace, path)}"; @@ -206,6 +208,8 @@ public class ToolService } case "list_files": { + if (string.IsNullOrEmpty(workspace)) + return "Fehler: Kein Workspace konfiguriert"; var path = ResolvePath(input.TryGetProperty("path", out var p) ? p.GetString() ?? "" : "", workspace); if (!Directory.Exists(path)) return $"Fehler: Verzeichnis nicht gefunden: {Path.GetRelativePath(workspace, path)}"; @@ -218,6 +222,8 @@ public class ToolService } case "delete_file": { + if (string.IsNullOrEmpty(workspace)) + return "Fehler: Kein Workspace konfiguriert"; var path = ResolvePath(input.GetProperty("path").GetString() ?? "", workspace); if (File.Exists(path)) { @@ -233,6 +239,8 @@ public class ToolService } case "execute": { + if (string.IsNullOrEmpty(workspace)) + return "Fehler: Kein Workspace konfiguriert"; var command = input.GetProperty("command").GetString() ?? ""; var psi = new ProcessStartInfo {