Skip to main content

Context for Agents

ISH separates short-term dialogue, working context, and long-term agent memory. Dialogue is the user/assistant/tool history for a session; see Short-Term Dialogue. ContextStore is working state shared by an agent, tools, or subagents. MemoryStore holds reusable knowledge the agent can recall across sessions and may save through its memory tools. ContextStore and MemoryStore are in memory by default; pass a persistence store and namespace to write their portable JSON entries to SQLite or a configured StorageConnector. Opaque host-language objects remain process-local.

from ish import ContextStore

context = ContextStore()
rev = context.set("case_status", "under_review", author="coordinator")
print(context.get("case_status"), "rev:", rev)
context.close()

Persist working context when needed​

ContextStore remains in memory unless you supply the persistence store and a stable namespace. Durable mode stores portable JSON entries through Rust's shared persistence engine. With SQLite, those entries are stored in the app_records table under the context_entries collection in the database file opened by SQLiteLogger / PersistenceStore. With a StorageConnector, they are written to the connector's configured database or record service under the same logical collection. storage_dir is still only the rooted file area; it does not select the state database. Opaque host objects remain local to the process.

For example, in Python, this persists portable context values in ./data/agent-state.sqlite3. Reopen that same file and use the same namespace after a restart to restore them:

import asyncio
from ish import ContextStore, SQLiteLogger

async def main():
store = SQLiteLogger(db_path="./data/agent-state.sqlite3")
await store.initialize()
context = ContextStore(persistence=store, namespace="tenant-42")
try:
context.set("case_status", {"state": "under_review"})
finally:
context.close()
await store.close()

asyncio.run(main())

The default ContextStore() constructor does not create a database or persist values. Supplying storage_dir alone also does not persist its key/value state; it only configures the rooted file area.

SDKDurable constructor
PythonContextStore(persistence=store, namespace="tenant-42")
TypeScriptnew ContextStore(client, "./artifacts", { persistence: store, namespace: "tenant-42" })
GoNewContextStoreWithPersistence(client, "./artifacts", store, "tenant-42")
C#new ContextStore(client, store, "tenant-42", storageDirectory: "./artifacts")
Javanew ContextStore(client, store, "tenant-42", "./artifacts")
Rust coreSqliteWalLogger exposes app-record methods; the shared context.create operation accepts persistence_handle and namespace for the Rust-owned store.

The namespace is an application-level isolation boundary. Recreate the store with the same persistence backend and namespace to load its entries after a restart. Use distinct namespaces for unrelated users or tenants.

For SQLite, the persistence store's database path is the file receiving this data; ContextStore entries are stored in app_records under context_entries. See SQLite WAL for a complete database-path setup and Custom Storage Connectors for PostgreSQL, SQL Server, Redis, and other connector-backed databases. Passing storage_dir by itself only configures rooted artifact files; it does not select or create the context database.

ISH keeps the conversation sent to the model separate from runtime-managed state. The model sees instructions, recent messages, and compact references. The runtime stores shared values and large artifacts, then retrieves the requested content when a tool needs it.

The Control Plane is optional

Context storage runs inside the SDK process. It does not require the separate Control Plane service.

Follow a value through a run​

The model receives a compact reference when a result is stored outside the conversation. Before a tool uses that reference, the runtime resolves it to the stored value and applies the configured policy. The reference is not a security boundary by itself: permissions and data policies decide what may be accessed.

Two kinds of information appear throughout this guide:

  • Conversation context is the messages and instructions sent to the model.
  • Working context is data held by the context store or saved tool results. It is not automatically copied in full into each model request.

By default, attaching a ContextStore adds a short index of available keys. The agent can use Blackboard tools to search or read relevant content. If a specific small value must always be visible to the model, project that key into the prompt explicitly.

Which Primitive Should I Use?​

  • Share values or documents across your app, agent, and subagents: Working context, including optional checks that reject an update if someone changed the value first.
  • Keep large tool results out of model messages while chaining tools: Tool result management stores the full result separately and passes a short reference between tools.
  • Exchange worker updates and resolve conflicts consistently: Worker updates explains the merge rule; your application sends updates between instances.
  • Keep long conversations within a chosen size: Conversation compaction summarizes older turns while retaining the original history for review.
  • Preserve agent or project knowledge across runs, or load repository rules: See Memory (MemoryStore and AgentsMdMemory).

Where each kind of context belongs​

NeedChannelWhat it carriesLifetime by default
Continue short-term dialogueSession historyUser, assistant, and tool messagesSaved when a persistence store and session_id are supplied; otherwise current agent/run state
Share facts and documentsContextStore (Blackboard)Named JSON values and searchable documentsIn memory by default; optionally durable in a persistence store under a namespace
Exchange updates between workersSharedScratchpadSmall values with conflict-resolving updatesIn memory; synchronize or persist explicitly
Notify an agent or queue workEventBus / mailboxEvents and targeted messagesEventBus is process-local; SQLite mailbox survives restart
Recall scoped factsMemoryStoreSearchable notes by scopeIn memory by default; optionally durable in a persistence store under a namespace
Load repository guidanceAgentsMdMemoryAGENTS.md instructions and recorded pitfallsRepository file on disk
Delegate a taskSubagent callTask prompt, selected context, and child reportParent run; use persistence for durable work
Keep a large result out of promptsStored result referenceShort reference to content held separatelyDepends on the configured storage

Data sharing across agents​

A parent and child can exchange information in several ways. Attach a ContextStore when both should read or update the same named working values. Delegate with a task prompt when the child should return a focused report. Pass a context reference when the payload is large. Use EventBus messages to notify an agent that context changed or work is ready; use a durable mailbox when queued messages must survive a restart. Messages can carry context, but they do not become shared state automatically. These channels are different: an event announces or delivers a message, while Blackboard holds shared mutable state that agents can query and update.

Continue exploring context and memory​

  1. Shared working context and document search — share values, search documents, and reject updates based on an older value.
  2. Worker updates and file storage — exchange small updates and store larger artifacts.
  3. Tool result management — keep large tool results outside the conversation and retrieve them when needed.
  4. Conversation compaction — summarize older turns while retaining the original history for review.

For scoped recall and repository rules, see Memory. A persistence store can hold session history, ContextStore entries, and MemoryStore entries; session IDs and namespaces define separate data boundaries.