執行期

對話狀態

讓對話能在各輪次之間連貫進行的持久性與暫態記錄。

對話狀態

這是什麼

讓對話能在各輪次之間連貫進行的持久性與暫態記錄。

白話解釋

在一本厚小說中夾入書籤,讓你可以放下書本數週後再拿起來,從離開的那一頁和那一句繼續讀,而不需要重讀之前的所有章節。對話狀態就是 Hermes 版本的書籤:記錄說過的話和做過的決定,準備好讓對話隨時可以繼續。

為什麼重要

讓對話從中斷處繼續進行之所以能實現,是因為 turn_finalizer 在每一輪之後寫入持久性和暫態記錄,而 turn context 在下一輪開始時將它們讀回。去掉這個機制,每一條訊息都得從頭建立上下文,這就失去了對話相較於無狀態 API 呼叫的意義。Compression 控制這些狀態有多少能在長期存活,而 session search 則讓使用者之後能再次檢索它們。

How it works

After each turn, _persist_session (run_agent.py) writes the message history to state.db, a SQLite store that’s the canonical record — an optional JSON snapshot per session can also be enabled for external tooling, but the database is what Hermes actually reads from. Writes are deduplicated with a marker stamped onto already-flushed messages, so repeated persistence calls from different exit paths don’t create duplicate rows. At the start of the next turn, agent/turn_context.py’s build_turn_context step restores the system prompt and splices the prior exchanges back into the working message list, reading from that same state.db. Only the SQLite store is considered the source of truth; the optional JSON exports exist purely for external inspection.