Seshat AIDocumentation

Documentation / Concepts

Memory and compaction

How Seshat keeps your sessions, stays inside the model's context window, and remembers things across sessions.

Seshat has three kinds of memory, each with its own job.

1. Session history

Every conversation is saved in a local SQLite database: messages, tool results, token usage and metadata. Sessions survive restarts and can be resumed.

seshat chat --continue          # the most recent session
seshat chat --resume <id>       # a specific one
seshat sessions list

2. The context window and compaction

A model can only read so much at once. Seshat tracks how much of the window a session uses. When it passes a threshold, it compacts: older messages are summarised into a shorter form so the session can go on.

When it starts

The window Seshat works with is the model’s window minus a reserve for the summary (2,000 tokens). Two marks matter:

Below the threshold: the session runs as it isCompaction0100% = the effective windowTarget after compactionabout 50%Threshold85%, auto-compaction starts
Percentages are of the effective window. The threshold is 85% but never closer than 13,000 tokens to the end of the window.
  • The threshold: 85% of that window, but never closer than 13,000 tokens to its end. Above it, auto-compaction runs before the next model call.
  • The target: about 50% of the window. Compaction aims to land there.

In the Go SDK, turn automatic compaction on with AutoCompact in ClientConfig.

What it does

Compaction is checked before every model call, with two ways of freeing room: first a cheap one that needs no model, then a summary.

Before each model callauto-compaction checkAbove the threshold ?Nothing to dothe model call goes aheadMicro-compactiontrims large tool resultsUnder the target ?Done, no model neededthe trimmed history is keptSummarise the conversationthe session model, 2,000 tokens at mostSummary failedthe turn ends with an error;3 in a row stop the retriesKeep the recent messagesup to the target, tool pairs intactRebuild the historysummary, marker, kept messagesnoyesyesnoerror
Auto-compaction, checked before every model call. Orange is the model-based step, red is a failure, green is a successful end.
  1. Threshold. Below it, nothing happens.
  2. Micro-compaction. Large tool results are trimmed. If that brings the session under the target, there is no model call at all.
  3. Summary. Otherwise the session’s own model writes a summary of the conversation, told to preserve the active requests, the decisions made, the tool outcomes that still matter and the unresolved work.
  4. Recent messages are kept. Starting from the newest message, Seshat keeps messages until it reaches the target. The cut is then moved back if needed, so a tool result is never kept without the tool call it answers.
  5. Rebuild. The new history is the summary, a marker saying the context was compacted, and the kept messages.

If the summary call fails, that turn ends with an error. By default the summary is written by the model of the session, so compaction works with any provider. In Go, ClientConfig.CompactSummaryModel picks another model for it.

When compaction keeps failing

The runtime counts failed compactions from one turn to the next. After 3 in a row it stops trying to summarise for the rest of the session, instead of paying for a call that keeps failing. The request is still checked against the hard limit of the window: if it does not fit, it fails on your machine with the compact_full error, before it reaches the provider.

What the history looks like afterwards

msg 1msg 2msg 3msg 4msg 5msg 6msg 7msg 8msg 9msg 10SummaryCompaction markermsg 6msg 7msg 8msg 9msg 10summarisedBefore: usage above the thresholdAfter: about half of the windowThe cut is moved back when needed, so a tool result is never kept without the tool call it answers.The summary asks the model to preserve active requests, decisions made, tool outcomes that still matter and unresolved work.
The older messages are replaced by one summary and a marker. The recent ones are kept as they were.

3. Notes that last

The agent can keep notes across sessions with the memory tools. They form a small knowledge graph of named entities and observations:

ToolUse
memory_create_entitiesCreate entities (a person, a project, a decision)
memory_add_observationsAdd facts to an entity
memory_search_nodesSearch what is stored
memory_open_nodesRead specific entities

You can also read and edit memory yourself from the command line:

seshat memory                                          # show user memory
seshat memory --scope project                          # this project's memory
seshat memory --action set --key style --value "short answers, no preamble"
seshat memory --action clear --scope user
seshat memory --action context                         # what would be given to the agent

--scope is user, project or cross (shared across sessions).

Documents and knowledge

Memory is about the conversation and what the agent learns. For large bodies of documents, Seshat has a retrieval layer (chunking, embeddings, hybrid search) in the SDK. It is covered in Retrieval and knowledge.

Updated on 2026-10-13