Documentation
¶
Index ¶
- Variables
- func SessionKeyFromContext(ctx context.Context) string
- func WithSessionKey(ctx context.Context, key string) context.Context
- type ChildSession
- type ChildSessionConfig
- type ChildSessionStore
- type EntStore
- func (s *EntStore) AnnotateTimeout(key string, partial string) error
- func (s *EntStore) AppendMessage(key string, msg Message) error
- func (s *EntStore) Client() *ent.Client
- func (s *EntStore) Close() error
- func (s *EntStore) CompactMessages(key string, upToIndex int, summary string) error
- func (s *EntStore) Create(session *Session) error
- func (s *EntStore) Delete(key string) error
- func (s *EntStore) Get(key string) (*Session, error)
- func (s *EntStore) GetChecksum(name string) ([]byte, error)
- func (s *EntStore) GetSalt(name string) ([]byte, error)
- func (s *EntStore) MigrateSecrets(ctx context.Context, reencryptFn func([]byte) ([]byte, error), ...) (err error)
- func (s *EntStore) SetChecksum(name string, checksum []byte) error
- func (s *EntStore) SetSalt(name string, salt []byte) error
- func (s *EntStore) Update(session *Session) error
- type InMemoryChildStore
- func (s *InMemoryChildStore) ChildrenOf(parentKey string) ([]*ChildSession, error)
- func (s *InMemoryChildStore) DiscardChild(childKey string) error
- func (s *InMemoryChildStore) ForkChild(parentKey, agentName string, cfg ChildSessionConfig) (*ChildSession, error)
- func (s *InMemoryChildStore) GetChild(childKey string) (*ChildSession, error)
- func (s *InMemoryChildStore) MergeChild(childKey string, summary string) error
- type Message
- type Session
- type Store
- type StoreOption
- type ToolCall
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func SessionKeyFromContext ¶
SessionKeyFromContext extracts the session key from context.
Types ¶
type ChildSession ¶ added in v0.4.0
type ChildSession struct {
// Key is the unique identifier for this child session.
Key string
// ParentKey is the key of the parent session.
ParentKey string
// AgentName is the sub-agent that owns this child session.
AgentName string
// History contains messages added during this child session.
History []Message
// Config holds the child session settings.
Config ChildSessionConfig
// CreatedAt is when this child session was forked.
CreatedAt time.Time
// MergedAt is set when the child session is merged back to parent.
// Zero value means not yet merged.
MergedAt time.Time
}
ChildSession represents an isolated sub-session forked from a parent. It follows "read parent, write child" semantics: the child session has its own message history that does not pollute the parent until explicitly merged.
func NewChildSession ¶ added in v0.4.0
func NewChildSession(parentKey, agentName string, cfg ChildSessionConfig) *ChildSession
NewChildSession creates a new child session forked from a parent.
func (*ChildSession) AppendMessage ¶ added in v0.4.0
func (cs *ChildSession) AppendMessage(msg Message)
AppendMessage adds a message to the child session's history.
func (*ChildSession) IsMerged ¶ added in v0.4.0
func (cs *ChildSession) IsMerged() bool
IsMerged returns true if this child session has been merged back to parent.
type ChildSessionConfig ¶ added in v0.4.0
type ChildSessionConfig struct {
// MaxMessages limits the child session's message history.
// Zero means unlimited (inherits parent limit).
MaxMessages int
// InheritHistory copies the last N messages from parent.
// Zero means start with empty history.
InheritHistory int
// SummarizeOnMerge applies a summarizer when merging back to parent.
SummarizeOnMerge bool
}
ChildSessionConfig configures how a child session behaves.
type ChildSessionStore ¶ added in v0.4.0
type ChildSessionStore interface {
// ForkChild creates a new child session from a parent session.
// If cfg.InheritHistory > 0, the last N messages are copied from parent.
ForkChild(parentKey, agentName string, cfg ChildSessionConfig) (*ChildSession, error)
// MergeChild merges a child session's messages back into the parent.
// The summary parameter, if non-empty, replaces the full child history
// with a single assistant message containing the summary.
MergeChild(childKey string, summary string) error
// DiscardChild removes a child session without merging.
DiscardChild(childKey string) error
// GetChild retrieves a child session by key.
GetChild(childKey string) (*ChildSession, error)
// ChildrenOf returns all child sessions for a parent.
ChildrenOf(parentKey string) ([]*ChildSession, error)
}
ChildSessionStore extends Store with child session operations.
type EntStore ¶
type EntStore struct {
// contains filtered or unexported fields
}
EntStore implements Store using entgo.io
func NewEntStore ¶
func NewEntStore(dbPath string, opts ...StoreOption) (*EntStore, error)
NewEntStore creates a new ent-backed session store
func NewEntStoreWithClient ¶
func NewEntStoreWithClient(client *ent.Client, opts ...StoreOption) *EntStore
NewEntStoreWithClient creates a new ent-backed session store using an existing ent.Client. This avoids opening a second database connection when the client is already available (e.g., from the bootstrap process). Schema migration is assumed to be already complete.
func (*EntStore) AnnotateTimeout ¶ added in v0.6.0
AnnotateTimeout appends a synthetic assistant message to mark a timed-out turn.
func (*EntStore) AppendMessage ¶
AppendMessage adds a message to session history
func (*EntStore) Close ¶
Close closes the ent client and underlying database connection. When the client was provided externally via NewEntStoreWithClient, only the ent client is closed; the raw DB connection is managed by the caller.
func (*EntStore) CompactMessages ¶
CompactMessages replaces messages up to (and including) upToIndex with a single summary message. This achieves compaction: the original messages are removed and replaced by a condensed version, preserving recent context.
func (*EntStore) GetChecksum ¶
GetChecksum retrieves the passphrase checksum by name
func (*EntStore) MigrateSecrets ¶
func (s *EntStore) MigrateSecrets(ctx context.Context, reencryptFn func([]byte) ([]byte, error), newSalt, newChecksum []byte) (err error)
MigrateSecrets performs the secret migration using callbacks to avoid import cycles. reencryptFn typically decrypts with old key and encrypts with new key.
func (*EntStore) SetChecksum ¶
SetChecksum stores the passphrase checksum by name
type InMemoryChildStore ¶ added in v0.4.0
type InMemoryChildStore struct {
// contains filtered or unexported fields
}
InMemoryChildStore implements ChildSessionStore using an in-memory map. It wraps an existing Store for parent session access.
func NewInMemoryChildStore ¶ added in v0.4.0
func NewInMemoryChildStore(parent Store) *InMemoryChildStore
NewInMemoryChildStore creates a new in-memory child session store.
func (*InMemoryChildStore) ChildrenOf ¶ added in v0.4.0
func (s *InMemoryChildStore) ChildrenOf(parentKey string) ([]*ChildSession, error)
ChildrenOf returns all child sessions for a parent using the parent index.
func (*InMemoryChildStore) DiscardChild ¶ added in v0.4.0
func (s *InMemoryChildStore) DiscardChild(childKey string) error
DiscardChild removes a child session without merging.
func (*InMemoryChildStore) ForkChild ¶ added in v0.4.0
func (s *InMemoryChildStore) ForkChild(parentKey, agentName string, cfg ChildSessionConfig) (*ChildSession, error)
ForkChild creates a new child session from a parent session.
func (*InMemoryChildStore) GetChild ¶ added in v0.4.0
func (s *InMemoryChildStore) GetChild(childKey string) (*ChildSession, error)
GetChild retrieves a child session by key.
func (*InMemoryChildStore) MergeChild ¶ added in v0.4.0
func (s *InMemoryChildStore) MergeChild(childKey string, summary string) error
MergeChild merges a child session's messages back into the parent.
type Message ¶
type Message struct {
Role types.MessageRole `json:"role"` // "user", "assistant", "tool"
Content string `json:"content"`
Timestamp time.Time `json:"timestamp"`
ToolCalls []ToolCall `json:"toolCalls,omitempty"`
Author string `json:"author,omitempty"` // ADK agent name for multi-agent routing
}
Message represents a single message in conversation history
type Session ¶
type Session struct {
Key string `json:"key"`
AgentID string `json:"agentId,omitempty"`
ChannelType string `json:"channelType,omitempty"`
ChannelID string `json:"channelId,omitempty"`
History []Message `json:"history"`
Metadata map[string]string `json:"metadata,omitempty"`
Model string `json:"model,omitempty"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
Session represents a conversation session
type Store ¶
type Store interface {
// Create creates a new session
Create(session *Session) error
// Get retrieves a session by key
Get(key string) (*Session, error)
// Update updates an existing session
Update(session *Session) error
// Delete removes a session
Delete(key string) error
// AppendMessage adds a message to session history
AppendMessage(key string, msg Message) error
// AnnotateTimeout appends a synthetic assistant message to indicate that the
// previous turn was interrupted by a timeout. This prevents incomplete history
// from leaking into subsequent turns.
// partial is any partial response text accumulated before the timeout.
AnnotateTimeout(key string, partial string) error
// Close closes the store
Close() error
// GetSalt retrieves the encryption salt for LocalCryptoProvider
GetSalt(name string) ([]byte, error)
// SetSalt stores the encryption salt for LocalCryptoProvider
SetSalt(name string, salt []byte) error
}
Store defines the interface for session storage
type StoreOption ¶
type StoreOption func(*EntStore)
StoreOption defines the functional option pattern for EntStore
func WithMaxHistoryTurns ¶
func WithMaxHistoryTurns(n int) StoreOption
WithMaxHistoryTurns limits the number of messages kept per session.
func WithPassphrase ¶
func WithPassphrase(passphrase string) StoreOption
WithPassphrase sets the encryption passphrase for the database.