Documentation
¶
Index ¶
Constants ¶
const AccomplishmentType = "accomplishment"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Episode ¶
type Episode struct {
Goal string `json:"goal"`
Trajectory string `json:"trajectory"`
Status EpisodeStatus `json:"status"`
}
Episode records a single subgoal-level experience for episodic memory. Each episode stores the goal, the full text trajectory, and the termination status. This granularity enables targeted in-context example retrieval per the paper.
type EpisodeStatus ¶
type EpisodeStatus string
EpisodeStatus records how an agent node terminated.
const ( // EpisodeSuccess means the agent completed its subgoal. EpisodeSuccess EpisodeStatus = "success" // EpisodeFailure means the agent failed its subgoal. EpisodeFailure EpisodeStatus = "failure" // EpisodeExpand means the agent decomposed into sub-tasks. EpisodeExpand EpisodeStatus = "expand" // EpisodePending means the episode is awaiting human validation. // Episodes are initially stored as pending until a user reacts // (e.g. 👍 upgrades to success, 👎 downgrades to failure). EpisodePending EpisodeStatus = "pending" )
type EpisodicMemory ¶
type EpisodicMemory interface {
// Store saves a completed episode into the memory.
Store(ctx context.Context, episode Episode)
// Retrieve finds the top-k most similar episodes for the given goal.
Retrieve(ctx context.Context, goal string, k int) []Episode
}
EpisodicMemory stores and retrieves past subgoal-level experiences. Implementations can use embedding similarity (e.g., Sentence-BERT) to find the most relevant past experiences for a given goal.
func NewNoOpEpisodicMemory ¶
func NewNoOpEpisodicMemory() EpisodicMemory
NewNoOpEpisodicMemory creates an episodic memory that does nothing. Store is a no-op and Retrieve always returns nil. This is suitable for initial use cases that don't yet have an experience corpus, and avoids the overhead of constructing a real memory.Service backend.
type EpisodicMemoryConfig ¶
type EpisodicMemoryConfig struct {
// Service is the trpc-agent-go memory.Service backend.
Service memory.Service
// AppName identifies the application for memory scoping.
AppName string
// UserID identifies the user/session for memory scoping.
UserID string
}
EpisodicMemoryConfig holds configuration for creating a memory.Service-backed EpisodicMemory implementation.
func DefaultEpisodicMemoryConfig ¶
func DefaultEpisodicMemoryConfig() EpisodicMemoryConfig
func (EpisodicMemoryConfig) NewEpisodicMemory ¶
func (cfg EpisodicMemoryConfig) NewEpisodicMemory() EpisodicMemory
NewServiceEpisodicMemory creates an EpisodicMemory backed by memory.Service. Episodes are stored as JSON-serialized content and searched by goal text.
func (EpisodicMemoryConfig) WithUserID ¶
func (cfg EpisodicMemoryConfig) WithUserID(userID string) EpisodicMemoryConfig
WithUserID returns a copy of the config with the UserID set to the given value. This enables creating per-sender episodic memory from a shared base config.
type ReactionContext ¶
type ReactionContext struct {
// Goal is the agent's goal when the message was sent.
Goal string `json:"goal"`
// Output is the agent's output text (truncated for storage).
Output string `json:"output"`
// SenderKey identifies the user/channel ("platform:senderID:channelID").
SenderKey string `json:"sender_key"`
}
ReactionContext captures the agent's goal and output when a message was sent, so that a later emoji reaction can be correlated back to the episode. Without this correlation, reactions would be meaningless because we wouldn't know which goal/output the user is approving.
type ReactionHandler ¶
type ReactionHandler struct {
// contains filtered or unexported fields
}
ReactionHandler processes incoming emoji reactions and converts them into episodic memory entries. This is the core of the "giving the LLM a cookie" mechanism: positive reactions store the episode as validated success, negative reactions store it as failure.
Without this handler, the system would rely solely on heuristic-based episode storage (looksLikeError), which is susceptible to memory poisoning from graceful LLM failures.
func NewReactionHandler ¶
func NewReactionHandler(cfg ReactionHandlerConfig) *ReactionHandler
NewReactionHandler creates a handler that processes incoming reactions against the ledger and stores/updates episodes accordingly. Returns nil if either dependency is nil (safe to call HandleReaction on nil).
func (*ReactionHandler) HandleReaction ¶
func (h *ReactionHandler) HandleReaction(ctx context.Context, msg messenger.IncomingMessage)
HandleReaction processes an incoming reaction message. It looks up the reacted message in the ledger, maps the emoji to an episode status, and stores the validated episode in episodic memory.
It is safe to call on a nil receiver (no-op).
type ReactionHandlerConfig ¶
type ReactionHandlerConfig struct {
Ledger *ReactionLedger
Episodic EpisodicMemory
}
ReactionHandlerConfig holds the dependencies needed to create a ReactionHandler.
type ReactionLedger ¶
type ReactionLedger struct {
// contains filtered or unexported fields
}
ReactionLedger is a DB-backed ledger that maps sent message IDs to the agent context that produced them. The send_message tool records entries; the reaction handler looks them up.
Without this ledger, incoming reactions (which only carry the reacted message ID) cannot be correlated to the agent's goal and output.
Backed by the generic short_memories table (memory_type = "reaction_ledger").
func NewReactionLedger ¶
func NewReactionLedger(store *db.ShortMemoryStore) *ReactionLedger
NewReactionLedger creates a new DB-backed ledger. If store is nil, the ledger operates as a no-op (lookups always return false).
func (*ReactionLedger) Lookup ¶
func (l *ReactionLedger) Lookup(ctx context.Context, messageID string) (ReactionContext, bool)
Lookup retrieves the agent context for a sent message ID. Returns the context and true if found and not expired, or zero value and false otherwise.
type WorkingMemory ¶
type WorkingMemory struct {
// contains filtered or unexported fields
}
WorkingMemory is a thread-safe key-value store shared across all agent nodes in a single ReAcTree run. It enables agents to share environment-specific observations (e.g., discovered file content, resource locations) without re-exploring the environment. Without this, each agent node would operate in isolation, potentially duplicating costly exploration actions.
func NewWorkingMemory ¶
func NewWorkingMemory() *WorkingMemory
NewWorkingMemory creates an empty WorkingMemory instance.
func (*WorkingMemory) Clear ¶
func (m *WorkingMemory) Clear()
Clear removes all entries from working memory.
func (*WorkingMemory) Keys ¶
func (m *WorkingMemory) Keys() []string
Keys returns all keys currently stored in working memory. This is useful for agents to discover what observations are available.
func (*WorkingMemory) Recall ¶
func (m *WorkingMemory) Recall(key string) (string, bool)
Recall retrieves the value for a given key from working memory. Returns the value and true if the key exists, or empty string and false otherwise.
func (*WorkingMemory) Snapshot ¶
func (m *WorkingMemory) Snapshot() map[string]string
Snapshot returns a shallow copy of the current memory state. Useful for logging or passing a read-only view to prompts.
func (*WorkingMemory) Store ¶
func (m *WorkingMemory) Store(key, value string)
Store saves a key-value pair into working memory. If the key already exists, its value is overwritten with the latest observation.