session

package
v1.9.23 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2025 License: Apache-2.0 Imports: 16 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyID  = errors.New("session ID cannot be empty")
	ErrNotFound = errors.New("session not found")
)

Functions

This section is empty.

Types

type Item

type Item struct {
	// Message holds a regular conversation message
	Message *Message `json:"message,omitempty"`

	// SubSession holds a complete sub-session from task transfers
	SubSession *Session `json:"sub_session,omitempty"`

	// Summary is a summary of the session up until this point
	Summary string `json:"summary,omitempty"`
}

Item represents either a message or a sub-session

func NewMessageItem

func NewMessageItem(msg *Message) Item

NewMessageItem creates a SessionItem containing a message

func NewSubSessionItem

func NewSubSessionItem(subSession *Session) Item

NewSubSessionItem creates a SessionItem containing a sub-session

func (*Item) IsMessage

func (si *Item) IsMessage() bool

IsMessage returns true if this item contains a message

func (*Item) IsSubSession

func (si *Item) IsSubSession() bool

IsSubSession returns true if this item contains a sub-session

type Message

type Message struct {
	AgentFilename string       `json:"agentFilename"`
	AgentName     string       `json:"agentName"` // TODO: rename to agent_name
	Message       chat.Message `json:"message"`
	// Implicit is an optional field to indicate if the message shouldn't be shown to the user. It's needed for special  situations
	// like when an agent transfers a task to another agent - new session is created with a default user message, but this shouldn't be shown to the user.
	// Such messages should be marked as true
	Implicit bool `json:"implicit,omitempty"`
}

Message is a message from an agent

func ImplicitUserMessage added in v1.6.3

func ImplicitUserMessage(agentFilename, content string) *Message

func NewAgentMessage

func NewAgentMessage(a *agent.Agent, message *chat.Message) *Message

func SystemMessage

func SystemMessage(content string) *Message

func UserMessage

func UserMessage(agentFilename, content string, multiContent ...chat.MessagePart) *Message

type Migration

type Migration struct {
	ID          int
	Name        string
	Description string
	UpSQL       string
	DownSQL     string
	AppliedAt   time.Time
}

Migration represents a database migration

type MigrationManager

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

MigrationManager handles database migrations

func NewMigrationManager

func NewMigrationManager(db *sql.DB) *MigrationManager

NewMigrationManager creates a new migration manager

func (*MigrationManager) GetAppliedMigrations

func (m *MigrationManager) GetAppliedMigrations(ctx context.Context) ([]Migration, error)

GetAppliedMigrations returns a list of applied migrations

func (*MigrationManager) InitializeMigrations

func (m *MigrationManager) InitializeMigrations(ctx context.Context) error

InitializeMigrations sets up the migrations table and runs pending migrations

func (*MigrationManager) RunPendingMigrations

func (m *MigrationManager) RunPendingMigrations(ctx context.Context) error

RunPendingMigrations executes all migrations that haven't been applied yet

type Opt

type Opt func(s *Session)

func WithImplicitUserMessage added in v1.6.3

func WithImplicitUserMessage(agentFilename, content string) Opt

func WithMaxIterations added in v1.3.5

func WithMaxIterations(maxIterations int) Opt

func WithSendUserMessage added in v1.9.8

func WithSendUserMessage(sendUserMessage bool) Opt

func WithSystemMessage

func WithSystemMessage(content string) Opt

func WithTitle added in v1.9.0

func WithTitle(title string) Opt

func WithToolsApproved added in v1.9.8

func WithToolsApproved(toolsApproved bool) Opt

func WithUserMessage

func WithUserMessage(agentFilename, content string) Opt

func WithWorkingDir added in v1.5.14

func WithWorkingDir(workingDir string) Opt

type SQLiteSessionStore

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

SQLiteSessionStore implements Store using SQLite

func (*SQLiteSessionStore) AddSession

func (s *SQLiteSessionStore) AddSession(ctx context.Context, session *Session) error

