session

package
v0.3.33 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package session is the capability boundary for the session event log: event payload DTOs, pure projections over the recorded events, and the write/index interfaces implemented by runtime/session/sessevents and injected into plugins via deps.

Index

Constants

View Source
const (
	TodoPending    = "pending"
	TodoInProgress = "in_progress"
	TodoDone       = "done"
)

Todo statuses. Anything other than TodoDone counts as outstanding work.

View Source
const (
	FinishCompleted = "completed"
	FinishBlocked   = "blocked"
)

Run finish statuses.

View Source
const MetadataLogicalChars = "logical_chars"

MetadataLogicalChars stores pre-sanitize size when storage shrinks the message (e.g. stripped inline media).

Variables

This section is empty.

Functions

func EstimateLogicalChars

func EstimateLogicalChars(msg agentkit.ModelMessage) int

EstimateLogicalChars approximates model-visible size before session storage.

func EstimateMessagesChars

func EstimateMessagesChars(messages []agentkit.ModelMessage) int

EstimateMessagesChars sums logical character counts for a message list (e.g. pre-step history including hydrated vision).

func FlattenTextParts

func FlattenTextParts(parts []agentkit.ContentPart, sep string) string

FlattenTextParts joins non-empty text parts with sep (empty type is treated as text).

func LastAssistantText

func LastAssistantText(events []agentkit.SessionEvent, seq agentkit.EventSeq) string

LastAssistantText returns the text of the most recent assistant message after seq.

func LatestEventSeq

func LatestEventSeq(events []agentkit.SessionEvent) agentkit.EventSeq

LatestEventSeq returns the highest seq present in events.

func MetadataInt

func MetadataInt(md map[string]any, key string) int

MetadataInt reads an integer metadata value written at ingest time.

func RepeatedToolCalls

func RepeatedToolCalls(events []agentkit.SessionEvent, seq agentkit.EventSeq) int

RepeatedToolCalls returns how many times the most recent tool call signature repeats consecutively at the tail of the log after seq.

func ResolveActiveSessionID

func ResolveActiveSessionID(ctx context.Context, store agentkit.SessionStore, entryKey agentkit.SessionID) (agentkit.SessionID, error)

ResolveActiveSessionID maps a stable active-session entry key to the current history SessionID. When no /new mapping exists, entryKey is returned unchanged.

func RunStartSeq

func RunStartSeq(events []agentkit.SessionEvent) agentkit.EventSeq

RunStartSeq returns the seq of the most recent inbound user message.

func StepCount

func StepCount(events []agentkit.SessionEvent, seq agentkit.EventSeq) int

StepCount counts the steps completed after seq.

func SumLogicalCharsFromEvents

func SumLogicalCharsFromEvents(events []agentkit.SessionEvent, agentID agentkit.AgentID) int

SumLogicalCharsFromEvents totals logical message size for compaction estimates.

Types

type Compaction

type Compaction interface {
	// AppendCompaction writes a compaction marker event. Compaction events are
	// self-describing: session backends trim their own in-memory history when
	// appending one, and message derivation always honors the latest marker.
	AppendCompaction(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID, data compaction.EventData) error
	AppendSummarizationRetryStart(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID, data RetryStartData) error
	AppendSummarizationRetryEnd(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID, data RetryEndData) error
	// IndexForCompaction rebuilds the model-visible message list with source
	// event seqs, including the latest compaction summary and retained tail.
	IndexForCompaction(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID) ([]compaction.IndexedMessage, error)
}

Compaction records compaction markers, indexes history for summarization, and logs summarization-retry attempts around the summary LLM call.

type Conversation

type Conversation interface {
	// AppendMessage sanitizes and appends a user/assistant message event.
	AppendMessage(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID, typ agentkit.EventType, msg agentkit.ModelMessage) error
	// AppendToolCall sanitizes and appends a tool call event.
	AppendToolCall(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID, call agentkit.ToolCall) error
	// AppendToolResult appends a tool result event.
	AppendToolResult(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID, result agentkit.ToolResult) error
	AppendTurnStart(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID) error
	AppendTurnEnd(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID, data TurnEndData) error
	AppendStepStart(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID, step int) error
	AppendStepEnd(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID, step int) error
}

Conversation is transcript plus turn bracketing, used by remote agents that persist inbound/outbound messages without owning the local tool loop.

type Events

type Events interface {
	Conversation
	RunLog
	Compaction
	Skills
	// Recovery markers: overflow and generic auto-retry bracketing. No plugin
	// consumes these today; runtime records them through the same instance.
	AppendAutoRetryStart(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID, data RetryStartData) error
	AppendAutoRetryEnd(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID, data RetryEndData) error
	AppendOverflowRecovery(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID, data OverflowRecoveryData) error
}

Events is the full session event log write contract. The standard implementation lives in runtime/session/sessevents (kind session/events). Plugins should depend on the smallest interface they need; the same session.events instance satisfies all of them.

