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 input
// Check if we know the user's name
call db.get("user_name") as name
if name == null
say "I don't know your name yet. What is it?"
call input.text() as new_name
call db.set("user_name", new_name)
say "Nice to meet you, " + new_name
else
say "Welcome back, " + name
end
end
end