Skip to main content
The @session tool lets the agent recall earlier saved conversations — “what did we decide about the cache last week?”. Implemented natively over the existing SessionManager. Inspired by hermes-agent’s session_search. The recall flow has two halves: search finds which session discussed something, get reads that part of it.

Subcommands


Ranked search (BM25)

Search is ranked, not just matched: every message of every saved session is scored as a BM25 document by the same keyless lexical engine the knowledge base uses. Two-level semantics balance recall and precision:
  • A session qualifies when every query term appears somewhere in the conversation — in any message, not necessarily the same one. “oauth refresh decision” discussed across several turns still finds the session.
  • Qualifying sessions rank by their aggregate message scores, so the session where the terms are dense and rare beats one that mentions them in passing. Snippets come from each session’s strongest messages, and the user’s own turns may take up to two of the three slots: what a user says about themselves lives in their turns, and long assistant turns would otherwise crowd it out.
  • Partial matches follow. When a query has three or more terms and some session holds all of them, up to four more sessions that hold at least half of the terms are listed after the full matches, labeled partial: 3 of 5 terms. A later update, or the second item of a count, is often worded differently from the first mention, and an all-terms filter would hide it. Two-term queries stay strict, and when no session holds every term the search still falls back to any-term, as before.

Several phrasings in one call

The user said things in their own words, not the question’s. In LongMemEval’s multi-session questions, 15% of the sessions holding the answer share no word with the question (“which projects did I lead?” against “I presented a poster on my research”). queries takes up to 6 phrasings of the same question and searches them all in one call:
  • The rankings are fused by reciprocal rank, so a session found by several phrasings rises. A session that fully matches any phrasing is a full match, and its snippets are merged without repeats.
  • When a hit was found by only some of the phrasings, it says which: found by: presented my research.
  • query, when also given, is the first phrasing. The list is accepted under queries, alternatives, phrasings, paraphrases or also, as an array or as one string separated by | or newlines.
  • from, to and as_of bound every phrasing, and a time expression in the first one sets the window, as it does for query.
  • The memory card teaches the agent to pass several wordings this way, and always for counts and lists. On LongMemEval the agent used it in all 500 questions, needed 3.4 tool calls per question instead of 4.7, and answered 247 of the 260 validation questions instead of 240.

By meaning (embeddings)

When an embedding provider is configured (CHATCLI_EMBED_PROVIDER: Voyage, OpenAI, Google, Bedrock, or a local keyless Ollama), a search also adds up to 3 sessions related by meaning after every lexical hit, labeled related by meaning (similarity 0.62):
  • Only the user’s own messages are embedded: what they said about themselves is what a later question asks about.
  • The vectors live in a sealed index beside the sessions directory (session_vectors.json). It is built incrementally (at most 2,000 new messages per search, within 20 seconds), pruned when sessions are deleted or edited, and rebuilt when the provider changes (/config reload).
  • Lexical hits keep their order. Related sessions only add to them, and a provider failure or timeout adds nothing.
  • With HyDE enabled (CHATCLI_QUALITY_HYDE_ENABLED), its expansion of the question runs as one more phrasing.
With one phrasing and no embedding provider or HyDE, the result is exactly the lexical search, byte for byte.

Output

How well this works end to end is measured on LongMemEval: the session holding the answer reached the model in 470 of 470 questions. Every hit carries its save date with the weekday and its age in calendar days measured from the current date, so a “how long ago” question is answered from the result instead of guessed. A session saved on the 15th at 18:11 and read on the 18th at 01:48 is 3d ago (three calendar dates), not the two days that 55 elapsed hours would suggest; under a day the age is in minutes or hours. For arithmetic beyond that (days between two sessions, “last Saturday”), use @date. The date is the session file’s last save — a session resumed and saved again moves to its new date.

Dates: from, to and as_of

  • from / to bound the save date. They take an ISO date (2023-05-01, 2023-05; a day or a month includes all of it) or a natural expression in English or Portuguese (3 weeks ago, há 3 semanas, abril). Either one alone works. A value that is not a date is an error, never ignored.
  • A time expression inside query sets the window when from/to are absent (“ibotta há 3 semanas”); the remaining words rank the hits.
  • No query with a window lists that window’s sessions, newest first.
  • as_of (2006-01-02, 2006-01-02 15:04 or RFC 3339) is the date relative expressions and the ages are counted from, for that one call only — nothing else in the session changes. Without it they are counted from the current date, which CHATCLI_NOW can pin for a whole run.
  • No migration: sessions saved by any earlier version, including the legacy plain-array format, are searched and dated the same way; the format did not change.

Automatic saving on exit

The interactive REPL auto-saves the conversation on exit under a reserved autosave-YYYYMMDD-HHMMSS name, and the MCP/ACP server mirrors each live conversation as a rolling mcp-<session> file — every conversation becomes retrievable memory even when nobody ran /session save. Trivial sessions (fewer than 2 non-system messages) and one-shot -p runs are never saved. Gated by CHATCLI_SESSION_AUTOSAVE (on by default; CHATCLI_MCP_SESSION_AUTOSAVE overrides for MCP). Retention is time-first: machine sessions expire after the 90-day TTL with a 600-file keep backstop, user-named sessions never expire, and the distilled memory layers (facts, episodes, rollups) survive any cleanup — see Session Management › Automatic Cleanup.

Notes

  • search, get and list are read-only and concurrency-safe. get accepts id or session in place of name, the words a model tends to use for what a search result printed.
  • Stored system prompts are masked out: they are excluded from the search corpus and ranking, and get replaces them with an omission marker — a recap query returns the conversation, never the session’s own instructions echoed back.
  • Searches both the chat and agent history of saved sessions.
  • Pair with Session Management (/session save) for named checkpoints — autosave covers everything else.
Use alongside @memory (facts) and @skill (procedures): @session is episodic memory (“what we talked about”), while memory and skills are distilled knowledge. The 50 most recent saved sessions are also notes of the knowledge graph, linked to the projects their names mention and to the episodes of the same day, so @memory neighbors on a project points at the conversations about it (the vault’s session notes carry the title and links, never the transcript).