type OverflowRecoveryData

type OverflowRecoveryData struct {
	Applied int    `json:"applied"`
	Reason  string `json:"reason,omitempty"`
	Error   string `json:"error,omitempty"`
}

type RecoveryData

type RecoveryData struct {
	TurnStartSeq  agentkit.EventSeq `json:"turnStartSeq"`
	Steps         int               `json:"steps"`
	OrphanResults int               `json:"orphanResults"`
	ClosedStep    int               `json:"closedStep"`
	Reason        string            `json:"reason"`
}

RecoveryData is the audit payload of a session/recovery event, written after repairing an interrupted turn.

type RetryEndData

type RetryEndData struct {
	Success    bool   `json:"success"`
	Attempt    int    `json:"attempt"`
	FinalError string `json:"finalError,omitempty"`
}

RetryEndData is the shared payload of the retry-bracketing end events.

type RetryStartData

type RetryStartData struct {
	Attempt      int    `json:"attempt"`
	MaxAttempts  int    `json:"maxAttempts"`
	DelayMs      int    `json:"delayMs"`
	ErrorMessage string `json:"errorMessage"`
}

RetryStartData is the shared payload of the retry-bracketing start events (auto-retry, summarization-retry); the event type distinguishes the domain.

type RunFinishData

type RunFinishData struct {
	Status  string `json:"status"`
	Summary string `json:"summary,omitempty"`
}

RunFinishData is the payload of an EventRunFinish event.

func FinishAfter

func FinishAfter(events []agentkit.SessionEvent, seq agentkit.EventSeq) *RunFinishData

FinishAfter returns the run/finish event recorded after seq, or nil.

type RunLog

type RunLog interface {
	AppendTodoUpdate(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID, items []Todo) error
	AppendRunFinish(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID, data RunFinishData) error
	AppendTurnContinue(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID, data TurnContinueData) error
	AppendUsage(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID, data UsageData) error
}

RunLog records agent-run control events (todo, finish, continue, usage).

type RunState

type RunState struct {
	StartSeq agentkit.EventSeq
	Todos    []Todo
	Pending  []Todo
	Finish   *RunFinishData
	Repeats  int
	Usage    UsageData
	Context  int
}

RunState is a snapshot of autonomous-run signals from the session log.

func RunStateFromEvents

func RunStateFromEvents(events []agentkit.SessionEvent) RunState

RunStateFromEvents assembles the autonomous-run snapshot from the full event log of one session.

type Skills

type Skills interface {
	// RenderSkillContent formats loaded skill instructions for the model (tool result and event payload).
	RenderSkillContent(content skill.Content) string
	// AppendSkillLoad persists skill/load and returns the same rendered text.
	AppendSkillLoad(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID, content skill.Content) (string, error)
}

Skills records skill injections during tool execution.

type StepEndData

type StepEndData struct {
	Step int `json:"step"`
}

type StepStartData

type StepStartData struct {
	Step int `json:"step"`
}

type Todo

type Todo struct {
	ID     string `json:"id"`
	Title  string `json:"title"`
	Status string `json:"status"`
}

Todo is one entry of the durable task list written by tool/todo.

func LatestTodos

func LatestTodos(events []agentkit.SessionEvent) []Todo

LatestTodos returns the task list from the most recent todo/update event.

func PendingTodos

func PendingTodos(items []Todo) []Todo

PendingTodos filters LatestTodos down to entries that still need work.

func (Todo) Done

func (t Todo) Done() bool

Done reports whether this entry no longer needs work.

type TodoUpdateData

type TodoUpdateData struct {
	Items []Todo `json:"items"`
}

TodoUpdateData is the payload of an EventTodoUpdate event.

type TurnContinueData

type TurnContinueData struct {
	Segment  int                     `json:"segment"`
	Reason   string                  `json:"reason"`
	Steps    int                     `json:"steps"`
	Messages []agentkit.ModelMessage `json:"messages,omitempty"`
}

TurnContinueData records one autonomous turn extension.

type TurnEndData

type TurnEndData struct {
	Steps      int    `json:"steps"`
	StopReason string `json:"stopReason,omitempty"`
	StepLimit  int    `json:"stepLimit,omitempty"`
	Cancelled  bool   `json:"cancelled,omitempty"`
	Failed     bool   `json:"failed,omitempty"`
}

type TurnStartData

type TurnStartData struct{}

type UsageData

type UsageData struct {
	InputTokens  int `json:"inputTokens"`
	OutputTokens int `json:"outputTokens"`
	TotalTokens  int `json:"totalTokens"`
}

UsageData records token accounting for one model step.

func LatestUsage

func LatestUsage(events []agentkit.SessionEvent) UsageData

LatestUsage returns the most recent usage event.

func TotalUsage

func TotalUsage(events []agentkit.SessionEvent, seq agentkit.EventSeq) UsageData

TotalUsage sums usage events recorded after seq.

Jump to

Keyboard shortcuts

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