session

package
v0.1.19 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package session provides in-memory conversation session management for the chatbot. Sessions are keyed by ID and hold a sliding window of messages.

Design ref: docs/chatbot-design-spec.md §5.3

Index

Constants

View Source
const DefaultMaxMessages = 40

DefaultMaxMessages is the maximum number of messages kept per session.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager is a concurrent-safe session store. Sessions are held in memory and are lost on process restart.

func NewManager

func NewManager(maxMessages int) *Manager

NewManager creates a new session manager.

func (*Manager) Count

func (m *Manager) Count() int

Count returns the number of active sessions.

func (*Manager) Delete

func (m *Manager) Delete(id string)

Delete removes a session.

func (*Manager) Get

func (m *Manager) Get(id string) *Session

Get returns the session for the given ID, or nil if it doesn't exist.

func (*Manager) GetOrCreate

func (m *Manager) GetOrCreate(id string) *Session

GetOrCreate returns the session for the given ID, creating it if needed. If id is empty, a new session with a generated ID is created.

type Session

type Session struct {
	ID        string
	Messages  []llm.Message
	CreatedAt time.Time
	UpdatedAt time.Time
	// contains filtered or unexported fields
}

Session holds the conversation state for a single chat session.

func (*Session) AddMessage

func (s *Session) AddMessage(msg llm.Message)

AddMessage appends a message and trims the window if needed. Tool call/result pairs are kept together: we always trim from the front, skipping the system messages.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL