diff options
Diffstat (limited to 'libpanto/src/agent.zig')
| -rw-r--r-- | libpanto/src/agent.zig | 23 |
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"); |
