memory

package
v1.1.10 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentState

type AgentState struct {
	CurrentTask string
	History     []string
	Variables   map[string]interface{}
	// contains filtered or unexported fields
}

AgentState represents the current state of an agent

func NewAgentState

func NewAgentState() *AgentState

NewAgentState creates a new agent state

func (*AgentState) Clear

func (s *AgentState) Clear()

Clear clears the state

func (*AgentState) GetHistory

func (s *AgentState) GetHistory() []string

GetHistory returns the task history

func (*AgentState) GetTask

func (s *AgentState) GetTask() string

GetTask returns the current task

func (*AgentState) GetVariable

func (s *AgentState) GetVariable(key string) (interface{}, bool)

GetVariable gets a state variable

func (*AgentState) SetTask

func (s *AgentState) SetTask(task string)

SetTask sets the current task

func (*AgentState) SetVariable

func (s *AgentState) SetVariable(key string, value interface{})

SetVariable sets a state variable

func (*AgentState) String

func (s *AgentState) String() string

String returns a string representation of the state

type Document

type Document struct {
	ID        string
	Content   string
	Embedding []float64
	Metadata  map[string]interface{}
}

Document represents a document stored in long-term memory

type InMemoryLongTermMemory

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

InMemoryLongTermMemory is a simple in-memory implementation for testing

func NewInMemoryLongTermMemory

func NewInMemoryLongTermMemory() *InMemoryLongTermMemory

NewInMemoryLongTermMemory creates a new in-memory long-term memory

func (*InMemoryLongTermMemory) Clear

Clear clears all documents

func (*InMemoryLongTermMemory) Delete

func (m *InMemoryLongTermMemory) Delete(ctx context.Context, id string) error

Delete deletes a document

func (*InMemoryLongTermMemory) DeleteByMetadata

func (m *InMemoryLongTermMemory) DeleteByMetadata(ctx context.Context, key, value string) error

DeleteByMetadata deletes documents matching a metadata key-value pair

func (*InMemoryLongTermMemory) Search

func (m *InMemoryLongTermMemory) Search(ctx context.Context, query []float64, limit int) ([]Document, error)

Search searches for similar documents (simplified cosine similarity)

func (*InMemoryLongTermMemory) Store

Store stores a document

type LongTermMemory

type LongTermMemory interface {
	// Store stores a document with its embedding
	Store(ctx context.Context, doc Document) error

	// Search searches for similar documents
	Search(ctx context.Context, query []float64, limit int) ([]Document, error)

	// Delete deletes a document by ID
	Delete(ctx context.Context, id string) error

	// DeleteByMetadata deletes documents matching a metadata key-value pair
	DeleteByMetadata(ctx context.Context, key, value string) error

	// Clear clears all documents
	Clear(ctx context.Context) error
}

LongTermMemory manages persistent vector storage

type Message

type Message struct {
	Role    string // system, user, assistant
	Content string
}

Message represents a conversation message

type ShortTermMemory

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

ShortTermMemory manages the current conversation context

func NewShortTermMemory

func NewShortTermMemory(maxSize int) *ShortTermMemory

NewShortTermMemory creates a new short-term memory

func (*ShortTermMemory) Add

func (m *ShortTermMemory) Add(role, content string)

Add adds a message to the memory

func (*ShortTermMemory) Clear

func (m *ShortTermMemory) Clear()

Clear clears all messages

func (*ShortTermMemory) GetAll

func (m *ShortTermMemory) GetAll() []Message

GetAll returns all messages in memory

func (*ShortTermMemory) GetLast

func (m *ShortTermMemory) GetLast(n int) []Message

GetLast returns the last n messages

func (*ShortTermMemory) Size

func (m *ShortTermMemory) Size() int

Size returns the current number of messages

func (*ShortTermMemory) String

func (m *ShortTermMemory) String() string

String returns a string representation of the conversation

Jump to

Keyboard shortcuts

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