Scratchpad Storage
Use different storage tools for different kinds of task data: shared facts, collaborative notes, large binary values, and workspace files. Each has a different lifetime and access pattern.
- Python
- TypeScript
- Rust
- Go
- C#
- Java
from ish import ContextStore
context = ContextStore(
initial_data={"project": "Revenue Forecast"},
storage_dir="./artifacts",
)
context.set("q3_revenue", 4_200_000, author="analyst")
print(context.get("q3_revenue"))
context.write_file("summary.txt", "Q3 revenue: 4.2 million\n")
print(context.read_file("summary.txt"))
import { ContextStore, IshClient } from "ish-harness";
const client = new IshClient();
const context = new ContextStore(client, "./artifacts");
context.set("q3_revenue", 4_200_000, { author: "analyst" });
console.log(context.get("q3_revenue")?.value);
context.writeFile("summary.txt", "Q3 revenue: 4.2 million\n");
console.log(context.readFile("summary.txt"));
context.close();
client.close();
use ish_harness::protocols::{context_read_file, context_write_file};
use ish_harness::{context_create_storage_dir, ContextStore};
use serde_json::json;
let context = ContextStore::new();
context.set("q3_revenue", json!(4_200_000), "analyst", "", None);
if let Some(entry) = context.get("q3_revenue") {
println!("{}", entry.value);
}
let storage_dir = context_create_storage_dir("./artifacts")?;
let storage = storage_dir.to_string_lossy();
context_write_file(&storage, "summary.txt", "Q3 revenue: 4.2 million\n")?;
println!("{}", context_read_file(&storage, "summary.txt")?);
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, "./artifacts")
if err != nil {
panic(err)
}
defer store.Close()
_, _ = store.SetWithRevision("q3_revenue", 4_200_000, nil, "analyst", "", nil)
if entry, ok, err := store.Get("q3_revenue"); err == nil && ok {
fmt.Println(entry["value"])
}
if _, err := store.WriteFile("summary.txt", "Q3 revenue: 4.2 million\n"); err != nil {
panic(err)
}
content, err := store.ReadFile("summary.txt")
if err != nil {
panic(err)
}
fmt.Println(content)
}
using Ish.Harness;
using var client = new IshClient();
using var context = new ContextStore(client, "./artifacts");
context.Set("q3_revenue", 4_200_000, author: "analyst");
Console.WriteLine(context.Get("q3_revenue")?.GetProperty("value").GetInt64());
context.WriteFile("summary.txt", "Q3 revenue: 4.2 million\n");
Console.WriteLine(context.ReadFile("summary.txt"));
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, "./artifacts")) {
context.set("q3_revenue", 4_200_000, "analyst", "", null);
System.out.println(context.get("q3_revenue").path("value").asLong());
context.writeFile("summary.txt", "Q3 revenue: 4.2 million\n");
System.out.println(context.readFile("summary.txt"));
}
- Shared values and rooted files (
ContextStore): Share values up to10 MiBper key. An optional version check rejects an update if the value changed since it was read. File access can be confined to a chosen directory. - Worker update store (
LwwScratchpad/SharedScratchpad): A small in-memory store for exchanging updates. If two workers change the same key, the most recent update wins; ties use a stable source name. Your application is responsible for sending updates between instances. - Large content storage (
BlobTable/ObjectTable): Keep large or binary results outside the conversation and pass a short reference to the stored value. Storage can use disk with a bounded memory cache. - Objects kept in the current application process (
HostObjectTable/set_host_value): Keep values such as database connections that cannot be represented as JSON. They are available only to that running application and are lost when it exits.
Choose where to put a value
| Use | Good fit for | Shared with | Survives restart? |
|---|---|---|---|
ContextStore | Named JSON values and searchable documents | Application, agent, and subagents | In memory by default; durable with a persistence store and namespace. storage_dir still stores files, not these values |
SharedScratchpad | Small values updated by concurrent workers | Workers using the same scratchpad | In memory; export or synchronize state explicitly |
| Blob references | Large text or binary tool results | Tools that receive the reference | Can use disk-backed blob storage |
| Host object storage | Non-JSON objects such as connection pools | Code in the same host process | No; the object is process-local |
Context values, rooted files
When constructed with storage_dir, ContextStore canonicalizes the root via
context_create_storage_dir and enforces Rust-owned lexical and symlink path
confinement (context_check_storage_path) on every write_file / writeFile /
WriteFile and read_file / readFile / ReadFile call. Absolute paths,
.. traversal segments, and symlinks resolving outside storage_dir fail with
"Access outside storage_dir is denied.".
All six SDKs expose ContextStore through the shared Rust context operations;
method signatures and return shapes vary by language (Context remains a
backward-compatible alias in Python). The five host SDKs also provide
language-specific, process-local fallbacks for non-JSON host objects. In Rust,
ContextStore manages JSON entries while ish_harness::context_create_storage_dir and
ish_harness::protocols::{context_write_file, context_read_file} expose the
same rooted file routines.
Exchange worker updates
Use SharedScratchpad (Python) or LwwScratchpad (TypeScript, Rust, Go, C#,
Java) when your application exchanges small updates among agents or workers.
Each instance keeps its own local copy; your application sends updates between
instances and asks each copy to merge them. The update with the later timestamp
wins. If timestamps match, a stable source name breaks the tie. Invalid JSON
values are rejected before they can change the saved state.
- Python
- TypeScript
- Rust
- Go
- C#
- Java
from ish import SharedScratchpad
node_a = SharedScratchpad(node_id="node-a")
node_b = SharedScratchpad(node_id="node-b")
node_a.set("phase", "build", timestamp=100.0)
node_b.set("phase", "test", timestamp=105.0)
node_a.merge(node_b.export())
print(node_a.get("phase")) # "test"
import { IshClient, LwwScratchpad } from "ish-harness";
const client = new IshClient();
const nodeA = new LwwScratchpad(client, "node-a");
const nodeB = new LwwScratchpad(client, "node-b");
nodeA.set("phase", "build", 100.0);
nodeB.set("phase", "test", 105.0);
nodeA.merge(nodeB.export());
console.log(nodeA.get("phase")); // "test"
nodeA.close();
nodeB.close();
client.close();
use ish_harness::LwwScratchpad;
let node_a = LwwScratchpad::new("node-a");
let node_b = LwwScratchpad::new("node-b");
node_a.set_json("phase", r#""build""#, 100.0)?;
node_b.set_json("phase", r#""test""#, 105.0)?;
for (key, (val, ts, node)) in node_b.export_entries() {
node_a.merge_entry_json_if_newer(&key, &val, ts, &node)?;
}
println!("{:?}", node_a.get("phase"));
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()
nodeA, err := ish.NewLwwScratchpad(client, "node-a")
if err != nil {
panic(err)
}
defer nodeA.Close()
nodeB, err := ish.NewLwwScratchpad(client, "node-b")
if err != nil {
panic(err)
}
defer nodeB.Close()
_ = nodeA.Set("phase", "build", ish.Float64Ptr(100.0))
_ = nodeB.Set("phase", "test", ish.Float64Ptr(105.0))
exported, _ := nodeB.Export()
_, _ = nodeA.Merge(exported)
if val, err := nodeA.Get("phase"); err == nil {
fmt.Println(val)
}
}
using Ish.Harness;
using var client = new IshClient();
using var nodeA = new LwwScratchpad(client, "node-a");
using var nodeB = new LwwScratchpad(client, "node-b");
nodeA.Set("phase", "build", timestamp: 100.0);
nodeB.Set("phase", "test", timestamp: 105.0);
nodeA.Merge(nodeB.Export());
Console.WriteLine(nodeA.Get("phase")?.GetString());
import io.github.ishharness.IshClient;
import io.github.ishharness.LwwScratchpad;
import java.nio.file.Path;
import java.util.Map;
try (var client = new IshClient(Path.of(System.getenv("ISH_NATIVE_LIBRARY")));
var nodeA = new LwwScratchpad(client, "node-a");
var nodeB = new LwwScratchpad(client, "node-b")) {
nodeA.set("phase", "build", 100.0);
nodeB.set("phase", "test", 105.0);
nodeA.merge(Map.of(
"phase", Map.of("value", "test", "timestamp", 105.0, "node_id", "node-b")));
System.out.println(nodeA.get("phase").asText());
}
Store large values as blobs
Large binary values can be kept outside the prompt and passed as short references. ISH checks that a retrieved value matches the saved value. Configure storage_dir when files must survive process restarts; see the Context API reference for limits and methods.
Cross-SDK behavior
| Need | Shared capability | SDK notes |
|---|---|---|
| Shared values and document search | Available in all six SDKs | Python also accepts the older name Context |
| Workspace files | ContextStore can read and write files under its configured root | Path checks prevent escaping that root |
| Host objects | Kept in process-local host memory | Not shared across processes |
| Collaborative notes | SharedScratchpad merges updates by timestamp | Available across all six SDKs |
| Large values | Stored separately and passed between tools as short references | Available across all six SDKs |
Keep values shared between processes in JSON format; language objects such as
connections stay local to the process. Attaching a
ContextStore with storage_dir to an agent mounts artifact tools
(write_artifact, read_artifact, list_artifacts), but does not inject file
bodies into model prompts automatically. See the
Context API reference for full signatures.