Documentation
¶
Overview ¶
Package session defines conversation identity and the minimal persistence contract used by the agent runner.
A Store has exactly two operations: Load and the atomic Append. Advanced durability features such as sequences, leases, and checkpoints belong in store modules, not in the core.
NewContext and FromContext carry the current Session through a run so tools and provider adapters can read conversation identity without extra plumbing.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrIDRequired is returned when a store operation receives a session // without an ID. ErrIDRequired = errors.New("session: id is required") // ErrMessagesRequired is returned when Append receives no messages. ErrMessagesRequired = errors.New("session: at least one message is required") // ErrClosed is returned when the in-memory store is used after Close. ErrClosed = errors.New("session: store is closed") )
Functions ¶
Types ¶
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
Memory is a thread-safe in-memory Store. It is intended for tests, examples, and ephemeral applications.
func (*Memory) Clear ¶
func (m *Memory) Clear()
Clear removes all sessions. It is intended for tests.
type Session ¶
type Session struct {
// ID identifies the conversation.
ID string `json:"id"`
// ResourceID identifies the owner or tenant. Stores must use it to isolate
// conversations that happen to share an ID.
ResourceID string `json:"resource_id,omitempty"`
}
Session identifies a conversation and its owner scope.
func FromContext ¶
FromContext returns the session carried by ctx, if any.
type Store ¶
type Store interface {
// Load returns the session's messages in chronological order.
Load(ctx context.Context, session Session) ([]llm.Message, error)
// Append atomically adds messages to the session.
Append(ctx context.Context, session Session, messages ...llm.Message) error
}
Store persists conversation messages.
Append must be atomic: either every message is persisted or none is. The runner calls Append once per step with the assistant message and all tool results, so a crash cannot leave a transcript with unanswered tool calls.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package sessiontest provides a shared conformance suite for session.Store implementations.
|
Package sessiontest provides a shared conformance suite for session.Store implementations. |