From bb85e867bc938138f29fb45230169af1ba60761c Mon Sep 17 00:00:00 2001 From: t Date: Wed, 10 Jun 2026 10:06:07 -0600 Subject: Add addUserText helper; update all call sites Conversation.addUserMessage now takes a []ContentBlock (symmetric with addAssistantMessage). Introduce a thin addUserText wrapper in agent.zig for the plain-text case and update every call site in agent.zig and anthropic_messages_json.zig accordingly. --- libpanto/src/openai_chat_json.zig | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'libpanto/src/openai_chat_json.zig') diff --git a/libpanto/src/openai_chat_json.zig b/libpanto/src/openai_chat_json.zig index b30b424..8af939f 100644 --- a/libpanto/src/openai_chat_json.zig +++ b/libpanto/src/openai_chat_json.zig @@ -535,6 +535,16 @@ fn emptyTools() tool_registry_mod.ToolRegistry { return tool_registry_mod.ToolRegistry.init(testing.allocator); } +/// Test helper: append a single-text user message. `addUserMessage` now +/// takes a block slice (symmetric with `addAssistantMessage`); this wraps +/// the common plain-text case the tests below use. +fn addUserText(conv: *conversation.Conversation, text: []const u8) !void { + const tb = try conversation.textualBlockFromSlice(conv.allocator, text); + var block: conversation.ContentBlock = .{ .Text = tb }; + errdefer block.deinit(conv.allocator); + try conv.addUserMessage(&.{block}); +} + test "serializeRequest - system + user" { const allocator = testing.allocator; @@ -542,7 +552,7 @@ test "serializeRequest - system + user" { defer conv.deinit(); try conv.addSystemMessage("You are helpful."); - try conv.addUserMessage("Hello!"); + try addUserText(&conv, "Hello!"); const cfg = testConfig("gpt-4o"); var tools = emptyTools(); @@ -576,9 +586,9 @@ test "serializeRequest - multiple system blocks hoisted as separate leading mess defer conv.deinit(); try conv.addSystemMessage("seed"); - try conv.addUserMessage("Hello!"); + try addUserText(&conv, "Hello!"); try conv.addSystemMessage("mid-conversation append"); - try conv.addUserMessage("again"); + try addUserText(&conv, "again"); const cfg = testConfig("gpt-4o"); var tools = emptyTools(); @@ -611,7 +621,7 @@ test "serializeRequest - replace-mode system block wipes prior system messages" try conv.addSystemMessage("original"); try conv.replaceSystemMessage("fresh seed"); try conv.addSystemMessage("fresh append"); - try conv.addUserMessage("Hi"); + try addUserText(&conv, "Hi"); const cfg = testConfig("gpt-4o"); var tools = emptyTools(); @@ -663,7 +673,7 @@ test "serializeRequest - reasoning effort level included when set" { var conv = conversation.Conversation.init(allocator); defer conv.deinit(); - try conv.addUserMessage("Hi"); + try addUserText(&conv, "Hi"); var cfg = testConfig("gpt-4o"); cfg.reasoning = .high; @@ -687,7 +697,7 @@ test "serializeRequest - reasoning .off sends \"none\"" { var conv = conversation.Conversation.init(allocator); defer conv.deinit(); - try conv.addUserMessage("Hi"); + try addUserText(&conv, "Hi"); var cfg = testConfig("gpt-4o"); cfg.reasoning = .off; @@ -798,7 +808,7 @@ test "serializeRequest - emits tools array when registry non-empty" { var conv = conversation.Conversation.init(allocator); defer conv.deinit(); - try conv.addUserMessage("call something"); + try addUserText(&conv, "call something"); var tools = emptyTools(); defer tools.deinit(); @@ -833,7 +843,7 @@ test "serializeRequest - dotted tool name is wire-encoded with __" { var conv = conversation.Conversation.init(allocator); defer conv.deinit(); - try conv.addUserMessage("go"); + try addUserText(&conv, "go"); var tools = emptyTools(); defer tools.deinit(); @@ -1050,14 +1060,14 @@ test "serializeRequest - compaction summary trims superseded prefix" { // System prompt survives compaction. try conv.addSystemMessage("you are helpful"); // Old prefix that must be dropped. - try conv.addUserMessage("ancient question"); + try addUserText(&conv, "ancient question"); try conv.addAssistantMessage(&.{ .{ .Text = try conversation.textualBlockFromSlice(allocator, "ancient answer") }, }, null); // Compaction summary resets conversation context. try conv.addCompactionSummary("summary of the ancient exchange"); // Kept-verbatim suffix replayed after the summary. - try conv.addUserMessage("recent question"); + try addUserText(&conv, "recent question"); var tools = emptyTools(); defer tools.deinit(); -- cgit v1.3