Memory & State

How agents store and retrieve information.

Three Layers of Memory

1. Short-Term (Context Window)

This is the immediate conversation history. It is limited by the LLM's context window (e.g., 128k tokens). Bothive automatically manages this via a sliding window and summarization strategy.

2. Key-Value Store (Session)

Persistent state that lasts for a user session or lifetime. Accessed via `db.get(key)` and `db.set(key, value)`. Useful for user preferences, flags, and counters.

3. Vector Memory (RAG)

Semantic search over large datasets. When you upload documents to a Bot, they are automatically chunked and embedded here.

Using KV Memory

bot MemoryDemo { on user.message { // Look up a stored value; fall back to null if it's not set yet. recall "user_name" as name default null if name == null { // First time: treat this message as their name and store it. remember "user_name" as input respond with "Nice to meet you, " + input } else { respond with "Welcome back, " + name } } }

How helpful was this page?

Not helpfulExcellent