memory

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContextRecoveryCompact      = "compact"
	ContextRecoveryPruneCompact = "pruneCompact"
)

Variables

View Source
var ConversationIDKey = conversationIDKey("conversationID")
View Source
var ModelMessageIDKey = modelMessageIDKey("modelMessageID")
View Source
var ToolMessageIDKey = toolMessageIDKey("toolMessageID")

Functions

func CleanupTurn

func CleanupTurn(turnID string)

CleanupTurn removes all in-memory state for the given turn. Call this when the turn completes or is canceled to prevent memory leaks.

func ContextRecoveryModeFromContext

func ContextRecoveryModeFromContext(ctx context.Context) (string, bool)

func ConversationIDFromContext

func ConversationIDFromContext(ctx context.Context) string

ConversationIDFromContext return conversation id from context

func MergeDiscoveryMode

func MergeDiscoveryMode(ctx context.Context, update DiscoveryMode) context.Context

MergeDiscoveryMode merges an update into existing discovery mode and stores the resulting value in context.

func ModelMessageIDFromContext

func ModelMessageIDFromContext(ctx context.Context) string

func RequestModeFromContext added in v0.1.5

func RequestModeFromContext(ctx context.Context) string

RequestModeFromContext returns the current generate/stream mode when present.

func SetTurnModelMessageID

func SetTurnModelMessageID(turnID, msgID string)

SetTurnModelMessageID stores the current model call's assistant message ID.

func SetTurnTrace

func SetTurnTrace(turnID, traceID string)

SetTurnTrace stores a provider trace/anchor id for the given turn id.

func ToolMessageIDFromContext

func ToolMessageIDFromContext(ctx context.Context) string

func TurnModelMessageID

func TurnModelMessageID(turnID string) string

TurnModelMessageID returns the most recent assistant message ID for this turn.

func TurnTrace

func TurnTrace(turnID string) string

TurnTrace returns a previously stored provider trace/anchor id for this turn.

func WithContextRecoveryMode

func WithContextRecoveryMode(ctx context.Context, mode string) context.Context

func WithConversationID

func WithConversationID(ctx context.Context, conversationID string) context.Context

WithConversationID create context with conversation id

func WithDiscoveryMode

func WithDiscoveryMode(ctx context.Context, mode DiscoveryMode) context.Context

WithDiscoveryMode stores discovery mode in context.

func WithModelCompletionMeta

func WithModelCompletionMeta(ctx context.Context, meta ModelCompletionMeta) context.Context

WithModelCompletionMeta stores completion metadata on the context.

func WithRequestMode added in v0.1.5

func WithRequestMode(ctx context.Context, mode string) context.Context

WithRequestMode stores the current generate/stream mode (chat/plan/summary/chain).

func WithRunMeta

func WithRunMeta(ctx context.Context, meta RunMeta) context.Context

WithRunMeta stores run metadata on the context for downstream persistence.

func WithToolMessageID

func WithToolMessageID(ctx context.Context, messageID string) context.Context

func WithTurnMeta

func WithTurnMeta(ctx context.Context, meta TurnMeta) context.Context

WithTurnMeta stores TurnMeta on the context and also seeds individual keys for backward compatibility with existing readers.

Types

type DiscoveryMode

type DiscoveryMode struct {
	Scheduler     bool
	Strict        bool
	ScheduleID    string
	ScheduleRunID string
}

DiscoveryMode controls how tool discovery behaves for the current request.

func DiscoveryModeFromContext

func DiscoveryModeFromContext(ctx context.Context) (DiscoveryMode, bool)

DiscoveryModeFromContext returns discovery mode when set.

type EmbedFunc

type EmbedFunc func(ctx context.Context, texts []string) ([][]float32, error)

EmbedFunc defines a function that creates embeddings for given texts. It should return one embedding per input text.

type ModelCompletionMeta

type ModelCompletionMeta struct {
	Content       string
	Preamble      string
	FinalResponse bool
	FinishReason  string
}

ModelCompletionMeta carries LLM response data through context so that emitCanonicalModelEvent can include all data points in a single model_completed event (content, preamble, finalResponse, finish reason).

func ModelCompletionMetaFromContext

func ModelCompletionMetaFromContext(ctx context.Context) (ModelCompletionMeta, bool)

ModelCompletionMetaFromContext returns completion metadata if present.

type RunMeta

type RunMeta struct {
	RunID     string
	Iteration int
}

RunMeta captures the active persisted run identity and loop iteration.

func RunMetaFromContext

func RunMetaFromContext(ctx context.Context) (RunMeta, bool)

RunMetaFromContext returns run metadata when available.

type TurnMeta

type TurnMeta struct {
	TurnID          string
	Assistant       string
	ConversationID  string
	ParentMessageID string // last user message id (or tool message when parenting final)
}

TurnMeta captures minimal per-turn context for downstream persistence. Prefer passing a single TurnMeta instead of scattering separate keys.

func TurnMetaFromContext

func TurnMetaFromContext(ctx context.Context) (TurnMeta, bool)

TurnMetaFromContext returns a stored TurnMeta when present.

Jump to

Keyboard shortcuts

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