Skip to main content

Overview

The Workspace provides persistent memory for agents with a flexible filesystem-like structure. Agents can create arbitrary markdown file hierarchies that get indexed for full-text and semantic search. Inspired by OpenClaw’s memory system, the Workspace follows the principle: if you want to remember something, write it.

Filesystem Structure

Workspace

Provides database-backed memory storage for an agent.

Constructor (PostgreSQL)

src/workspace/mod.rs
Creates a new workspace backed by a PostgreSQL connection pool.
String
required
User identifier (from channel)
Pool
required
PostgreSQL connection pool

Constructor (Generic Database)

src/workspace/mod.rs
Creates a new workspace backed by any Database implementation (e.g., libSQL).
String
required
User identifier
Arc<dyn Database>
required
Database implementation

Configuration

src/workspace/mod.rs
Optionally scope the workspace to a specific agent and/or add semantic search support.

File Operations

read

src/workspace/mod.rs
Reads a file by path. Returns the document if it exists, or an error if not found.
&str
required
File path (e.g., “context/vision.md”)
Returns: Result<MemoryDocument, WorkspaceError> Example:

write

src/workspace/mod.rs
Writes (creates or updates) a file. Creates parent directories implicitly. Re-indexes the document for search after writing.
&str
required
File path
&str
required
File content
Returns: Result<MemoryDocument, WorkspaceError> Example:

append

src/workspace/mod.rs
Appends content to a file. Creates the file if it doesn’t exist. Adds a newline separator between existing and new content.
&str
required
File path
&str
required
Content to append

delete

src/workspace/mod.rs
Deletes a file and its associated chunks.

exists

src/workspace/mod.rs
Checks if a file exists.

list

src/workspace/mod.rs
Lists files and directories in a path. Returns immediate children (not recursive). Use empty string or ”/” for root directory.
&str
required
Directory path (e.g., “projects/”)
Example:

list_all

src/workspace/mod.rs
Lists all files recursively (flat list of all paths).

Convenience Methods

memory

src/workspace/mod.rs
Gets the main MEMORY.md document (long-term curated memory). Creates it if it doesn’t exist.

today_log

src/workspace/mod.rs
Gets today’s daily log. Daily logs are append-only and keyed by date.

daily_log

src/workspace/mod.rs
Gets a daily log for a specific date.

heartbeat_checklist

src/workspace/mod.rs
Gets the heartbeat checklist (HEARTBEAT.md). Returns the DB-stored checklist if it exists, otherwise falls back to the in-memory seed template.

append_memory

src/workspace/mod.rs
Appends an entry to the main MEMORY.md document. This is for important facts, decisions, and preferences worth remembering long-term.

append_daily_log

src/workspace/mod.rs
Appends an entry to today’s daily log with a timestamp.

System Prompt

system_prompt

src/workspace/mod.rs
Builds the system prompt from identity files. Loads AGENTS.md, SOUL.md, USER.md, IDENTITY.md, and MEMORY.md to compose the agent’s system prompt.

system_prompt_for_context

src/workspace/mod.rs
Builds the system prompt, optionally excluding personal memory. When is_group_chat is true, MEMORY.md is excluded to prevent leaking personal context into group conversations.

search

src/workspace/mod.rs
Hybrid search across all memory documents. Combines full-text search (BM25) with semantic search (vector similarity) using Reciprocal Rank Fusion (RRF).
&str
required
Search query
usize
required
Maximum number of results

search_with_config

src/workspace/mod.rs
Search with custom configuration.

Seeding

seed_if_empty

src/workspace/mod.rs
Seeds any missing core identity files in the workspace. Called on every boot. Only creates files that don’t already exist, so user edits are never overwritten. Returns: Number of files created (0 if all core files already existed)

import_from_directory

src/workspace/mod.rs
Imports markdown files from a directory on disk into the workspace DB. Only imports files that don’t already exist in the database.

backfill_embeddings

src/workspace/mod.rs
Generates embeddings for chunks that don’t have them yet. Useful for backfilling embeddings after enabling the provider.

Types

MemoryDocument

src/workspace/document.rs

WorkspaceEntry

src/workspace/document.rs

SearchResult

src/workspace/search.rs

SearchConfig

src/workspace/search.rs

Example