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
- func ContextEvents(events []agentkit.SessionEvent) []agentkit.SessionEvent
- func EstimateLogicalChars(msg agentkit.ModelMessage) int
- func EstimateMessagesChars(messages []agentkit.ModelMessage) int
- func FlattenTextParts(parts []agentkit.ContentPart, sep string) string
- func LastAssistantText(events []agentkit.SessionEvent, seq agentkit.EventSeq) string
- func LatestEventSeq(events []agentkit.SessionEvent) agentkit.EventSeq
- func MetadataInt(md map[string]any, key string) int
- func RepeatedToolCalls(events []agentkit.SessionEvent, seq agentkit.EventSeq) int
- func ResolveActiveSessionID(ctx context.Context, store agentkit.SessionStore, entryKey agentkit.SessionID) (agentkit.SessionID, error)
- func RunStartSeq(events []agentkit.SessionEvent) agentkit.EventSeq
- func StepCount(events []agentkit.SessionEvent, seq agentkit.EventSeq) int
- func SumLogicalCharsFromEvents(events []agentkit.SessionEvent, agentID agentkit.AgentID) int
- type Compaction
- type ContextData
- type Conversation
- type Events
- type OverflowRecoveryData
- type RecoveryData
- type RetryEndData
- type RetryStartData
- type RunFinishData
- type RunLog
- type RunState
- type Skills
- type StepEndData
- type StepStartData
- type Todo
- type TodoUpdateData
- type TurnContinueData
- type TurnEndData
- type TurnStartData
- type TurnSteerData
- type UsageData
Constants ¶
const ( TodoPending = "pending" TodoInProgress = "in_progress" TodoDone = "done" )
Todo statuses. Anything other than TodoDone counts as outstanding work.
const ( FinishCompleted = "completed" FinishBlocked = "blocked" )
Run finish statuses.
const ( // SteerOutcomeQueued means the message was accepted onto the running // session's steer queue. It is the immediate, best-effort ack. SteerOutcomeQueued = "queued" // SteerOutcomeInjected means the message was folded into the turn that was // already streaming (a local agent injected it at its next step boundary, or // an ACP peer acknowledged `_session/steering`). SteerOutcomeInjected = "injected" // SteerOutcomeNextTurn means the running turn was too far along to accept // steering, so the message runs as the session's next turn instead. SteerOutcomeNextTurn = "next-turn" // SteerOutcomeRejected means delivery failed. The message may or may not have // reached the agent, so it is never retried automatically. SteerOutcomeRejected = "rejected" )
The outcome vocabulary of an EventTurnSteer event. The runner reports queued the moment a message is accepted; whoever resolves where it actually landed reports the terminal outcome through the message's SteerAck.
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 ContextEvents ¶ added in v0.4.38
func ContextEvents(events []agentkit.SessionEvent) []agentkit.SessionEvent
ContextEvents returns the current model context while preserving the original event log for auditing. Compaction and normal message derivation share it.
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 ¶
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 ContextData ¶ added in v0.4.38
ContextData records the execution directory associated with the following conversation history. Empty Cwd returns to the configured consumer defaults.
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 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 ¶
PendingTodos filters LatestTodos down to entries that still need 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"`
// Message carries the turn's final assistant message when one was produced.
// It lets consumers render the reply without depending on streaming deltas
// (message/update) having all arrived.
Message json.RawMessage `json:"message,omitempty"`
}
type TurnStartData ¶
type TurnStartData struct{}
type TurnSteerData ¶ added in v0.4.35
type TurnSteerData struct {
// Outcome is always SteerOutcomeQueued today. Reserved as the seam for agents
// that can report a finer result for their steering (injected mid-turn vs
// deferred to the next turn) without a wire change.
Outcome string `json:"outcome"`
// SessionID is the conversation the running turn belongs to.
SessionID string `json:"sessionId,omitempty"`
// AgentID is the agent handling the running turn.
AgentID string `json:"agentId,omitempty"`
// UserID identifies the sender whose message was steered.
UserID string `json:"userId,omitempty"`
// Preview is a bounded, human-readable excerpt of the steered message.
Preview string `json:"preview,omitempty"`
}
TurnSteerData is the payload of an EventTurnSteer event. The runner emits it on the outbound channel when an inbound message is folded into a running turn (steering) instead of starting a new one, so platforms can acknowledge the very message that was steered.
The event carries the steered message's own route, not the running turn's: the point is to let the platform react on that message (Lark replaces its in-flight reaction emoji). Whether the agent later injects the message mid-turn or consumes it as the next turn is not visible here.
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.