summaryrefslogtreecommitdiff
path: root/libpanto/src/agent.zig
diff options
context:
space:
mode:
authort <t@tjp.lol>2026-06-07 14:49:20 -0600
committert <t@tjp.lol>2026-06-07 14:49:20 -0600
commit1eddee33902757f7e06993825a3ad1011e7ec346 (patch)
tree37671194f5b15f542cfcb8ed69b46bc21196afa5 /libpanto/src/agent.zig
parent11818552dad254649af012df3b4277633943d2b6 (diff)
Plug the deep-embedder holes; remove public.zig escape hatch
Close the gap that forced the CLI to import internal libpanto namespaces, then delete the transitional re-exports. The CLI now uses only the curated public surface. Additions to the public Agent facade: - init/deinit (heap-pin the inner; the handle is a copyable value). - addSystemMessage (.append) and setSystemPrompt (.replace). - compact(override_system_prompt, extra) falling back to the config prompt. - sessionId() accessor. CompactionConfig gains compaction_prompt, which owns the compaction system prompt for both auto-compaction and the explicit compact() default; the Agent.compaction_system_prompt field is deleted. ConversationData is the public name for the owned conversation value type (Session.load returns it, Agent.init adopts it), distinct from the borrowed Conversation handle. Agent.addSystemMessage/setSystemPrompt are kept on Agent (they persist with the SystemMode) rather than dropped as the plan first proposed.
Diffstat (limited to 'libpanto/src/agent.zig')
-rw-r--r--libpanto/src/agent.zig23
1 files changed, 12 insertions, 11 deletions
diff --git a/libpanto/src/agent.zig b/libpanto/src/agent.zig
index 5f9bee5..6d62b8a 100644
--- a/libpanto/src/agent.zig
+++ b/libpanto/src/agent.zig
@@ -206,11 +206,6 @@ pub const Agent = struct {
/// Injectable streaming seam. Defaults to the real provider dispatch
/// (`provider_mod.openStream`); tests override it with a stub.
open_stream_fn: provider_mod.OpenStreamFn = provider_mod.openStream,
- /// Compaction system prompt used for automatic compaction on context
- /// overflow. Borrowed; set by the embedder (resolved from its
- /// `COMPACTION.md` layers). When null, auto-compaction is disabled and
- /// a context-overflow error propagates unchanged.
- compaction_system_prompt: ?[]const u8 = null,
/// Set by the embedder after `runStep` returns to learn whether an
/// automatic compaction occurred this turn (so it can persist the
/// rewritten conversation). Reset at the top of each `runStep`.
@@ -454,7 +449,7 @@ pub const Agent = struct {
err: anyerror,
) !provider_mod.ProviderStream {
if (self.auto_compacted) return err; // already retried once this turn
- const sys = self.compaction_system_prompt orelse return err;
+ const sys = self.config.compaction.compaction_prompt orelse return err;
const res = try self.compact(sys, null);
if (!res.compacted) return err; // nothing to shed; give up
self.auto_compacted = true;
@@ -595,11 +590,19 @@ pub const Agent = struct {
/// if anything was compacted, appends the new compaction window
/// (summary + restated kept suffix) to the store. Returns the same
/// `CompactionResult` for the embedder to report.
+ ///
+ /// `override_system_prompt`, when non-null, is the compaction system
+ /// prompt for this run; when null it falls back to
+ /// `config.compaction.compaction_prompt`. With neither set, this errors
+ /// (`error.NoCompactionPrompt`).
pub fn compactAndPersist(
self: *Agent,
- system_prompt: []const u8,
+ override_system_prompt: ?[]const u8,
extra_instructions: ?[]const u8,
) !CompactionResult {
+ const system_prompt = override_system_prompt orelse
+ self.config.compaction.compaction_prompt orelse
+ return error.NoCompactionPrompt;
const res = try self.compact(system_prompt, extra_instructions);
if (res.compacted) {
try turn_persist.persistCompaction(
@@ -2852,13 +2855,12 @@ test "runStep: auto-compacts on context overflow and retries once" {
var h = TestHarness.init(allocator);
defer h.deinit();
h.activate();
- h.config.compaction = .{ .keep_verbatim = 10 };
+ h.config.compaction = .{ .keep_verbatim = 10, .compaction_prompt = "Summarize the conversation." };
var ns = null_store_mod.NullStore.init(allocator);
var agent = Agent.init(allocator, io, &h.config, ns.store().create(), null);
defer agent.deinit();
h.seedInto(&agent);
agent.open_stream_fn = stub.install();
- agent.compaction_system_prompt = "Summarize the conversation.";
const conv = &agent.conversation;
try conv.addSystemMessage("you are helpful");
@@ -3233,13 +3235,12 @@ test "runStep: context-overflow compaction fires a compaction retry notification
var h = TestHarness.init(allocator);
defer h.deinit();
h.activate();
- h.config.compaction = .{ .keep_verbatim = 10 };
+ h.config.compaction = .{ .keep_verbatim = 10, .compaction_prompt = "Summarize the conversation." };
var ns = null_store_mod.NullStore.init(allocator);
var agent = Agent.init(allocator, io, &h.config, ns.store().create(), null);
defer agent.deinit();
h.seedInto(&agent);
agent.open_stream_fn = stub.install();
- agent.compaction_system_prompt = "Summarize the conversation.";
const conv = &agent.conversation;
try conv.addSystemMessage("you are helpful");