Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type History ¶
type History struct {
// contains filtered or unexported fields
}
History stores conversation messages purely in memory. It is concurrency safe and does not perform any persistence.
func (*History) Append ¶
Append stores a message at the end of the history. The message is cloned to avoid external mutation after insertion.
func (*History) Replace ¶
Replace swaps the stored history with the provided slice, cloning entries to keep ownership local to the History.
func (*History) TokenCount ¶
TokenCount reports the estimated token cost of all stored messages.
type Message ¶
type Message struct {
Role string
Content string
ToolCalls []ToolCall
Attachments []model.MessageAttachment // Images for vision API
}
Message represents a single conversational turn used within the message package. It is purposefully minimal to keep the history layer independent from concrete model providers.
func CloneMessage ¶
CloneMessage performs a deep clone of a model.Message, duplicating nested maps to avoid mutation leaks between callers.
func CloneMessages ¶
CloneMessages clones an entire slice of model messages.
type NaiveCounter ¶
type NaiveCounter struct{}
NaiveCounter approximates tokens using byte length. It intentionally errs on the side of overestimation to avoid exceeding upstream context limits.
func (NaiveCounter) Count ¶
func (NaiveCounter) Count(msg Message) int
Count implements TokenCounter.
type TokenCounter ¶
TokenCounter returns an estimated token cost for a message.
type Trimmer ¶
type Trimmer struct {
MaxTokens int
Counter TokenCounter
}
Trimmer removes the oldest messages when the estimated token budget exceeds MaxTokens. The newest messages are preserved.
func NewTrimmer ¶
func NewTrimmer(limit int, counter TokenCounter) *Trimmer
NewTrimmer constructs a Trimmer with the provided token limit. When counter is nil a NaiveCounter is used.