summaryrefslogtreecommitdiff
path: root/libpanto/src/anthropic_messages_json.zig
diff options
context:
space:
mode:
Diffstat (limited to 'libpanto/src/anthropic_messages_json.zig')
-rw-r--r--libpanto/src/anthropic_messages_json.zig16
1 files changed, 14 insertions, 2 deletions
diff --git a/libpanto/src/anthropic_messages_json.zig b/libpanto/src/anthropic_messages_json.zig
index d382de8..c54db86 100644
--- a/libpanto/src/anthropic_messages_json.zig
+++ b/libpanto/src/anthropic_messages_json.zig
@@ -79,10 +79,12 @@ pub fn serializeRequest(
try s.endArray();
}
- // Emit messages (everything that isn't .system).
+ // Emit messages (everything that isn't .system). If the conversation
+ // has been compacted, only the latest compaction summary and the
+ // messages after it are active; the superseded prefix is dropped.
try s.objectField("messages");
try s.beginArray();
- for (conv.messages.items) |msg| {
+ for (conversation.activeMessageWindow(conv.messages.items)) |msg| {
if (msg.role == .system) continue;
try writeMessage(&s, msg, allocator);
}
@@ -239,6 +241,16 @@ fn writeBlock(s: *std.json.Stringify, block: conversation.ContentBlock) !void {
// system text is hoisted into the top-level `system` string by
// `collectSystemPrompt`. Present only to keep the switch exhaustive.
.System => {},
+ // A compaction summary is the synthetic seed text standing in for
+ // a compacted prefix; the model reads it as ordinary user text.
+ .CompactionSummary => |cs| {
+ try s.beginObject();
+ try s.objectField("type");
+ try s.write("text");
+ try s.objectField("text");
+ try s.write(cs.text.items);
+ try s.endObject();
+ },
}
}