diff options
Diffstat (limited to 'libpanto')
| -rw-r--r-- | libpanto/src/agent.zig | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/libpanto/src/agent.zig b/libpanto/src/agent.zig index 0252af6..24bc2cf 100644 --- a/libpanto/src/agent.zig +++ b/libpanto/src/agent.zig @@ -1162,6 +1162,25 @@ pub const Stream = struct { }; } + /// Reset a `.failed` stream back to `.turn_start` so the caller can resume + /// `next()` after changing the agent config (e.g. an embedder that catches + /// a terminal `ProviderBadRequest`, rewrites the provider config, and + /// wants to retry the SAME turn without re-appending the user message). + /// + /// Safe only at the OPEN boundary: a failed open never mutates the + /// conversation, so the already-committed user prompt at `_start` stays + /// intact and the re-open re-reads the (now-swapped) config snapshot. + /// Returns `error.StreamNotFailed` if the stream is not in `.failed`. + pub fn reopen(self: *Stream) !void { + if (self.state != .failed) return error.StreamNotFailed; + if (self._response) |ps| { + ps.deinit(); + self._response = null; + } + self._pending_error = null; + self.state = .turn_start; + } + /// Pull the next event, or null past the terminal. See the contract /// above. pub fn next(self: *Stream) !?Event { |
