Blackboard Document Retrieval
Use ContextStore as a shared workspace for values and documents used by your
application, an agent, and its subagents. The model does not receive every value
automatically: it can search or read the parts it needs through context tools.
Each value has a version number. An update can require the version you last
read, so a newer change is not silently overwritten. Values are limited to
10 MiB per key.
- Python
- TypeScript
- Rust
- Go
- C#
- Java
import asyncio
from ish import Agent, ContextStore
async def main() -> None:
context = ContextStore()
rev = context.set("case_status", "under_review", author="coordinator")
context.set("invoice_total", 1250.00, author="coordinator")
# Only update if the value has not changed since it was read.
rev = context.set("case_status", "ready_for_audit", author="coordinator", expected_rev=rev)
agent = Agent(
name="reviewer",
model="gpt-4o-mini",
instructions="Use the context tools to check the case status and invoice total.",
context=context,
)
result = await agent.run("Summarize the current case information.")
print(result.content)
asyncio.run(main())
import { Agent, ContextStore, IshClient } from "ish-harness";
const client = new IshClient();
const context = new ContextStore(client);
let rev = context.set("case_status", "under_review", { author: "coordinator" });
context.set("invoice_total", 1250.0, { author: "coordinator" });
rev = context.set("case_status", "ready_for_audit", {
author: "coordinator",
expectedRev: rev,
});
const agent = new Agent({
name: "reviewer",
model: { provider: "openai_chat", name: "gpt-4o-mini" },
instructions:
"Use the context tools to check the case status and invoice total.",
context,
});
const result = await agent.run("Summarize the current case information.");
console.log(result.content);
context.close();
client.close();
use std::sync::Arc;
use ish_harness::{Agent, ContextStore, OpenAIModel};
use serde_json::json;
let context = ContextStore::new();
let rev = context.set("case_status", json!("under_review"), "coordinator", "", None);
context.set("invoice_total", json!(1250.0), "coordinator", "", None);
let _next_rev = context.set_with_occ(
"case_status",
json!("ready_for_audit"),
"coordinator",
"",
None,
Some(rev),
)?;
let agent = Agent::builder(Arc::new(model))
.name("reviewer")
.instructions("Use the context tools to check the case status and invoice total.")
.context(context)
.build()?;
package main
import (
"context"
"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)
}
_, _ = store.SetWithRevision("invoice_total", 1250.0, nil, "coordinator", "", nil)
_, err = store.SetWithRevision("case_status", "ready_for_audit", &rev, "coordinator", "", nil)
if err != nil {
panic(err)
}
result, err := client.Run(context.Background(), ish.AgentRunRequest{
AgentName: "reviewer",
Model: &ish.AgentModel{Provider: "openai_chat", Name: "gpt-4o-mini"},
SystemPrompt: ish.StringPtr("Use the context tools to check the case status and invoice total."),
UserPrompt: ish.StringPtr("Summarize the current case information."),
Context: store,
})
if err != nil {
panic(err)
}
fmt.Println(result["content"])
}
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");
context.Set("invoice_total", 1250.0, author: "coordinator");
_ = context.SetWithRevision("case_status", "ready_for_audit", expectedRevision: rev, author: "coordinator");
var result = client.Run(new AgentRunRequest
{
AgentName = "reviewer",
Model = new AgentModel { Provider = "openai_chat", Name = "gpt-4o-mini" },
SystemPrompt = "Use the context tools to check the case status and invoice total.",
UserPrompt = "Summarize the current case information.",
Context = context,
});
Console.WriteLine(result.GetProperty("content").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)) {
long rev = context.setWithRevision("case_status", "under_review", "coordinator", "", null, null);
context.set("invoice_total", 1250.0, "coordinator", "", null);
context.setWithRevision("case_status", "ready_for_audit", "coordinator", "", null, rev);
var request = new IshClient.AgentRequest(
"gpt-4o-mini",
"Use the context tools to check the case status and invoice total.",
"Summarize the current case information.")
.agentName("reviewer")
.provider("openai_chat")
.context(context);
var result = client.runAgent(request);
System.out.println(result.path("content").asText());
}
Avoid overwriting a newer update
When multiple agents or application tasks update the same Blackboard key at
once, an older write can overwrite a newer one. The optional expected_rev
argument makes an update conditional on the version you previously read. In
other words, the write succeeds only if nobody has changed the value since you
read it:
- When creating a new key, use version
0so the write fails if that key already exists. - When updating a value, pass the version you read. The write succeeds only if that version is still current, then advances the version by one.
- If the version no longer matches, the update is rejected and includes the current version and a short preview so your application can decide what to do.
The agent receives only key names and short previews automatically. It can read the relevant portions on demand, instead of placing every large value in the conversation.
Attaching Blackboard context across the 6 SDKs
All six SDKs expose ContextStore through shared Rust 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. When a
ContextStore is attached to an agent, it exposes tools for searching,
reading, and updating shared context. It can also save accepted tool results
under their tool names, so the agent and its subagents can reuse them.
Search documents by relevant passages
Large JSON payloads, YAML configs, Markdown specifications, and source code
large files do not belong wholesale in the model prompt. The document search
helper, available in each SDK, detects common file formats and returns the
sections relevant to a query. You can use it directly or through the
multi-action blackboard tool:
| Source | Best for | Example task |
|---|---|---|
| JSON or YAML | Looking up a field or comparing configuration values | Find the retry limit for a service |
| Markdown | Navigating a specification or runbook by heading | Read the deployment section |
| Source code | Locating declarations and relevant code sections | Find the handler for an endpoint |
| Plain text | Searching logs, notes, or unstructured documents | Find the entries around an error |
The tools can inspect a document, search relevant passages, compare several queries, and read a selected section. Large documents are returned in bounded pieces; the full text stays in the store. See the Context API reference for operation options and limits.
- Python
- TypeScript
- Rust
- Go
- C#
- Java
from ish import ContextStore, DocumentIndex, ProgressiveContext
source = '{"service":{"name":"ledger","retries":4},"notes":"Retry on 503."}'
with DocumentIndex(source) as idx:
print(idx.inspect())
print(idx.search("ledger retry", limit=4))
print(idx.compare([("svc", "ledger"), ("err", "503")], limit_each=1))
print(idx.read(path="$.service.retries"))
prog = ProgressiveContext(initial_data={"config": source})
print(prog.document_search("config", "ledger", limit=4))
blackboard_tools = prog.get_tools(agent_name="auditor")
import {
ContextStore,
DocumentIndex,
IshClient,
ProgressiveContext,
} from "ish-harness";
const client = new IshClient();
const source = '{"service":{"name":"ledger","retries":4},"notes":"Retry on 503."}';
const idx = new DocumentIndex(client, source);
console.log(idx.inspect());
console.log(idx.search("ledger retry", 4));
console.log(
idx.compare(
[
{ label: "svc", query: "ledger" },
{ label: "err", query: "503" },
],
1,
),
);
console.log(idx.read({ path: "$.service.retries" }));
console.log(idx.stats());
idx.close();
// Mount progressive blackboard tool over an existing ContextStore
const store = new ContextStore(client);
store.set("config", source);
const prog = new ProgressiveContext(store, "config");
const blackboardTools = prog.getTools("auditor");
store.close();
client.close();
use ish_harness::{context::DocumentIndex, ContextStore};
use serde_json::json;
let source = r#"{"service":{"name":"ledger","retries":4},"notes":"Retry on 503."}"#;
// Standalone DocumentIndex
let idx = DocumentIndex::new(source, None);
println!("{}", idx.inspect());
println!("{}", idx.search("ledger retry", 4));
let queries = vec![
("svc".to_string(), "ledger".to_string()),
("err".to_string(), "503".to_string()),
];
println!("{}", idx.compare(&queries, 1));
println!("{}", idx.read(1, None, Some("$.service.retries"), false)?);
println!("{}", idx.stats_json());
// Or index keys stored inside ContextStore directly
let store = ContextStore::new();
store.set("config", json!(source), "host", "", None);
println!("{}", store.document_search("config", "ledger", 4)?);
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()
source := `{"service":{"name":"ledger","retries":4},"notes":"Retry on 503."}`
idx, err := ish.NewDocumentIndex(client, source)
if err != nil {
panic(err)
}
defer idx.Close()
fmt.Println(idx.Inspect())
fmt.Println(idx.Search("ledger retry", 4))
fmt.Println(idx.Compare([]ish.DocumentQuery{
{Label: "svc", Query: "ledger"},
{Label: "err", Query: "503"},
}, 1))
fmt.Println(idx.Read(1, nil, "$.service.retries", false))
fmt.Println(idx.Stats())
store, _ := ish.NewContextStore(client, "")
defer store.Close()
_, _ = store.Set("config", source)
prog, _ := ish.NewProgressiveContext(store, "config")
blackboardTools, _ := prog.GetTools("auditor")
_ = blackboardTools
}
using Ish.Harness;
using var client = new IshClient();
const string source = """{"service":{"name":"ledger","retries":4},"notes":"Retry on 503."}""";
using var idx = new DocumentIndex(client, source);
Console.WriteLine(idx.Inspect());
Console.WriteLine(idx.Search("ledger retry", 4));
Console.WriteLine(idx.Compare([("svc", "ledger"), ("err", "503")], 1));
Console.WriteLine(idx.Read(path: "$.service.retries"));
Console.WriteLine(idx.Stats());
using var store = new ContextStore(client);
store.Set("config", source);
var prog = new ProgressiveContext(store, "config");
var blackboardTools = prog.GetTools("auditor");
import io.github.ishharness.ContextStore;
import io.github.ishharness.DocumentIndex;
import io.github.ishharness.IshClient;
import io.github.ishharness.ProgressiveContext;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
try (var client = new IshClient(Path.of(System.getenv("ISH_NATIVE_LIBRARY")))) {
String source = "{\"service\":{\"name\":\"ledger\",\"retries\":4},\"notes\":\"Retry on 503.\"}";
try (var idx = new DocumentIndex(client, source)) {
System.out.println(idx.inspect());
System.out.println(idx.search("ledger retry", 4));
System.out.println(idx.compare(
List.of(Map.of("label", "svc", "query", "ledger"), Map.of("label", "err", "query", "503")),
1));
System.out.println(idx.read(1, null, "$.service.retries", false));
System.out.println(idx.stats());
}
try (var store = new ContextStore(client)) {
store.set("config", source);
var prog = new ProgressiveContext(store, "config");
var blackboardTools = prog.getTools("auditor");
}
}
Portable behavior, host-local values
Values stored in ContextStore must be finite JSON (up to
10 MiB per key). All five host SDKs (Python, TypeScript, Go, C#, and Java)
may keep non-JSON objects such as database connections in the current running
process. Those objects are not saved, shared with subagents, or available to
other processes.
Next: Context concepts, Scratchpad & Artifact Storage, and the Context API reference.