bankai/memory

Agent memories (G4) — short content-addressed insights that persist across runs and are injected into prime output so agents start with context.

A memory is content-addressed like a task: SHA-256 over canonical bytes (text + created_at; content_hash excluded, just like Task). Lives in .bankai/memories.jsonl alongside tasks.jsonl.

Types

pub type Memory {
  Memory(
    text: String,
    created_at: Int,
    content_hash: identity.Hash,
  )
}

Constructors

  • Memory(
      text: String,
      created_at: Int,
      content_hash: identity.Hash,
    )

Values

pub fn all(workspace: String) -> Result(List(Memory), String)
pub fn flush(
  memories: List(Memory),
  to path: String,
) -> Result(Nil, simplifile.FileError)
pub fn load(from path: String) -> Result(List(Memory), String)
pub fn memory_bytes(m: Memory) -> BitArray

Canonical, deterministic byte encoding (versioned — see canonical.gleam). Excludes content_hash (a hash cannot include itself).

pub fn memory_decoder() -> decode.Decoder(Memory)
pub fn memory_from_json_string(
  s: String,
) -> Result(Memory, String)
pub fn memory_hash(m: Memory) -> identity.Hash
pub fn memory_to_json(m: Memory) -> json.Json
pub fn memory_to_json_string(m: Memory) -> String
pub fn new(text: String, created_at: Int) -> Memory

Build a memory with a real content hash (computed from a placeholder draft, mirroring builder.build_with_derived_id — no self-reference).

pub fn remember(
  workspace: String,
  text: String,
) -> Result(Memory, String)
Search Document