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 }