From ea4a3084e0ef3fc5eab58d10af82433090c1d34d Mon Sep 17 00:00:00 2001 From: Levi Neely <141506390+lneely@users.noreply.github.com> Date: Sun, 17 May 2026 10:15:24 +0200 Subject: [PATCH] session: add Checkpoint for typed subflow handoff --- pkg/agent/session.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pkg/agent/session.go b/pkg/agent/session.go index 513fa95..162b9de 100644 --- a/pkg/agent/session.go +++ b/pkg/agent/session.go @@ -133,6 +133,22 @@ func newSession(goal string) *Session { return &Session{goal: goal} } +// Checkpoint forks the session: returns a new Session that inherits the given +// TaskState but starts with a clean message history. This enables narrow-context +// sub-agents that know what to do without inheriting all parent message noise. +func (s *Session) Checkpoint(ts TaskState) *Session { + child := &Session{ + goal: ts.Objective, + TaskState: &ts, + } + // Seed with a user message so the child has a valid initial turn. + child.messages = []backend.Message{{ + Role: "user", + Content: ts.render(), + }} + return child +} + func (s *Session) history() []backend.Message { return s.messages }