Skip to content

Sessions And Memory

KosmoKrator persists useful state so terminal, headless CLI, SDK, ACP, Telegram gateway, and subagents can all resume work consistently.

State is stored under ~/.kosmokrator/data in SQLite-backed repositories.

DataPurpose
SessionsConversation identity, project root, model/provider metadata, timestamps, names.
MessagesUser, assistant, tool-call, tool-result, and system context messages.
SettingsGlobal and project-scoped setting overrides.
MemoriesLong-lived project/user/decision notes injected into future sessions.
Swarm metadataSubagent tree state and output summaries.
Usage metadataToken and cost counters used for status and resume views.

Interactive:

Terminal window
kosmokrator
/rename Payment refactor
/compact
/sessions
/resume
/new
/quit

Headless:

Terminal window
kosmokrator -p "Explain the auth flow"
kosmokrator -p "Continue the previous task" --continue
kosmokrator -p "Use this exact session" --session sess_abc123
kosmokrator -p "One-off analysis" --no-session

SDK:

use Kosmokrator\Sdk\AgentBuilder;
$agent = AgentBuilder::create()
->forProject('/repo')
->resumeLatestSession()
->build();
$result = $agent->collect('Continue the previous task.');

ACP sessions are normal persisted sessions and can be resumed from the terminal when needed.

The agent can search and read past sessions when those tools are available in the active mode.

ToolPurpose
session_searchSearch prior sessions by text, project, and metadata.
session_readLoad a full transcript by session ID prefix.

Modes:

Mode/typeSession tools
Editsession_search, session_read
Plansession_search, session_read
Asksession_search
General subagentsession_search, session_read
Explore/Plan subagentsession_search, session_read

Long sessions are kept usable through a pipeline:

  1. Tool output truncation.
  2. Duplicate tool-result removal.
  3. Low-value tool-result pruning.
  4. LLM-based compaction.
  5. Oldest-turn trimming as a last resort.

Manual compaction:

Terminal window
/compact

Settings:

Terminal window
kosmokrator settings:get context.auto_compact --json
kosmokrator settings:set context.auto_compact on --global --json
kosmokrator settings:set context.reserve_output_tokens 16000 --project --json

See Context for the full pipeline.

Memories are durable facts that should survive one conversation.

TypeUse
projectArchitecture facts, repo conventions, commands, persistent environment details.
userUser preferences and workflow preferences.
decisionArchitectural decisions and trade-offs.

Interactive commands:

Terminal window
/memories
/forget 42

Agent tools:

ToolPurpose
memory_searchSearch saved memories before asking the user.
memory_saveCreate or update a durable memory.

Mode behavior:

Mode/typeMemory access
EditSearch and save.
PlanSearch only.
AskSearch only.
General subagentSearch and save.
Explore/Plan subagentSearch only.

Disable memory features:

Terminal window
kosmokrator settings:set context.memories off --global --json

Name important sessions so they are easy to resume:

Terminal window
/rename MCP implementation audit

Good names include the project area and the outcome:

WeakBetter
Fix stuffFix MCP trust policy
DocsStarlight docs migration
ReviewReview provider auth refactor

Use /sessions to inspect prior sessions. If a session contains sensitive output, delete it from the session UI or remove the underlying SQLite data after backing up anything important.

Secrets are not stored as plain session settings by provider configuration commands. Use the secret store for API keys:

Terminal window
kosmokrator secrets:list --json
kosmokrator secrets:status provider.openai.api_key --json
SymptomFix
--continue resumed the wrong workUse --session <id> from /sessions output.
Session picker is clutteredRename important sessions and clean old ones from /sessions.
Agent forgot a durable project factCheck context.memories; save or update a memory in an Edit-capable session.
Context compacts too oftenIncrease context.auto_compact_buffer_tokens carefully or use a model with a larger context window.
Context overflow warnings appearRun /compact, reduce huge tool outputs, or split the task into a new named session.