Documentation
¶
Index ¶
- type ReActChain
- type RoundSummary
- type ShortTermMemory
- func (s *ShortTermMemory) AddRoundSummary(summary *RoundSummary) (evicted *RoundSummary, err error)
- func (s *ShortTermMemory) BindPersistence(dataDir, subjectID string) error
- func (s *ShortTermMemory) BuildContextString(count int) string
- func (s *ShortTermMemory) Clear() error
- func (s *ShortTermMemory) GenerateSummaryFromWorkingMemory(wm *WorkingMemory) *RoundSummary
- func (s *ShortTermMemory) GetAllSummaries() []*RoundSummary
- func (s *ShortTermMemory) GetRecentSummaries(count int) []*RoundSummary
- func (s *ShortTermMemory) GetRoundSummary(roundID string) (*RoundSummary, error)
- func (s *ShortTermMemory) GetStats() *ShortTermMemoryStats
- func (s *ShortTermMemory) GetSummariesOldestFirst() []*RoundSummary
- func (s *ShortTermMemory) ToMessages(count int) []protocol.Message
- type ShortTermMemoryStats
- type ToolAction
- type ToolObservation
- type WorkingMemory
- func (w *WorkingMemory) AddAction(toolName string, input map[string]interface{})
- func (w *WorkingMemory) AddMessage(role protocol.MessageRole, content string)
- func (w *WorkingMemory) AddObservation(observation string)
- func (w *WorkingMemory) AddThought(thought string)
- func (w *WorkingMemory) Clear()
- func (w *WorkingMemory) GetAllTempVars() map[string]interface{}
- func (w *WorkingMemory) GetContext() WorkingMemoryContext
- func (w *WorkingMemory) GetDuration() time.Duration
- func (w *WorkingMemory) GetMessages() []protocol.Message
- func (w *WorkingMemory) GetReActChain() ReActChain
- func (w *WorkingMemory) GetRoundID() string
- func (w *WorkingMemory) GetStats() WorkingMemoryStats
- func (w *WorkingMemory) GetTempVar(key string) interface{}
- func (w *WorkingMemory) MarkMessageAsPriority(index int)
- func (w *WorkingMemory) OptimizeContext()
- func (w *WorkingMemory) SetCompressionRatio(ratio float32)
- func (w *WorkingMemory) SetMaxSize(size int)
- func (w *WorkingMemory) SetTempVar(key string, value interface{})
- func (w *WorkingMemory) ToPrompt() string
- type WorkingMemoryContext
- type WorkingMemoryStats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ReActChain ¶
type ReActChain struct {
Thoughts []string
Actions []ToolAction
Observations []string
}
ReActChain represents the complete ReAct chain.
type RoundSummary ¶
type RoundSummary struct {
RoundID string `json:"round_id"`
Summary string `json:"summary"`
KeyPoints []string `json:"key_points"`
Messages int `json:"messages"`
Thoughts int `json:"thoughts"`
Actions int `json:"actions"`
Observations int `json:"observations"`
Timestamp time.Time `json:"timestamp"`
ExpiresAt time.Time `json:"expires_at"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
RoundSummary represents a summary of a conversation round.
type ShortTermMemory ¶
type ShortTermMemory struct {
// contains filtered or unexported fields
}
ShortTermMemory represents the short-term memory for recent N rounds.
L2: Short-Term Memory (短期会话记忆,最近 N 轮) 作用:最近几轮对话的摘要(不是原文),跨轮连贯、不重复、不溢出 存储:内存缓存,带 TTL(比如 1 小时) 特点:会话级、自动摘要、自动过期、容量可控
func NewShortTermMemory ¶
func NewShortTermMemory(maxRounds int, ttl time.Duration) *ShortTermMemory
NewShortTermMemory creates a new short-term memory.
func (*ShortTermMemory) AddRoundSummary ¶
func (s *ShortTermMemory) AddRoundSummary(summary *RoundSummary) (evicted *RoundSummary, err error)
AddRoundSummary adds a summary of a completed round. When capacity exceeds maxRounds, the oldest round is removed and returned as evicted so L4 can consolidate it.
func (*ShortTermMemory) BindPersistence ¶
func (s *ShortTermMemory) BindPersistence(dataDir, subjectID string) error
BindPersistence enables L2 disk persistence (dataDir/l2_<subjectID>.json).
func (*ShortTermMemory) BuildContextString ¶
func (s *ShortTermMemory) BuildContextString(count int) string
BuildContextString builds a context string from recent summaries.
func (*ShortTermMemory) Clear ¶
func (s *ShortTermMemory) Clear() error
Clear clears all stored summaries.
func (*ShortTermMemory) GenerateSummaryFromWorkingMemory ¶
func (s *ShortTermMemory) GenerateSummaryFromWorkingMemory(wm *WorkingMemory) *RoundSummary
GenerateSummaryFromWorkingMemory generates a summary from working memory.
func (*ShortTermMemory) GetAllSummaries ¶
func (s *ShortTermMemory) GetAllSummaries() []*RoundSummary
GetAllSummaries retrieves all stored summaries.
func (*ShortTermMemory) GetRecentSummaries ¶
func (s *ShortTermMemory) GetRecentSummaries(count int) []*RoundSummary
GetRecentSummaries retrieves the most recent N summaries.
func (*ShortTermMemory) GetRoundSummary ¶
func (s *ShortTermMemory) GetRoundSummary(roundID string) (*RoundSummary, error)
GetRoundSummary retrieves a summary of a specific round.
func (*ShortTermMemory) GetStats ¶
func (s *ShortTermMemory) GetStats() *ShortTermMemoryStats
GetStats returns statistics about short-term memory.
func (*ShortTermMemory) GetSummariesOldestFirst ¶
func (s *ShortTermMemory) GetSummariesOldestFirst() []*RoundSummary
GetSummariesOldestFirst returns all L2 summaries in chronological order (for flushing to L4).
func (*ShortTermMemory) ToMessages ¶
func (s *ShortTermMemory) ToMessages(count int) []protocol.Message
ToMessages converts short-term memory to messages for LLM context.
type ShortTermMemoryStats ¶
ShortTermMemoryStats represents statistics about short-term memory.
type ToolAction ¶
ToolAction represents an action taken by the agent.
type ToolObservation ¶
ToolObservation represents the result of a tool action.
type WorkingMemory ¶
type WorkingMemory struct {
// contains filtered or unexported fields
}
WorkingMemory represents the working memory for the current round.
L1: Working Memory (工作记忆,当前轮) Stores the current conversation context, reasoning chain, and temporary variables.
func NewWorkingMemory ¶
func NewWorkingMemory(roundID string) *WorkingMemory
NewWorkingMemory creates a new working memory.
func (*WorkingMemory) AddAction ¶
func (w *WorkingMemory) AddAction(toolName string, input map[string]interface{})
AddAction adds an action to the ReAct chain.
func (*WorkingMemory) AddMessage ¶
func (w *WorkingMemory) AddMessage(role protocol.MessageRole, content string)
AddMessage adds a message to the working memory.
func (*WorkingMemory) AddObservation ¶
func (w *WorkingMemory) AddObservation(observation string)
AddObservation adds an observation to the ReAct chain.
func (*WorkingMemory) AddThought ¶
func (w *WorkingMemory) AddThought(thought string)
AddThought adds a thought to the ReAct chain.
func (*WorkingMemory) Clear ¶
func (w *WorkingMemory) Clear()
Clear clears all data (called after round completion).
func (*WorkingMemory) GetAllTempVars ¶
func (w *WorkingMemory) GetAllTempVars() map[string]interface{}
GetAllTempVars returns all temporary variables.
func (*WorkingMemory) GetContext ¶
func (w *WorkingMemory) GetContext() WorkingMemoryContext
GetContext returns the complete working memory context.
func (*WorkingMemory) GetDuration ¶
func (w *WorkingMemory) GetDuration() time.Duration
GetDuration returns the duration since the round started.
func (*WorkingMemory) GetMessages ¶
func (w *WorkingMemory) GetMessages() []protocol.Message
GetMessages returns all messages in the current round.
func (*WorkingMemory) GetReActChain ¶
func (w *WorkingMemory) GetReActChain() ReActChain
GetReActChain returns the complete ReAct chain.
func (*WorkingMemory) GetRoundID ¶
func (w *WorkingMemory) GetRoundID() string
GetRoundID returns the round ID.
func (*WorkingMemory) GetStats ¶
func (w *WorkingMemory) GetStats() WorkingMemoryStats
GetStats returns statistics about the working memory.
func (*WorkingMemory) GetTempVar ¶
func (w *WorkingMemory) GetTempVar(key string) interface{}
GetTempVar gets a temporary variable.
func (*WorkingMemory) MarkMessageAsPriority ¶
func (w *WorkingMemory) MarkMessageAsPriority(index int)
MarkMessageAsPriority marks a message index as high-priority (won't be compressed).
func (*WorkingMemory) OptimizeContext ¶
func (w *WorkingMemory) OptimizeContext()
OptimizeContext optimizes the context when it exceeds capacity. Strategy: Keep system/user messages, compress middle messages, keep recent messages.
func (*WorkingMemory) SetCompressionRatio ¶
func (w *WorkingMemory) SetCompressionRatio(ratio float32)
SetCompressionRatio sets the compression ratio (0.0-1.0) for context optimization.
func (*WorkingMemory) SetMaxSize ¶
func (w *WorkingMemory) SetMaxSize(size int)
SetMaxSize sets the maximum number of messages to keep.
func (*WorkingMemory) SetTempVar ¶
func (w *WorkingMemory) SetTempVar(key string, value interface{})
SetTempVar sets a temporary variable.
func (*WorkingMemory) ToPrompt ¶
func (w *WorkingMemory) ToPrompt() string
ToPrompt converts working memory to a formatted prompt string.
type WorkingMemoryContext ¶
type WorkingMemoryContext struct {
RoundID string
Messages []protocol.Message
ReActChain ReActChain
TempVars map[string]interface{}
Stats WorkingMemoryStats
}
WorkingMemoryContext represents the complete context for the current round.