Documentation
¶
Overview ¶
Package mem0 adds long-term memory to a jargo voice agent, backed by a mem0 server (https://github.com/mem0ai/mem0).
It is a frame processor placed between the user aggregator and the LLM. On each turn it searches mem0 for memories relevant to the user's latest message and folds them into the context's system prompt (see frames.LLMContext.SetRecall), then stores the new user and assistant turns back to mem0 in the background so retrieval never blocks on writes.
mem := mem0.NewMemory(mem0.Config{Host: "http://localhost:8000", UserID: caller})
pipeline.New(input, stt, agg.User(), mem, llm, tts, output, agg.Assistant())
Point Host at a mem0 REST server (self-hosted, or the managed API with an APIKey) and scope memories to a caller with UserID. Memory is best-effort: search and store failures are logged and never break the conversation.
Index ¶
Constants ¶
const HeaderXAPIKey = "X-API-Key"
HeaderXAPIKey is the header a self-hosted mem0 server authenticates with. Set Config.APIKeyHeader to it when talking to one; the managed API uses the default "Authorization: Token <key>" instead.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Host is the base URL of the mem0 REST server, e.g. http://localhost:8000.
// Required.
Host string `validate:"required"`
// APIKey authenticates the caller. Optional.
APIKey string
// APIKeyHeader names the header APIKey is sent in. Empty sends
// "Authorization: Token <key>", which is what the managed mem0 API expects.
// A self-hosted server reads the key from X-API-Key instead and ignores the
// Authorization form, so point this at HeaderXAPIKey for one of those.
APIKeyHeader string `validate:"omitempty,printascii"`
// UserID scopes memories to a caller. Recommended; without it memories are
// not partitioned per user.
UserID string
// AgentID and RunID optionally scope memories to an agent or a session.
AgentID string
RunID string
// SearchLimit caps how many memories are retrieved per turn; 0 uses a default.
SearchLimit int
// SearchThreshold is the minimum relevance score for a memory to be used; 0
// leaves the cutoff to the server.
SearchThreshold float64
// Timeout bounds a single mem0 request; 0 uses a default.
Timeout time.Duration
// SearchTimeout bounds the per-turn retrieval specifically, which runs before
// the LLM and so delays the reply; 0 falls back to Timeout. Set it well below
// Timeout for voice, where a late memory is worse than a missing one.
SearchTimeout time.Duration
// Prewarm issues one throwaway search when the session starts, so the first
// real retrieval does not pay the cost of warming the path.
Prewarm bool
// HTTPClient overrides the HTTP client; nil uses one with Timeout.
HTTPClient *http.Client
}
Config configures the memory service.
type MemoryService ¶ added in v1.0.0
MemoryService is the memory frame processor.
func NewMemory ¶
func NewMemory(cfg Config) *MemoryService
NewMemory builds a memory service from cfg.
func (*MemoryService) ProcessFrame ¶ added in v1.0.0
func (s *MemoryService) ProcessFrame(ctx context.Context, f frames.Frame, dir processor.Direction) error
ProcessFrame retrieves and stores memory around the LLM context, forwarding every frame untouched.