Documentation
¶
Index ¶
- type Session
- func (s *Session) AddUsage(u llm.Usage)
- func (s *Session) Append(msg llm.Message)
- func (s *Session) FullCompact(messages []llm.Message, briefTokens int)
- func (s *Session) GetFullCompactCount() int
- func (s *Session) GetMessages() []llm.Message
- func (s *Session) IsMicroCompacted() bool
- func (s *Session) LastTurnInputTokens() int
- func (s *Session) MicroCompact(messages []llm.Message)
- func (s *Session) RecordTurn(u llm.Usage)
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 (*Session) AddUsage ¶
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) FullCompact ¶
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 (*Session) GetMessages ¶
func (*Session) IsMicroCompacted ¶
func (*Session) LastTurnInputTokens ¶
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 (*Session) RecordTurn ¶
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.