session

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const ScopeVersionV1 = 1

ScopeVersionV1 is the first structured session-scope schema version.

Variables

This section is empty.

Functions

func BuildMainSessionKey

func BuildMainSessionKey(agentID string) string

BuildMainSessionKey returns the opaque main-session key for an agent.

func BuildOpaqueSessionKey

func BuildOpaqueSessionKey(alias string) string

BuildOpaqueSessionKey returns a stable opaque session key derived from a canonical alias string.

func BuildSessionKey

func BuildSessionKey(scope SessionScope) string

BuildSessionKey returns the opaque key for a structured session scope.

func CanonicalScopeSignature

func CanonicalScopeSignature(scope SessionScope) string

CanonicalScopeSignature returns a stable serialized representation of scope.

func CanonicalSessionIdentityID

func CanonicalSessionIdentityID(channel, rawID string, identityLinks map[string][]string) string

CanonicalSessionIdentityID collapses an identity using identity_links when possible, then returns a normalized lowercase identifier.

func IsOpaqueSessionKey

func IsOpaqueSessionKey(key string) bool

IsOpaqueSessionKey returns true when the key matches the opaque session-key format. Only opaque keys are honoured as caller-supplied session keys.

func ResolveAgentID

func ResolveAgentID(store any, sessionKey string) string

ResolveAgentID returns the routed agent ID recorded in the structured scope metadata of a session, or "" when the store holds no scope for the key.

Types

type Allocation

type Allocation struct {
	Scope      SessionScope
	SessionKey string
}

Allocation contains the structured scope and opaque session key selected for a routed turn.

func AllocateRouteSession

func AllocateRouteSession(input AllocationInput) Allocation

AllocateRouteSession maps a route decision onto a structured scope and its opaque session key.

type AllocationInput

type AllocationInput struct {
	AgentID       string
	Context       bus.InboundContext
	SessionPolicy routing.SessionPolicy
}

AllocationInput contains the routing result and peer context needed to derive the session keys for a turn.

type JSONLBackend

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

JSONLBackend adapts a memory.Store into the SessionStore interface. Write errors are logged rather than returned, matching the fire-and-forget SessionStore contract the agent loop relies on.

func NewJSONLBackend

func NewJSONLBackend(store memory.Store) *JSONLBackend

NewJSONLBackend wraps a memory.Store for use as a SessionStore.

func (*JSONLBackend) AddFullMessage

func (b *JSONLBackend) AddFullMessage(sessionKey string, msg providers.Message)

func (*JSONLBackend) AddMessage

func (b *JSONLBackend) AddMessage(sessionKey, role, content string)

func (*JSONLBackend) Close

func (b *JSONLBackend) Close() error

Close releases resources held by the underlying store.

func (*JSONLBackend) EnsureSessionMetadata

func (b *JSONLBackend) EnsureSessionMetadata(sessionKey string, scope *SessionScope)

EnsureSessionMetadata persists the structured scope of a session.

func (*JSONLBackend) GetHistory

func (b *JSONLBackend) GetHistory(key string) []providers.Message

func (*JSONLBackend) GetSessionScope

func (b *JSONLBackend) GetSessionScope(sessionKey string) *SessionScope

GetSessionScope reads the structured scope metadata of a session.

func (*JSONLBackend) GetSummary

func (b *JSONLBackend) GetSummary(key string) string

func (*JSONLBackend) ListSessions

func (b *JSONLBackend) ListSessions() []string

ListSessions returns all known session keys.

func (*JSONLBackend) Save

func (b *JSONLBackend) Save(key string) error

Save persists session state. Since the JSONL store fsyncs every write immediately, the data is already durable. Save runs compaction to reclaim space from logically truncated messages (no-op when there are none).

func (*JSONLBackend) SetHistory

func (b *JSONLBackend) SetHistory(key string, history []providers.Message)

func (*JSONLBackend) SetSummary

func (b *JSONLBackend) SetSummary(key, summary string)

func (*JSONLBackend) TruncateHistory

func (b *JSONLBackend) TruncateHistory(key string, keepLast int)

type MetadataAwareSessionStore

type MetadataAwareSessionStore interface {
	EnsureSessionMetadata(sessionKey string, scope *SessionScope)
	GetSessionScope(sessionKey string) *SessionScope
}

MetadataAwareSessionStore exposes structured session metadata operations.

type SessionScope

type SessionScope struct {
	Version    int               `json:"version"`
	AgentID    string            `json:"agent_id"`
	Channel    string            `json:"channel"`
	Account    string            `json:"account"`
	Dimensions []string          `json:"dimensions"`
	Values     map[string]string `json:"values"`
}

SessionScope describes the semantic session partition selected for a turn.

func CloneScope

func CloneScope(scope *SessionScope) *SessionScope

CloneScope returns a deep copy of scope.

type SessionStore

type SessionStore interface {
	// AddMessage appends a simple role/content message to the session.
	AddMessage(sessionKey, role, content string)
	// AddFullMessage appends a complete message including tool calls.
	AddFullMessage(sessionKey string, msg providers.Message)
	// GetHistory returns the full message history for the session.
	GetHistory(key string) []providers.Message
	// GetSummary returns the conversation summary, or "" if none.
	GetSummary(key string) string
	// SetSummary replaces the conversation summary.
	SetSummary(key, summary string)
	// SetHistory replaces the full message history.
	SetHistory(key string, history []providers.Message)
	// TruncateHistory keeps only the last keepLast messages.
	TruncateHistory(key string, keepLast int)
	// Save persists any pending state to durable storage.
	Save(key string) error
	// ListSessions returns all known session keys.
	ListSessions() []string
	// Close releases resources held by the store.
	Close() error
}

SessionStore defines the persistence operations used by the agent loop. JSONLBackend is the durable implementation; the agent loop also runs sub-turns on an in-memory store behind the same interface.

Write methods (Add*, Set*, Truncate*) are fire-and-forget: they do not return errors. Implementations should log failures internally.

Jump to

Keyboard shortcuts

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