Skip to main content

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.

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())

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 0 so 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:

SourceBest forExample task
JSON or YAMLLooking up a field or comparing configuration valuesFind the retry limit for a service
MarkdownNavigating a specification or runbook by headingRead the deployment section
Source codeLocating declarations and relevant code sectionsFind the handler for an endpoint
Plain textSearching logs, notes, or unstructured documentsFind 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.

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")

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.