sessions

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package sessions provides persistent session management for the agent.

Index

Constants

View Source
const (

	// DefaultSessionTTL is the default TTL for sessions (7 days).
	DefaultSessionTTL = 7 * 24 * time.Hour
)

Variables

View Source
var ErrSessionNotFound = errors.New("session not found")

ErrSessionNotFound is returned when a session is not found.

Functions

This section is empty.

Types

type Session

type Session struct {
	ID        string             `json:"id"`
	AgentID   string             `json:"agent_id,omitempty"`
	Messages  []provider.Message `json:"messages"`
	CreatedAt time.Time          `json:"created_at"`
	UpdatedAt time.Time          `json:"updated_at"`
	Metadata  map[string]any     `json:"metadata,omitempty"`
}

Session represents a conversation session.

func NewSession

func NewSession(id string) *Session

NewSession creates a new session with the given ID.

func (*Session) AddMessage

func (s *Session) AddMessage(role provider.Role, content string)

AddMessage adds a message to the session.

func (*Session) AddMessageWithToolCalls

func (s *Session) AddMessageWithToolCalls(role provider.Role, content string, toolCalls []provider.ToolCall)

AddMessageWithToolCalls adds a message with tool calls to the session.

func (*Session) AddToolResult

func (s *Session) AddToolResult(toolCallID, content string)

AddToolResult adds a tool result message to the session.

func (*Session) Clear

func (s *Session) Clear()

Clear removes all messages from the session.

func (*Session) GetMessages

func (s *Session) GetMessages() []provider.Message

GetMessages returns all messages in the session.

func (*Session) GetMetadata

func (s *Session) GetMetadata(key string) (any, bool)

GetMetadata gets a metadata value.

func (*Session) MarshalJSON

func (s *Session) MarshalJSON() ([]byte, error)

MarshalJSON serializes the session to JSON.

func (*Session) SetMetadata

func (s *Session) SetMetadata(key string, value any)

SetMetadata sets a metadata value.

func (*Session) Trim

func (s *Session) Trim(n int)

Trim keeps only the last n messages.

func (*Session) UnmarshalJSON

func (s *Session) UnmarshalJSON(data []byte) error

UnmarshalJSON deserializes the session from JSON.

type Skill

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

Skill implements the compiled.Skill interface for session management.

func NewSkill

func NewSkill() *Skill

NewSkill creates a new session management skill. The store must be set before Init is called.

func (*Skill) Close

func (s *Skill) Close() error

Close releases resources.

func (*Skill) Description

func (s *Skill) Description() string

Description returns a human-readable description.

func (*Skill) Init

func (s *Skill) Init(ctx context.Context) error

Init initializes the skill.

func (*Skill) Name

func (s *Skill) Name() string

Name returns the skill identifier.

func (*Skill) SetStorage

func (s *Skill) SetStorage(backend kvs.Store)

SetStorage implements compiled.StorageAware.

func (*Skill) Tools

func (s *Skill) Tools() []skill.Tool

Tools returns the tools provided by this skill.

type Store

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

Store manages persistent session storage.

func NewStore

func NewStore(config StoreConfig) *Store

NewStore creates a new session store.

func (*Store) ClearCache

func (s *Store) ClearCache()

Clear removes all cached sessions. This does not delete sessions from the backend.

func (*Store) Close

func (s *Store) Close() error

Close closes the underlying backend.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, id string) error

Delete removes a session.

func (*Store) Get

func (s *Store) Get(ctx context.Context, id string) (*Session, error)

Get retrieves a session by ID. If the session doesn't exist, it creates a new one.

func (*Store) GetIfExists

func (s *Store) GetIfExists(ctx context.Context, id string) (*Session, error)

GetIfExists retrieves a session by ID only if it exists. Returns ErrSessionNotFound if the session doesn't exist.

func (*Store) List

func (s *Store) List(ctx context.Context) ([]string, error)

List returns all session IDs. This requires the backend to implement kvs.ListableStore.

func (*Store) Save

func (s *Store) Save(ctx context.Context, session *Session) error

Save persists a session to storage.

func (*Store) Touch

func (s *Store) Touch(ctx context.Context, id string) error

Touch updates the session's TTL without modifying its content.

type StoreConfig

type StoreConfig struct {
	// Backend is the KVS storage backend.
	Backend kvs.Store

	// TTL is the session time-to-live. Zero means no expiration.
	TTL time.Duration
}

StoreConfig configures the session store.

Jump to

Keyboard shortcuts

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