From 92072f5064914a74bb48df99140b9f789ce79683 Mon Sep 17 00:00:00 2001 From: Meleki Date: Sat, 28 Feb 2026 17:16:58 +0100 Subject: [PATCH] Prompt Caching: Top-Level cache_control im Request-Body --- Endpoints/ChatEndpoint.cs | 4 +--- Services/AnthropicService.cs | 3 ++- Services/ToolService.cs | 40 ++++++++++-------------------------- 3 files changed, 14 insertions(+), 33 deletions(-) diff --git a/Endpoints/ChatEndpoint.cs b/Endpoints/ChatEndpoint.cs index 0f934b9..25eb4c0 100644 --- a/Endpoints/ChatEndpoint.cs +++ b/Endpoints/ChatEndpoint.cs @@ -142,11 +142,9 @@ public static class ChatEndpoint }, attachmentRecords); } - // cache_control markiert den System-Prompt als Cache-Breakpoint. - // Anthropic cached alles bis einschließlich dieses Blocks für 5 Minuten → 90% Rabatt auf diese Tokens. var systemPrompt = new List { - new { type = "text", text = systemPromptText, cache_control = new { type = "ephemeral" } } + new { type = "text", text = systemPromptText } }; var workspace = session.Workspace; diff --git a/Services/AnthropicService.cs b/Services/AnthropicService.cs index 0d39db0..d460956 100644 --- a/Services/AnthropicService.cs +++ b/Services/AnthropicService.cs @@ -60,13 +60,14 @@ public class AnthropicService { ["model"] = modelId, ["max_tokens"] = 16384, + ["cache_control"] = new { type = "ephemeral" }, ["system"] = systemPrompt, ["messages"] = messages, ["stream"] = true }; if (!string.IsNullOrEmpty(workspace)) - payload["tools"] = _toolService.GetToolDefinitions(markLastAsCached: true); + payload["tools"] = _toolService.GetToolDefinitions(); var client = CreateClient(); var json = JsonSerializer.Serialize(payload); diff --git a/Services/ToolService.cs b/Services/ToolService.cs index f29f5a0..d0324a3 100644 --- a/Services/ToolService.cs +++ b/Services/ToolService.cs @@ -11,7 +11,7 @@ namespace Gott.Services; public class ToolService { - public object[] GetToolDefinitions(bool markLastAsCached = false) + public object[] GetToolDefinitions() { return new object[] { @@ -88,38 +88,20 @@ public class ToolService required = new[] { "path" } } }, - // Letztes Tool bekommt cache_control – Anthropic cached alles bis einschließlich - // dieses Breakpoints (System-Prompt + alle Tool-Definitionen) für 5 Minuten. - markLastAsCached - ? (object)new + new + { + name = "execute", + description = "Führt einen Shell-Befehl im Workspace-Verzeichnis aus. Gibt stdout und stderr zurück. Timeout: 30 Sekunden.", + input_schema = new { - name = "execute", - description = "Führt einen Shell-Befehl im Workspace-Verzeichnis aus. Gibt stdout und stderr zurück. Timeout: 30 Sekunden.", - input_schema = new + type = "object", + properties = new Dictionary { - type = "object", - properties = new Dictionary - { - ["command"] = new { type = "string", description = "Shell-Befehl zum Ausführen" } - }, - required = new[] { "command" } + ["command"] = new { type = "string", description = "Shell-Befehl zum Ausführen" } }, - cache_control = new { type = "ephemeral" } - } - : new - { - name = "execute", - description = "Führt einen Shell-Befehl im Workspace-Verzeichnis aus. Gibt stdout und stderr zurück. Timeout: 30 Sekunden.", - input_schema = new - { - type = "object", - properties = new Dictionary - { - ["command"] = new { type = "string", description = "Shell-Befehl zum Ausführen" } - }, - required = new[] { "command" } - } + required = new[] { "command" } } + } }; }