service.go

Overview

The service.go file defines the memory package, which provides key abstractions and data structures for interacting with agent memory—specifically long-term knowledge storage scoped to users. This package enables ingestion of user sessions and retrieval of relevant memory entries for subsequent user queries, supporting continuity and contextual awareness across user interactions.

The central component is the Service interface, which outlines methods for adding sessions into memory and searching memory entries based on query parameters. The file also defines data types representing search requests, search responses, and individual memory entries.

This package plays a foundational role in the system's memory management functionality, enabling agents to persist and recall user-specific information beyond a single session. It interfaces with session management (session.Session) and integrates with content representations from the genai package, facilitating large language model (LLM) interactions and context augmentation.


Package: memory

Service Interface

The Service interface encapsulates the memory service capabilities focused on storing and searching long-term memory entries.

type Service interface {
    AddSession(ctx context.Context, s session.Session) error
    Search(ctx context.Context, req *SearchRequest) (*SearchResponse, error)
}

Methods


Data Structures

SearchRequest

Represents the input parameters for a memory search operation.

type SearchRequest struct {
    Query   string
    UserID  string
    AppName string
}

SearchResponse

Encapsulates the results returned from a memory search.

type SearchResponse struct {
    Memories []Entry
}

Entry

Defines a single memory record stored in the system.

type Entry struct {
    Content   *genai.Content
    Author    string
    Timestamp time.Time
}

Implementation Details and Algorithms


Interaction with Other System Components


Usage Examples

// Create a memory service instance (concrete implementation not defined here)
var memService memory.Service

// Add a session to memory
err := memService.AddSession(ctx, userSession)
if err != nil {
    // handle error
}

// Search memory for relevant entries
searchReq := &memory.SearchRequest{
    Query:   "What did I discuss yesterday?",
    UserID:  "user123",
    AppName: "chatbot",
}
resp, err := memService.Search(ctx, searchReq)
if err != nil {
    // handle error
}
// Process resp.Memories as needed

Diagram: Memory Service Structure

classDiagram
class Service {
+AddSession()
+Search()
}
class SearchRequest {
+Query
+UserID
+AppName
}
class SearchResponse {
+Memories
}
class Entry {
+Content
+Author
+Timestamp
}
Service ..> SearchRequest : uses
Service ..> SearchResponse : returns
SearchResponse "1" o-- "*" Entry : contains
Entry ..> genai.Content : contains
Service ..> session.Session : interacts with

This documentation references relevant system concepts such as session management (Session Management) and LLM content integration (LLM Integration and Agents) for deeper understanding of how memory service fits into the overall agent architecture.