From 81ddb61dcfcc9bc85585f262bf303e1a9da507b0 Mon Sep 17 00:00:00 2001 From: t Date: Fri, 19 Jun 2026 14:53:03 -0600 Subject: libpanto fixes - ensuring stream.next() sequences are interruptible - Agent.run() takes any user message, not just chat text --- libpanto/src/turn_persist.zig | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'libpanto/src/turn_persist.zig') diff --git a/libpanto/src/turn_persist.zig b/libpanto/src/turn_persist.zig index 1dacfec..6d260c8 100644 --- a/libpanto/src/turn_persist.zig +++ b/libpanto/src/turn_persist.zig @@ -45,13 +45,29 @@ pub fn persistTurn( start_index: usize, identity: WireIdentity, tools: []const ToolDecl, +) !void { + return persistRange(alloc, session, conv, start_index, conv.messages.items.len, identity, tools); +} + +/// Persist conversation messages in `[start_index, end_index)`. Like +/// `persistTurn` but with an explicit upper bound, so an incremental flush can +/// exclude a trailing not-yet-coherent message (a dangling tool call awaiting +/// its results) while still committing everything before it. +pub fn persistRange( + alloc: Allocator, + session: *Session, + conv: *conversation.Conversation, + start_index: usize, + end_index: usize, + identity: WireIdentity, + tools: []const ToolDecl, ) !void { var batch: std.ArrayList(PersistentMessage) = .empty; defer batch.deinit(alloc); const all_messages = conv.messages.items; var i = start_index; - while (i < all_messages.len) : (i += 1) { + while (i < end_index) : (i += 1) { const msg = &all_messages[i]; if (msg.role == .assistant and hasToolUseWithoutFollowingResults(conv, i)) { continue; -- cgit v1.3