Documentation
¶
Overview ¶
Package memory is what the assistant remembers, which is shared by every session and agent: the details of the person it's talking to, and of itself, such as their names, where the person is, and their time zone and language, which are in the system prompt, each of which is known, not known, or declined, so it isn't. The memory is a namespace of a toolkit, whose tools set them, and whose system prompt has them, with the time.
Index ¶
- Constants
- func SortMemories(memories []schema.Memory)
- type Memory
- func (*Memory) Description() string
- func (m *Memory) Details() schema.Details
- func (m *Memory) Forget(ctx context.Context, key string) (_ schema.Memory, err error)
- func (m *Memory) ForgetLine(ctx context.Context, key, line string) (_ schema.Memory, err error)
- func (m *Memory) GetMemory(ctx context.Context, key string) (_ schema.Memory, err error)
- func (m *Memory) ListMemories(ctx context.Context, req schema.MemoryListRequest) (_ schema.MemoryList, err error)
- func (*Memory) Name() string
- func (*Memory) Notify(func(eventschema.EventAction, string))
- func (m *Memory) Remember(ctx context.Context, meta schema.MemoryMeta, version string) (_ schema.Memory, created bool, err error)
- func (m *Memory) SetDetail(ctx context.Context, field schema.Field, detail *schema.Detail) (_ schema.Details, err error)
- func (m *Memory) SystemPrompt() string
- func (m *Memory) SystemPromptFor(tools []string) string
- func (m *Memory) Tools() []llm.Tool
- type Opt
- type Store
Constants ¶
const ( DetailTable = "detail" // MemoryTable is the table of the events of the memories, whose schema // is Name, and whose rows are their keys MemoryTable = "memory" )
DetailTable is the table of the events of the details, whose schema is Name, and whose rows are their fields, such as location
const Name = "memory"
Name is the name of the namespace of the memory's tools
Variables ¶
This section is empty.
Functions ¶
func SortMemories ¶
SortMemories sorts the memories, the most recently changed first, and then by their keys, as a store lists them
Types ¶
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
Memory is what the assistant remembers, which is kept in a store. It's a namespace of a toolkit, whose system prompt has the details, and the time, and whose tools change them. It's safe to use concurrently.
func New ¶
New returns the memory, with the details in the store, and the options, such as the broadcaster it publishes its changes to, and the tracer. Returns ErrBadParameter when there's no store, or an option isn't valid, and the store's errors.
func (*Memory) Description ¶
Description returns what the memory is
func (*Memory) Forget ¶
Forget deletes the memory with the key, publishes that it was, and returns it, as it was. Returns ErrNotFound when there's none.
func (*Memory) ForgetLine ¶
ForgetLine takes the line out of the body of the memory with the key, apart from the space around it, and a bullet, such as "- ", or forgets the memory, when there's nothing left of it, publishes the change, and returns the memory, as it is, or was, when it's forgotten. Returns ErrNotFound when there's no memory with the key, or it hasn't the line.
func (*Memory) GetMemory ¶
GetMemory returns the memory with the key, or ErrNotFound when there's none
func (*Memory) ListMemories ¶
func (m *Memory) ListMemories(ctx context.Context, req schema.MemoryListRequest) (_ schema.MemoryList, err error)
ListMemories returns the memories which match the request's query, the most recently changed first, of its page, and how many there are
func (*Memory) Notify ¶
func (*Memory) Notify(func(eventschema.EventAction, string))
Notify does nothing, as the memory's tools don't change
func (*Memory) Remember ¶
func (m *Memory) Remember(ctx context.Context, meta schema.MemoryMeta, version string) (_ schema.Memory, created bool, err error)
Remember creates the memory, when the version is empty, or replaces the memory with its key, when the version is its version, and it's changed, publishes the change, and returns the memory, and whether it was created. Returns ErrBadParameter when it isn't valid, ErrConflict when there's a memory with its key, and the version isn't its version, as it was changed since it was seen, or there's none, and the version isn't empty, and the store's errors.
func (*Memory) SetDetail ¶
func (m *Memory) SetDetail(ctx context.Context, field schema.Field, detail *schema.Detail) (_ schema.Details, err error)
SetDetail sets the detail of the field, which is its value, or that it's declined, or forgets it, when it's nil, so it isn't known, in the store, publishes the change, when it changed, and returns the details. Returns ErrBadParameter when the field, or the detail, isn't valid, and the store's errors, when the details aren't changed.
func (*Memory) SystemPrompt ¶
SystemPrompt returns the time, in the person's time zone, when it's known, or the system's, and the details which are known, and which aren't, so the model asks for them, and remembers them. The details which are declined aren't in it, so they aren't asked for.
func (*Memory) SystemPromptFor ¶
SystemPromptFor returns the system prompt, when the model can call the tools, or all of them, when they're nil: when the person's messages were sent, the details, and, with the set_detail tool, those which aren't known, and how to remember them, and, with the memories tool, how to search, keep and use memories
type Opt ¶
type Opt func(*opt) error
Opt is an option of the memory
func WithBroadcaster ¶
func WithBroadcaster(b *broadcaster.Broadcaster) Opt
WithBroadcaster sets the broadcaster which the memory publishes its changes to: when a detail becomes known, or declined, which is created, changes, which is updated, or is forgotten, which is deleted. Their schema is Name, which is memory, their table is DetailTable, their rows are the details' fields, such as location, and their data is the detail, when there is one.
func WithTracer ¶
WithTracer sets the tracer which traces the memory's changes, and loading its details, or none, when it's nil
type Store ¶
type Store interface {
// Details returns the details, which are all not known, when none are
// stored
Details(context.Context) (schema.Details, error)
// PutDetails replaces the details
PutDetails(context.Context, schema.Details) error
// ListMemories returns the memories which match the query, as Matches
// says, the most recently changed first
ListMemories(ctx context.Context, q string) ([]schema.Memory, error)
// GetMemory returns the memory with the key, or ErrNotFound when there's
// none
GetMemory(ctx context.Context, key string) (schema.Memory, error)
// PutMemory creates the memory, or replaces the memory with its key
PutMemory(context.Context, schema.Memory) error
// DeleteMemory deletes the memory with the key, or returns ErrNotFound
// when there's none
DeleteMemory(ctx context.Context, key string) error
}
Store keeps the details, and the memories, such as in files, or a database, so they're kept when the server restarts
Directories
¶
| Path | Synopsis |
|---|---|
|
Package cmd has the memory's commands and flags
|
Package cmd has the memory's commands and flags |
|
Package httpclient is a client of the memory's HTTP API
|
Package httpclient is a client of the memory's HTTP API |
|
Package httphandler has the memory's HTTP API, which gets, sets and forgets the details it keeps, and lists, gets, remembers and forgets its memories
|
Package httphandler has the memory's HTTP API, which gets, sets and forgets the details it keeps, and lists, gets, remembers and forgets its memories |