session: add Checkpoint for typed subflow handoff

This commit is contained in:
Levi Neely 2026-05-17 10:15:24 +02:00
parent b5b2ee43ec
commit ea4a3084e0
1 changed files with 16 additions and 0 deletions

View File

@ -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
}