session

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: Apache-2.0 Imports: 4 Imported by: 4 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

func NewContext

func NewContext(ctx context.Context, s Session) context.Context

NewContext returns a copy of ctx carrying s. The agent runner installs the run's session this way, which lets policies, tools, and provider header functions read the current conversation identity.

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 NewMemory

func NewMemory() *Memory

NewMemory creates an empty in-memory store.

func (*Memory) Append

func (m *Memory) Append(ctx context.Context, session Session, messages ...llm.Message) error

Append atomically adds a deep copy of the messages.

func (*Memory) Clear

func (m *Memory) Clear()

Clear removes all sessions. It is intended for tests.

func (*Memory) Close

func (m *Memory) Close() error

Close makes subsequent operations fail with ErrClosed.

func (*Memory) Load

func (m *Memory) Load(ctx context.Context, session Session) ([]llm.Message, error)

Load returns a deep copy of the session's messages.

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

func FromContext(ctx context.Context) (Session, bool)

FromContext returns the session carried by ctx, if any.

func (Session) Validate

func (s Session) Validate() error

Validate checks the session before a store operation.

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.

Jump to

Keyboard shortcuts

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