Documentation
¶
Overview ¶
Package session manages branchable conversation trees and JSONL serialization.
Index ¶
- func MarshalEntry(entry TreeEntry) ([]byte, error)
- func SerializeSession(entries []TreeEntry) ([]byte, error)
- func ToAgentContext(sessionCtx Context, systemPrompt string) *msg.Context
- type CompactionResult
- type Context
- type EntryType
- type MemoryStorage
- func (m *MemoryStorage) Append(_ context.Context, entry TreeEntry) error
- func (m *MemoryStorage) Entries() []TreeEntry
- func (m *MemoryStorage) GetBranch(_ context.Context, leafID string) ([]TreeEntry, error)
- func (m *MemoryStorage) GetLeafID(_ context.Context) (string, error)
- func (m *MemoryStorage) ListEntries(_ context.Context) ([]TreeEntry, error)
- func (m *MemoryStorage) SetLeafID(_ context.Context, id string) error
- type Session
- func (s *Session) Append(ctx context.Context, entry TreeEntry) error
- func (s *Session) AppendCompaction(ctx context.Context, result CompactionResult) error
- func (s *Session) GetBranch(ctx context.Context, leafID string) ([]TreeEntry, error)
- func (s *Session) LeafID(ctx context.Context) (string, error)
- func (s *Session) ListEntries(ctx context.Context) ([]TreeEntry, error)
- func (s *Session) MoveTo(ctx context.Context, entryID, summary string) error
- type Storage
- type TreeEntry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MarshalEntry ¶
MarshalEntry serializes one session tree entry to JSON.
func SerializeSession ¶
SerializeSession writes session entries as JSONL.
Types ¶
type CompactionResult ¶
type CompactionResult struct {
EntryID string
Summary string
FirstKeptEntryID string
TokensBefore int
ReadFiles []string
ModifiedFiles []string
}
CompactionResult carries data needed to append a compaction tree node.
type Context ¶
type Context struct {
Messages []msg.AgentMessage
ModelName string
ActiveTools []string
}
Context is the reconstructed runtime view of a branch path.
func BuildContext ¶
BuildContext reconstructs loop context from a branch path with compaction boundaries.
type MemoryStorage ¶
type MemoryStorage struct {
// contains filtered or unexported fields
}
MemoryStorage is an in-memory Storage implementation for tests and ephemeral runs.
func NewMemoryStorage ¶
func NewMemoryStorage() *MemoryStorage
NewMemoryStorage creates an empty in-memory session store.
func (*MemoryStorage) Append ¶
func (m *MemoryStorage) Append(_ context.Context, entry TreeEntry) error
Append stores a tree entry in insertion order.
func (*MemoryStorage) Entries ¶
func (m *MemoryStorage) Entries() []TreeEntry
Entries returns a snapshot of stored entries for assertions.
func (*MemoryStorage) GetLeafID ¶
func (m *MemoryStorage) GetLeafID(_ context.Context) (string, error)
GetLeafID returns the current leaf pointer.
func (*MemoryStorage) ListEntries ¶
func (m *MemoryStorage) ListEntries(_ context.Context) ([]TreeEntry, error)
ListEntries returns all stored entries in append order.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session manages a branchable conversation tree backed by storage.
func (*Session) AppendCompaction ¶
func (s *Session) AppendCompaction(ctx context.Context, result CompactionResult) error
AppendCompaction stores a compaction node and moves the leaf pointer to it.
func (*Session) ListEntries ¶
ListEntries returns all persisted session entries when supported by storage.
type Storage ¶
type Storage interface {
Append(ctx context.Context, entry TreeEntry) error
GetBranch(ctx context.Context, leafID string) ([]TreeEntry, error)
GetLeafID(ctx context.Context) (string, error)
SetLeafID(ctx context.Context, id string) error
}
Storage persists session tree entries without prescribing a backend.
type TreeEntry ¶
type TreeEntry struct {
ID string `json:"id"`
ParentID string `json:"parent_id"`
Type EntryType `json:"type"`
Message msg.AgentMessage `json:"-"`
MessageRaw any `json:"message,omitempty"`
ModelName string `json:"model_name,omitempty"`
ActiveToolNames []string `json:"active_tool_names,omitempty"`
Summary string `json:"summary,omitempty"`
FromID string `json:"from_id,omitempty"`
FirstKeptEntryID string `json:"first_kept_entry_id,omitempty"`
TokensBefore int `json:"tokens_before,omitempty"`
ReadFiles []string `json:"read_files,omitempty"`
ModifiedFiles []string `json:"modified_files,omitempty"`
}
TreeEntry is one node in the append-only session tree.
func DeserializeSession ¶
DeserializeSession reads JSONL session entries.
func UnmarshalEntry ¶
UnmarshalEntry deserializes one session tree entry from JSON.