v0.7.0

ToriiDB in Agenvoy

Last updated


Agenvoy, an open-source local AI agent by Pardn Chiu that runs 24/7 on your machine, keeps its recent conversation vectors, tool error memory, tool result cache, and running-task markers in ToriiDB; this page maps each Agenvoy feature to the ToriiDB database and API it uses.

One daemon for every Agenvoy process


The Agenvoy TUI and one-shot prompt (both through openLocal in cmd/app/local.go), the background daemon (cmd/app/daemon.go), and the running-task check before stop/update (confirmInterrupt in cmd/app/main.go) all call torii.Init(filesystem.StoreDir), which runs:
  1. d, err := toriidb_daemon.New(path, go_pkg_filesystem_keychain.Get("OPENAI_API_KEY"))
  2. // ...
  3. err = d.Start()

ItemBehavior
Data directory~/.config/agenvoy/.store
First process to startBecomes the server, opens the store, and serves the unix socket
Every later processDials the same socket as a client and calls the same Get/Set/Del methods
Embedder availabilityAsked from the server with d.HasEmbedder(ctx) instead of the local keychain; without an OpenAI key, conversation vectors are not written

So when the TUI and the background daemon run at the same time they read and write the same data, with no file lock and no second store. See Mode Resolution for the mechanism.

Database map


Agenvoy defines four database indexes in internal/runtime/torii/torii.go and wraps the Daemon methods per database (its scan wrapper calls Entries, and its multi-key expiry wrapper calls Expire with several keys):
DBAgenvoy constantContentsToriiDB API used
0torii.DBToolCacheTool result cache, fetch_page skip list, provider quota cache, provider model lists, the decision model's last chosen modelSet (with TTL), Get, Entries, Del
1torii.DBSessionHistEvery conversation message with its embeddingSetVector, VSearch, Entries (Contains/After), Keys, Del
2torii.DBErrorMemoryTool error and fix recordsSetVector (90-day TTL), VSearch, Expire
3torii.DBOnlineLiveness markers for running tasksSet (60-second TTL), Keys, Del

Semantic chat search (DBSessionHist)


Each user and assistant message is written with SetVector under the key <sessionID>:<unixNano>, and ToriiDB attaches an OpenAI embedding in the background. The chat_history tool builds two search modes on it:
ModeToriiDB call
match=semanticVSearch ranks by cosine similarity; each hit is expanded with the messages around it
match=keywordEntries(db, sessionID+":*", &ScanOption{Contains, After, Limit}) filters by keyword and time range on the server, then merges with the SQLite FTS5 archive

On history compaction, session reset, and session removal, Agenvoy lists the affected keys with Keys and deletes them in one Del, so ToriiDB holds only recent conversations. The three-tier memory design on the Agenvoy side is described in Memory System.

Tool error memory (DBErrorMemory)


The write_error tool stores a tool failure and its fix under <toolName>:<unixNano> as a JSON record with keywords, written with SetVector and a 90-day TTL. The error_history tool searches with VSearch first and falls back to a keyword scan; every record it returns is extended by another 90 days with one Expire call over all returned keys, so fixes that keep being used do not expire. See State and Memory Tools.

Tool result cache (DBToolCache)


UseKeyTTL
search_web/fetch_page results, returned directly for a repeated call with the same argumentstc:<sessionID>:<callID> (tc:global: for global tools)30 minutes
fetch_page skips URLs that returned 4xxskip4xx:<sha256(url)>90 days
fetch_page skips URLs that returned 5xxskip5xx:<sha256(url)>12 hours
fetch_page skips URLs with empty contentskipEmpty:<sha256(url)>72 hours
Provider remaining quotaprovider:quota:<id>180 seconds
Provider model lists (list, image, decision, stt, tts); deleted in one Del when the provider is changedprovider:models:<target>:<name>15 minutes
The decision model's last chosen modellastModel:<sessionID>5–60 minutes by provider

All of these rely on ToriiDB TTLs: an expired key reads as missing, so Agenvoy never cleans them up itself. See Tool Dispatch for how tool calls run.

Running-task markers (DBOnline)


Every running task writes action:<sessionID>:<taskHash> with Set every 55 seconds and a 60-second TTL, and deletes it with Del when it finishes. Agenvoy counts a session's running tasks with Keys("action:<sessionID>:*"); if a process dies, its markers expire within 60 seconds. See Running Tasks for concurrency and cancel.

中文