Documentation
¶
Overview ¶
Package filememory provides a context provider with tools for persistent file-based agent memory.
Memory files have flat names within a working folder supplied by session state. The default folder is the root directory, so sessions share memories unless a StateInitializer selects separate folders. Descriptions are stored in hidden companion files named by appending "_description.md" to the full memory filename. A hidden memories.md index summarizes up to 50 files and is supplied to the agent before each invocation when present.
Searches are non-recursive and use Go regular expressions and case-insensitive filename patterns. Filename patterns support literal text and * wildcards; ? and brackets are literal characters. Backslashes are path separators, not escape characters. Leading separators, ./ and **/ select the working folder; *.* matches all filenames, including those without extensions. Search matches and line edits share 1-based line numbering. Search results retain each line's LF, CRLF or CR terminator. Edits insert replacement text verbatim, so callers include any terminator they want to keep. An empty replacement deletes the whole line, including its terminator.
Index ¶
Constants ¶
const ( WriteToolName = "file_memory_write" ReadFileToolName = "file_memory_read" DeleteFileToolName = "file_memory_delete" LsToolName = "file_memory_ls" GrepToolName = "file_memory_grep" ReplaceToolName = "file_memory_replace" ReplaceLinesToolName = "file_memory_replace_lines" )
Names of the tools supplied by the provider.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Instructions replaces the built-in instructions. Nil uses the defaults;
// an empty or whitespace-only string omits the provider's instructions.
Instructions *string
// StateInitializer supplies state when the session has none. Nil uses an
// empty working folder. The callback may receive a nil session when the
// provider is invoked without one; in that case state is not persisted.
StateInitializer func(*agent.Session) State
}
Config configures a file memory provider.
type ListEntry ¶
type ListEntry struct {
Name string `json:"name"`
Type string `json:"type"`
Description string `json:"description,omitempty"`
}
ListEntry describes a memory file returned by file_memory_ls.
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider supplies memory tools, instructions, and the current memory index. Use New to create a provider. Its filesystem handle is cleaned up when the provider becomes unreachable; Provider.Close releases it early. Provider is safe for concurrent use, including concurrent tool calls.
func New ¶
New creates a file memory provider rooted at rootDirectory, creating the directory if needed. New directories use permission 0700 and new files use 0600; existing permissions are unchanged. The provider confines file access to this root. Runtime cleanup releases the handle when the provider becomes unreachable; Provider.Close can release it earlier. Cleanup is asynchronous and is not guaranteed to run before program exit.
A zero Config uses built-in instructions and the root directory as the working folder.
Register the provider in agent.Config.ContextProviders. Custom backends using automatic tool-invocation middleware must apply that middleware through agent.ProviderConfig.Middlewares, after context providers have supplied tools.
func (*Provider) Close ¶
Close is an optimization that releases the filesystem handle before runtime cleanup. It is safe to call more than once, but must not overlap active tool calls. Subsequent storage operations return an error wrapping fs.ErrClosed.
func (*Provider) Invoked ¶
Invoked completes the context-provider lifecycle. Memory mutations are persisted by the tools, so no additional storage occurs after a run.