Skip to main content

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.

from ish import ContextStore

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

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:

CategoryOperationShared Semantics in ish_context::ContextStore
KV & OCCset / 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 & OCCget / GetPython returns the decoded JSON value (or default); TS, Rust, Go, C#, and Java return the ContextEntry (value, revision, author, description, timestamp).
KV & OCChas, delete / delete_entry, list / list_entries, clearCheck presence, delete (optionally guarded by expected_rev), enumerate metadata with 120-char preview strings, or reset entries.
Prompt Blockget_system_prompt_block / systemPromptBlockRenders keys, authors, revisions, and single-line 120-char previews so models browse on demand instead of ingesting full values.
Document Retrievaldocument_inspect, document_search, document_compare, document_read, section, projectModality-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 & Patchread_lines, read_bytes, grep, append, replace_lines, patchLine-range, byte-offset, regex match, append, line-splice, and structural JSON merge-patch / code-anchor mutations.
Rooted Artifactswrite_file, read_file, list_filesWrites and reads files confined lexically and via canonical symlink resolution inside the configured storage_dir.
Agent Toolsget_tools / agentTools / AgentToolsExposes 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 provide HostObjectTable (DataTables.HostObjectTable in Java; in Python ObjectTable is an alias for HostObjectTable, whereas Rust, TypeScript, Go, C#, and Java expose a separate Rust-backed byte ObjectTable with a 64 MiB FIFO cache).
  • Content-Addressed Binary & Multi-Writer State: Use BlobTable for large or binary payloads referenced by $BLOB:<sha256> handles (64 MiB byte-bounded FIFO cache) and LwwScratchpad when 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.