Context API
ContextStore is the shared state API for namespaced JSON values, searchable
documents, and files confined to a configured directory. The SDKs expose
shared Rust-backed operations for this portable context state. Their method
names, signatures, return shapes, and host-object adapters differ, so this
overview does not claim complete parity across SDKs. Python also keeps Context
as an older name for ContextStore. Non-JSON host objects can be held by the
host SDK, but those objects stay in that process and are not written to the
database. See
Context storage for the database-backed constructor and
SQLite WAL for the tables used when persistence is
enabled.
- Python
- TypeScript
- Rust
- Go
- C#
- Java
from ish import ContextStore
context = ContextStore()
rev = context.set("case_status", "under_review", author="coordinator")
print(rev, context.get("case_status"))
import { ContextStore, IshClient } from "ish-harness";
const client = new IshClient();
const context = new ContextStore(client);
context.set("case_status", "under_review", { author: "coordinator" });
console.log(context.get("case_status")?.value);
use ish_harness::ContextStore;
use serde_json::json;
let context = ContextStore::new();
context.set("case_status", json!("under_review"), "coordinator", "", None);
let entry = context.get("case_status").expect("entry was just written");
println!("{} (rev {})", entry.value, entry.revision);
store, err := ish.NewContextStore(client, "")
if err != nil {
panic(err)
}
defer store.Close()
_, err = store.SetWithRevision("case_status", "under_review", nil, "coordinator", "", nil)
entry, ok, err := store.Get("case_status")
if ok {
fmt.Println(entry["value"])
}
using Ish.Harness;
using var client = new IshClient();
using var context = new ContextStore(client);
context.Set("case_status", "under_review", author: "coordinator");
var entry = context.Get("case_status");
Console.WriteLine(entry?.GetProperty("value").GetString());
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)) {
context.set("case_status", "under_review", "coordinator", "", null);
System.out.println(context.get("case_status").path("value").asText());
}
Each example below writes "case_status" as "under_review", attributed to
"coordinator", and reads it back.
Python's get(key) returns the decoded value directly (metadata and revision
are exposed via list_entries()), whereas TypeScript, Rust, Go, C#, and Java
return the full ContextEntry record containing value, revision, author,
description, and timestamp.
For Java and Go, set ISH_NATIVE_LIBRARY to the native library path described
in the SDK overview (or let Go discover
target/release/ automatically). C# and TypeScript resolve the native library
according to their package configuration.
Common operations
The table summarizes shared ish_context::ContextStore operations exposed by
the six SDKs. Method casing, signatures, and result types are language-specific:
| Category | Operation | Shared Semantics in ish_context::ContextStore |
|---|---|---|
| KV & OCC | set / Set (expected_rev) | Stores JSON up to 10 MiB (10,485,760 bytes) and returns the new u64 revision. Passing expected_rev enforces CAS (0 requires insert-only; mismatch raises a revision conflict). |
| KV & OCC | get / Get | Python returns the decoded JSON value (or default); TS, Rust, Go, C#, and Java return the ContextEntry (value, revision, author, description, timestamp). |
| KV & OCC | has, delete / delete_entry, list / list_entries, clear | Check presence, delete (optionally guarded by expected_rev), enumerate metadata with 120-char preview strings, or reset entries. |
| Prompt Block | get_system_prompt_block / systemPromptBlock | Renders keys, authors, revisions, and single-line 120-char previews so models browse on demand instead of ingesting full values. |
| Document Retrieval | document_inspect, document_search, document_compare, document_read, section, project | Modality-aware structural outlines (json, yaml, markdown, code, text), cached Bm25Index (k1=1.5, b=0.75) passage search, and bounded 80-line slices (MAX_OUTPUT_CHARS = 9,000). |
| Slice & Patch | read_lines, read_bytes, grep, append, replace_lines, patch | Line-range, byte-offset, regex match, append, line-splice, and structural JSON merge-patch / code-anchor mutations. |
| Rooted Artifacts | write_file, read_file, list_files | Writes and reads files confined lexically and via canonical symlink resolution inside the configured storage_dir. |
| Agent Tools | get_tools / agentTools / AgentTools | Exposes the Rust-backed context tool descriptors (context_get, context_set, context_patch, context_document_*, and artifact tools when enabled) for an agent loop. |
Portability
Use JSON-compatible payloads on set when state must cross FFI boundaries,
pass between agent languages, persist to WAL snapshots, or be read by Rust-side
model tools (10 MiB maximum serialized payload per key).
- Process-Local Host Objects (All 5 Host SDKs): Python (
set_host_value/get_host_value), TypeScript and Java (setHostValue/getHostValue), and Go and C# (SetHostValue/GetHostValue) also support storing arbitrary in-process host objects (such as live database handles, sockets, or closures) that never cross FFI into Rust and are kept separately from JSON keys. For standalone opaque object references by handle ID, all five host SDKs provideHostObjectTable(DataTables.HostObjectTablein Java; in PythonObjectTableis an alias forHostObjectTable, whereas Rust, TypeScript, Go, C#, and Java expose a separate Rust-backed byteObjectTablewith a64 MiBFIFO cache). - Content-Addressed Binary & Multi-Writer State: Use
BlobTablefor large or binary payloads referenced by$BLOB:<sha256>handles (64 MiBbyte-bounded FIFO cache) andLwwScratchpadwhen independent writers need(timestamp, node_id)CRDT convergence instead of strict OCC.
See context architecture, Blackboard and progressive retrieval, scratchpad and storage, and tool output management.