session

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Session

type Session struct {
	// LLM context payload
	Messages []llm.Message
	// Usage is the running sum of every turn's reported token usage in this
	// session. Compaction is expected to reset Messages but leave Usage as
	// the running tab of what the user has already paid for.
	Usage llm.Usage
	// contains filtered or unexported fields
}

Session holds the live conversation history for a single agent run. The agent appends every message (user, assistant, tool result) here so the LLM always receives the full context on the next turn. tools, agent, llm, tui will use it.

func New

func New() *Session

func (*Session) AddUsage

func (s *Session) AddUsage(u llm.Usage)

AddUsage folds one usage entry into the cumulative session total only. Use this for non-turn usage events whose input-token count does NOT represent the current prompt size — e.g. the LLM call inside full compaction, where InputTokens reflects the size of the conversation we just summarized, not the size of the post-compaction prompt.

func (*Session) Append

func (s *Session) Append(msg llm.Message)

func (*Session) FullCompact

func (s *Session) FullCompact(messages []llm.Message, briefTokens int)

FullCompact replaces Messages with the summarization brief and resets the in-flight compaction state. lastTurnInputTokens is set to briefTokens — the brief is now the entirety of the prompt the next turn will send, so callers (the TUI's context bar in particular) can read accurate "current prompt size" without waiting for the next thinking call to land.

Cumulative Usage is also reset: in=briefTokens, out=0. The HUD reads as "fresh context after compact" so the user can visually confirm the bar drop (e.g. 80% → 40%) without the cumulative tail dragging the numbers up. The compaction caller is responsible for logging the pre-reset totals before invoking this — they're gone after.

func (*Session) GetFullCompactCount

func (s *Session) GetFullCompactCount() int

func (*Session) GetMessages

func (s *Session) GetMessages() []llm.Message

func (*Session) IsMicroCompacted

func (s *Session) IsMicroCompacted() bool

func (*Session) LastTurnInputTokens

func (s *Session) LastTurnInputTokens() int

LastTurnInputTokens returns the InputTokens from the most recent agent turn (zero before the first turn completes, or right after a full-compact reset). This is the canonical "how full is the prompt right now" signal — preferred over Usage.Total for ratio checks.

func (*Session) MicroCompact

func (s *Session) MicroCompact(messages []llm.Message)

func (*Session) RecordTurn

func (s *Session) RecordTurn(u llm.Usage)

RecordTurn marks u as the most recent agent-turn usage: it folds u into the cumulative total AND updates lastTurnInputTokens so compaction can measure live prompt pressure. The agent loop calls this after every Complete / Stream that drove a real iteration.

Jump to

Keyboard shortcuts

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