Prompt Caching: Top-Level cache_control im Request-Body

This commit is contained in:
Meleki committed 2026-02-28 17:16:58 +01:00
1 parent 52e9ef7f9e
commit 92072f5064
3 files changed
+14 -33

No files matched your search

+1 -3
View File
@@ -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<object>
{
new { type = "text", text = systemPromptText, cache_control = new { type = "ephemeral" } }
new { type = "text", text = systemPromptText }
};
var workspace = session.Workspace;
+2 -1
View File
@@ -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);
+11 -29
View File
@@ -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<string, object>
{
type = "object",
properties = new Dictionary<string, object>
{
["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<string, object>
{
["command"] = new { type = "string", description = "Shell-Befehl zum Ausführen" }
},
required = new[] { "command" }
}
required = new[] { "command" }
}
}
};
}