Documentation
¶
Overview ¶
Package sessions provides persistent session management for the agent.
Index ¶
- Constants
- Variables
- type Session
- func (s *Session) AddMessage(role provider.Role, content string)
- func (s *Session) AddMessageWithToolCalls(role provider.Role, content string, toolCalls []provider.ToolCall)
- func (s *Session) AddToolResult(toolCallID, content string)
- func (s *Session) Clear()
- func (s *Session) GetMessages() []provider.Message
- func (s *Session) GetMetadata(key string) (any, bool)
- func (s *Session) MarshalJSON() ([]byte, error)
- func (s *Session) SetMetadata(key string, value any)
- func (s *Session) Trim(n int)
- func (s *Session) UnmarshalJSON(data []byte) error
- type Skill
- type Store
- func (s *Store) ClearCache()
- func (s *Store) Close() error
- func (s *Store) Delete(ctx context.Context, id string) error
- func (s *Store) Get(ctx context.Context, id string) (*Session, error)
- func (s *Store) GetIfExists(ctx context.Context, id string) (*Session, error)
- func (s *Store) List(ctx context.Context) ([]string, error)
- func (s *Store) Save(ctx context.Context, session *Session) error
- func (s *Store) Touch(ctx context.Context, id string) error
- type StoreConfig
Constants ¶
const ( // DefaultSessionTTL is the default TTL for sessions (7 days). DefaultSessionTTL = 7 * 24 * time.Hour )
Variables ¶
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 ¶
NewSession creates a new session with the given ID.
func (*Session) AddMessage ¶
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 ¶
AddToolResult adds a tool result message to the session.
func (*Session) GetMessages ¶
GetMessages returns all messages in the session.
func (*Session) GetMetadata ¶
GetMetadata gets a metadata value.
func (*Session) MarshalJSON ¶
MarshalJSON serializes the session to JSON.
func (*Session) SetMetadata ¶
SetMetadata sets a metadata value.
func (*Session) UnmarshalJSON ¶
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) Description ¶
Description returns a human-readable description.
func (*Skill) SetStorage ¶
SetStorage implements compiled.StorageAware.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store manages persistent session storage.
func (*Store) ClearCache ¶
func (s *Store) ClearCache()
Clear removes all cached sessions. This does not delete sessions from the backend.
func (*Store) Get ¶
Get retrieves a session by ID. If the session doesn't exist, it creates a new one.
func (*Store) GetIfExists ¶
GetIfExists retrieves a session by ID only if it exists. Returns ErrSessionNotFound if the session doesn't exist.
func (*Store) List ¶
List returns all session IDs. This requires the backend to implement kvs.ListableStore.