memu

package
v0.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const MemorySystemPrefix = "[memu-memory-context]"

Variables

This section is empty.

Functions

func BuildConversationTurn

func BuildConversationTurn(userText, assistantText string) string

BuildConversationTurn formats a user/assistant exchange into a single conversation turn string suitable for memorization.

func FormatMemoryContext

func FormatMemoryContext(resp RetrieveResponse, maxItems int) string

FormatMemoryContext formats a RetrieveResponse into a human-readable string suitable for injection as a system message. It limits output to maxItems per category.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is an HTTP client for the memu memory service.

func NewClient

func NewClient(baseURL string, httpClient *http.Client) *Client

NewClient creates a new memu Client. If httpClient is nil, a default client with a 30-second timeout is used. The baseURL trailing slash is stripped.

func (*Client) Memorize

func (c *Client) Memorize(ctx context.Context, req MemorizeRequest) (MemorizeResponse, error)

Memorize sends a memorization request to the memu /memorize endpoint.

func (*Client) Retrieve

func (c *Client) Retrieve(ctx context.Context, req RetrieveRequest) (RetrieveResponse, error)

Retrieve sends a retrieval request to the memu /retrieve endpoint.

type MemorizeRequest

type MemorizeRequest struct {
	Content  string         `json:"content"`
	Modality string         `json:"modality"`
	User     map[string]any `json:"user,omitempty"`
}

MemorizeRequest is the request body for the /memorize endpoint.

type MemorizeResponse

type MemorizeResponse map[string]any

MemorizeResponse is the response from the /memorize endpoint.

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider implements memory.MemoryProvider backed by the memu HTTP service.

func NewProvider

func NewProvider(config *ProviderConfig) (*Provider, error)

NewProvider creates a new memu Provider. It returns an error if config is nil or BaseURL is empty. Default values are applied for HistoryLimit (6) and MaxItems (3) when not set.

func (*Provider) Close

func (p *Provider) Close() error

Close releases any resources held by the provider. Currently a no-op.

func (*Provider) Memorize

func (p *Provider) Memorize(ctx context.Context, req *memory.MemorizeRequest) error

Memorize persists a conversation turn to the memu service after a model call. It extracts the user and assistant messages and sends them as a conversation turn.

func (*Provider) Retrieve

Retrieve fetches relevant memory context from the memu service before a model call. It gracefully degrades on error, returning an empty result.

type ProviderConfig

type ProviderConfig struct {
	BaseURL      string
	UserID       string
	HistoryLimit int
	MaxItems     int
}

ProviderConfig holds the configuration for the memu provider.

type Query

type Query struct {
	Role    string       `json:"role"`
	Content QueryContent `json:"content"`
}

Query represents a single message in a retrieve request.

type QueryContent

type QueryContent struct {
	Text string `json:"text"`
}

QueryContent represents the text content of a query message.

type RetrieveRequest

type RetrieveRequest struct {
	Queries []Query        `json:"queries"`
	Where   map[string]any `json:"where,omitempty"`
}

RetrieveRequest is the request body for the /retrieve endpoint.

func BuildRetrieveRequest

func BuildRetrieveRequest(messages []*schema.Message, userID string, limit int) RetrieveRequest

BuildRetrieveRequest constructs a RetrieveRequest from a list of messages. It filters to only user/assistant messages, trims whitespace, and limits to the most recent `limit` messages.

type RetrieveResponse

type RetrieveResponse struct {
	NeedsRetrieval bool                `json:"needs_retrieval,omitempty"`
	OriginalQuery  string              `json:"original_query,omitempty"`
	RewrittenQuery string              `json:"rewritten_query,omitempty"`
	NextStepQuery  string              `json:"next_step_query,omitempty"`
	Categories     []RetrievedCategory `json:"categories,omitempty"`
	Items          []RetrievedItem     `json:"items,omitempty"`
	Resources      []RetrievedResource `json:"resources,omitempty"`
}

RetrieveResponse is the response from the /retrieve endpoint.

type RetrievedCategory

type RetrievedCategory struct {
	ID          string  `json:"id,omitempty"`
	Name        string  `json:"name,omitempty"`
	Description string  `json:"description,omitempty"`
	Summary     string  `json:"summary,omitempty"`
	Score       float64 `json:"score,omitempty"`
	CreatedAt   string  `json:"created_at,omitempty"`
	UpdatedAt   string  `json:"updated_at,omitempty"`
}

RetrievedCategory represents a memory category returned by retrieval.

type RetrievedItem

type RetrievedItem struct {
	ID         string  `json:"id,omitempty"`
	MemoryType string  `json:"memory_type,omitempty"`
	Summary    string  `json:"summary,omitempty"`
	Score      float64 `json:"score,omitempty"`
	CreatedAt  string  `json:"created_at,omitempty"`
	UpdatedAt  string  `json:"updated_at,omitempty"`
	HappenedAt string  `json:"happened_at,omitempty"`
}

RetrievedItem represents a memory item returned by retrieval.

type RetrievedResource

type RetrievedResource struct {
	ID       string  `json:"id,omitempty"`
	URL      string  `json:"url,omitempty"`
	Modality string  `json:"modality,omitempty"`
	Caption  string  `json:"caption,omitempty"`
	Score    float64 `json:"score,omitempty"`
}

RetrievedResource represents a resource returned by retrieval.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL