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.
- Python
- TypeScript
- Rust
- Go
- C#
- Java
from ish import ContextStore
context = ContextStore()
rev = context.set("case_status", "under_review", author="coordinator")
print(context.get("case_status"), "rev:", rev)
context.close()
import { ContextStore, IshClient } from "ish-harness";
const client = new IshClient();
const context = new ContextStore(client);
const rev = context.set("case_status", "under_review", { author: "coordinator" });
console.log(context.get("case_status")?.value, "rev:", rev);
context.close();
client.close();
use ish_harness::ContextStore;
use serde_json::json;
let context = ContextStore::new();
let rev = context.set("case_status", json!("under_review"), "coordinator", "", None);
if let Some(entry) = context.get("case_status") {
println!("{} (rev {})", entry.value, rev);
}
package main
import (
"fmt"
"github.com/ish-harness/ish-harness/sdks/go"
)
func main() {
client, err := ish.NewClient()
if err != nil {
panic(err)
}
defer client.Close()
store, err := ish.NewContextStore(client, "")
if err != nil {
panic(err)
}
defer store.Close()
rev, err := store.SetWithRevision("case_status", "under_review", nil, "coordinator", "", nil)
if err != nil {
panic(err)
}
if entry, ok, err := store.Get("case_status"); err == nil && ok {
fmt.Printf("%v (rev %d)\n", entry["value"], rev)
}
}
using Ish.Harness;
using var client = new IshClient();
using var context = new ContextStore(client);
var rev = context.SetWithRevision("case_status", "under_review", null, author: "coordinator");
var entry = context.Get("case_status");
Console.WriteLine($"{entry?.GetProperty("value").GetString()} (rev {rev})");
import io.github.ishharness.ContextStore;
import io.github.ishharness.IshClient;
import java.nio.file.Path;
try (var client = new IshClient(Path.of(System.getenv("ISH_NATIVE_LIBRARY")));
var context = new ContextStore(client)) {
long rev = context.setWithRevision("case_status", "under_review", "coordinator", "", null, null);
System.out.println(context.get("case_status").path("value").asText() + " (rev " + rev + ")");
}
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.
| SDK | Durable constructor |
|---|---|
| Python | ContextStore(persistence=store, namespace="tenant-42") |
| TypeScript | new ContextStore(client, "./artifacts", { persistence: store, namespace: "tenant-42" }) |
| Go | NewContextStoreWithPersistence(client, "./artifacts", store, "tenant-42") |
| C# | new ContextStore(client, store, "tenant-42", storageDirectory: "./artifacts") |
| Java | new ContextStore(client, store, "tenant-42", "./artifacts") |
| Rust core | SqliteWalLogger 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.
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 (
MemoryStoreandAgentsMdMemory).
Where each kind of context belongs
| Need | Channel | What it carries | Lifetime by default |
|---|---|---|---|
| Continue short-term dialogue | Session history | User, assistant, and tool messages | Saved when a persistence store and session_id are supplied; otherwise current agent/run state |
| Share facts and documents | ContextStore (Blackboard) | Named JSON values and searchable documents | In memory by default; optionally durable in a persistence store under a namespace |
| Exchange updates between workers | SharedScratchpad | Small values with conflict-resolving updates | In memory; synchronize or persist explicitly |
| Notify an agent or queue work | EventBus / mailbox | Events and targeted messages | EventBus is process-local; SQLite mailbox survives restart |
| Recall scoped facts | MemoryStore | Searchable notes by scope | In memory by default; optionally durable in a persistence store under a namespace |
| Load repository guidance | AgentsMdMemory | AGENTS.md instructions and recorded pitfalls | Repository file on disk |
| Delegate a task | Subagent call | Task prompt, selected context, and child report | Parent run; use persistence for durable work |
| Keep a large result out of prompts | Stored result reference | Short reference to content held separately | Depends 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
- Shared working context and document search — share values, search documents, and reject updates based on an older value.
- Worker updates and file storage — exchange small updates and store larger artifacts.
- Tool result management — keep large tool results outside the conversation and retrieve them when needed.
- 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.