Skip to main content

Module memory_blocks

Module memory_blocks 

Source
Expand description

Letta/MemGPT-inspired self-editing memory blocks.

Memory blocks are named, versioned text slots that an AI agent can read and overwrite during a session. Each write increments the version counter and appends a row to block_edit_log so the full rewrite history is preserved.

§Design

  • One row per block name (PRIMARY KEY on name).
  • Overflow detection uses a rough 4 chars/token heuristic; if the content exceeds max_tokens * 4 bytes the excess is returned and the block is truncated to the allowed length.
  • All timestamps follow the project-wide convention: RFC 3339 UTC strings.

Structs§

BlockEditLog
A single entry in the edit history for a block.
MemoryBlock
A named, versioned text slot.

Constants§

CREATE_BLOCK_EDIT_LOG_TABLE
SQL that creates the block_edit_log table.
CREATE_MEMORY_BLOCKS_TABLE
SQL that creates the memory_blocks table.

Functions§

archive_overflow
If the block’s content exceeds its max_tokens budget (estimated at 4 chars/token), truncate the block to the allowed length, persist the truncated version with a log entry, and return the overflow text.
create_block
Create a new memory block.
delete_block
Delete a block and its edit history.
get_block
Retrieve a block by name, returning None when it does not exist.
get_block_history
Retrieve the edit history for a block, most-recent first.
list_blocks
Return all memory blocks ordered by name.
update_block
Update a block’s content, increment its version, and record the edit.