Documentation
¶
Index ¶
- type ChatOption
- type CompactionConfig
- type Pool
- func (p *Pool) ActiveSession(channel string) (SessionInfo, bool)
- func (p *Pool) ArchiveSession(sessionID string) error
- func (p *Pool) Chat(ctx context.Context, sessionID string, message runner.MessageContent, ...) <-chan runner.Event
- func (p *Pool) Close() error
- func (p *Pool) CompactSession(ctx context.Context, sessionID string) (string, error)
- func (p *Pool) CreateSession(channel string) (SessionInfo, error)
- func (p *Pool) GetSession(sessionID string) (SessionInfo, error)
- func (p *Pool) History(sessionID string) []ai.Message
- func (p *Pool) ListSessions(includeArchived bool) ([]SessionInfo, error)
- func (p *Pool) NeedsCompaction(sessionID string) bool
- func (p *Pool) ResolveSession(channel string) (SessionInfo, error)
- func (p *Pool) RotateSession(channel string) (SessionInfo, error)
- func (p *Pool) SetDefaultModel(model string)
- func (p *Pool) SetFactory(factory runner.NewRunnerFunc)
- func (p *Pool) StartReaper(ctx context.Context)
- type PoolOption
- type Session
- type SessionInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChatOption ¶
type ChatOption func(*chatOptions)
ChatOption configures a single Chat call.
func WithModel ¶
func WithModel(model string) ChatOption
WithModel overrides the model for this Chat call. If the session already has a runner with a different model, the runner is replaced.
type CompactionConfig ¶
type CompactionConfig struct {
// MaxTokens triggers compaction when the estimated token count exceeds this.
// 0 (or omitted) uses the default of 80000. Negative values disable
// automatic compaction. Manual /compact still works.
MaxTokens int `yaml:"max_tokens"`
// KeepTail is the number of recent message entries to preserve verbatim
// after compaction. Default: 20.
KeepTail int `yaml:"keep_tail"`
}
CompactionConfig controls automatic session compaction.
func (CompactionConfig) WithDefaults ¶
func (c CompactionConfig) WithDefaults() CompactionConfig
WithDefaults returns a copy with zero-value fields replaced by defaults. MaxTokens 0 -> 80000; negative values are preserved (meaning disabled).
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool manages a set of sessions, each with its own history and runner. It is the only type channels interact with.
func NewPool ¶
func NewPool(factory runner.NewRunnerFunc, mem memory.Engine, opts ...PoolOption) *Pool
NewPool creates a new Pool with the given runner factory and memory engine. The memory engine is required — it is the sole persistence layer for sessions.
func (*Pool) ActiveSession ¶
func (p *Pool) ActiveSession(channel string) (SessionInfo, bool)
ActiveSession returns the most recent non-archived session for a channel.
func (*Pool) ArchiveSession ¶
ArchiveSession marks a session as archived, closes its runner, but keeps history on disk. The session is removed from the in-memory map; its metadata persists in the index.
func (*Pool) Chat ¶
func (p *Pool) Chat(ctx context.Context, sessionID string, message runner.MessageContent, opts ...ChatOption) <-chan runner.Event
Chat sends a message in a session and streams back events. Internally: gets/creates runner, passes history, collects events, appends to session log, streams to caller.
func (*Pool) CompactSession ¶
CompactSession delegates compaction to the memory engine and returns the summary text on success.
func (*Pool) CreateSession ¶
func (p *Pool) CreateSession(channel string) (SessionInfo, error)
CreateSession creates a new session with a generated ID and persists its metadata.
func (*Pool) GetSession ¶
func (p *Pool) GetSession(sessionID string) (SessionInfo, error)
GetSession returns metadata for a session.
func (*Pool) History ¶
History returns the message history for a session, loading from the memory engine. Returns nil if the session has no history.
func (*Pool) ListSessions ¶
func (p *Pool) ListSessions(includeArchived bool) ([]SessionInfo, error)
ListSessions returns metadata for all sessions.
func (*Pool) NeedsCompaction ¶
NeedsCompaction reports whether a session's estimated token count exceeds the compaction threshold. Returns false if compaction is disabled or no memory engine is set.
func (*Pool) ResolveSession ¶
func (p *Pool) ResolveSession(channel string) (SessionInfo, error)
ResolveSession returns the active session for a channel, creating one if needed. The check-and-create is atomic to prevent duplicate sessions under concurrent access.
func (*Pool) RotateSession ¶
func (p *Pool) RotateSession(channel string) (SessionInfo, error)
RotateSession archives the active session for a channel (if any) and creates a new one.
func (*Pool) SetDefaultModel ¶
SetDefaultModel updates the default model used for new runners. Call this alongside SetFactory when the user switches models at runtime.
func (*Pool) SetFactory ¶
func (p *Pool) SetFactory(factory runner.NewRunnerFunc)
SetFactory replaces the runner factory used for new runners. Existing runners are not affected until their session is reset.
func (*Pool) StartReaper ¶
StartReaper runs a background goroutine that periodically checks for idle or dead runners. It returns when ctx is cancelled.
type PoolOption ¶
type PoolOption func(*Pool)
PoolOption configures a Pool.
func WithCompaction ¶
func WithCompaction(cfg CompactionConfig) PoolOption
WithCompaction sets the compaction configuration.
func WithDefaultModel ¶
func WithDefaultModel(model string) PoolOption
WithDefaultModel sets the default model ID for new runners.
func WithFastModel ¶
func WithFastModel(model string) PoolOption
WithFastModel sets the model ID used for compaction and other fast tasks.
func WithIdleTimeout ¶
func WithIdleTimeout(d time.Duration) PoolOption
WithIdleTimeout sets the idle timeout for reaping runners.
type Session ¶
type Session struct {
Info SessionInfo
Runner runner.Runner
Model string // model ID the current runner was created with
}
Session holds the state of a single conversation: metadata and the currently assigned runner. Message persistence is handled by the memory engine exclusively.
type SessionInfo ¶
type SessionInfo = memory.SessionInfo
SessionInfo is an alias for memory.SessionInfo.