AddSession adds a new session to the store

func (*SQLiteSessionStore) Close

func (s *SQLiteSessionStore) Close() error

Close closes the database connection

func (*SQLiteSessionStore) DeleteSession

func (s *SQLiteSessionStore) DeleteSession(ctx context.Context, id string) error

DeleteSession deletes a session by ID

func (*SQLiteSessionStore) GetSession

func (s *SQLiteSessionStore) GetSession(ctx context.Context, id string) (*Session, error)

GetSession retrieves a session by ID

func (*SQLiteSessionStore) GetSessions

func (s *SQLiteSessionStore) GetSessions(ctx context.Context) ([]*Session, error)

GetSessions retrieves all sessions

func (*SQLiteSessionStore) GetSessionsByAgent added in v1.5.1

func (s *SQLiteSessionStore) GetSessionsByAgent(ctx context.Context, agentFilename string) ([]*Session, error)

GetSessionsByAgent retrieves all sessions for a specific agent

func (*SQLiteSessionStore) UpdateSession

func (s *SQLiteSessionStore) UpdateSession(ctx context.Context, session *Session) error

UpdateSession updates an existing session

type Session

type Session struct {
	// ID is the unique identifier for the session
	ID string `json:"id"`

	// Title is the title of the session, set by the runtime
	Title string `json:"title"`

	// Messages holds the conversation history (messages and sub-sessions)
	Messages []Item `json:"messages"`

	// CreatedAt is the time the session was created
	CreatedAt time.Time `json:"created_at"`

	// ToolsApproved is a flag to indicate if the tools have been approved
	ToolsApproved bool `json:"tools_approved"`

	// WorkingDir is the base directory used for filesystem-aware tools
	WorkingDir string `json:"working_dir,omitempty"`

	// SendUserMessage is a flag to indicate if the user message should be sent
	SendUserMessage bool

	// MaxIterations is the maximum number of agentic loop iterations to prevent infinite loops
	// If 0, there is no limit
	MaxIterations int `json:"max_iterations"`

	InputTokens  int     `json:"input_tokens"`
	OutputTokens int     `json:"output_tokens"`
	Cost         float64 `json:"cost"`
}

Session represents the agent's state including conversation history and variables

func New

func New(opts ...Opt) *Session

New creates a new agent session

func (*Session) AddMessage

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

AddMessage adds a message to the session

func (*Session) AddSubSession

func (s *Session) AddSubSession(subSession *Session)

AddSubSession adds a sub-session to the session

func (*Session) AllowedDirectories added in v1.5.14

func (s *Session) AllowedDirectories() []string

AllowedDirectories returns the directories that should be considered safe for tools

func (*Session) GetAllMessages

func (s *Session) GetAllMessages() []Message

GetAllMessages extracts all messages from the session, including from sub-sessions

func (*Session) GetLastAssistantMessageContent

func (s *Session) GetLastAssistantMessageContent() string

func (*Session) GetLastUserMessageContent added in v1.9.21

func (s *Session) GetLastUserMessageContent() string

func (*Session) GetMessages

func (s *Session) GetMessages(a *agent.Agent) []chat.Message

func (*Session) GetMostRecentAgentFilename

func (s *Session) GetMostRecentAgentFilename() string

type Store

type Store interface {
	AddSession(ctx context.Context, session *Session) error
	GetSession(ctx context.Context, id string) (*Session, error)
	GetSessions(ctx context.Context) ([]*Session, error)
	GetSessionsByAgent(ctx context.Context, agentFilename string) ([]*Session, error)
	DeleteSession(ctx context.Context, id string) error
	UpdateSession(ctx context.Context, session *Session) error
}

Store defines the interface for session storage

func NewSQLiteSessionStore

func NewSQLiteSessionStore(path string) (Store, error)

NewSQLiteSessionStore creates a new SQLite session store

Jump to

Keyboard shortcuts

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