Scoped Memory Store (MemoryStore)
MemoryStore holds reusable knowledge for an agent across conversations. The agent can search existing entries and, when useful, save new facts through its memory tools. It is in memory by default. Supply a persistence store and namespace to reload and save entries through the shared Rust persistence engine. Use the namespace to isolate an agent, project, or tenant; use scopes to organize categories inside that namespace. User-specific preferences are an optional use case, not the default memory model.
- Python
- TypeScript
- Rust
- Go
- C#
- Java
from ish import MemoryStore, ScopedMemoryEntry
# Initialize with seed memories
mem = MemoryStore(initial_entries=[
ScopedMemoryEntry(key="deployment_policy", value="Review migrations before rollout", scope="agent"),
ScopedMemoryEntry(key="primary_region", value="eu-west-1", scope="project"),
])
# Store new memories
mem.store("rollback_check", "Verify the previous image remains available", scope="agent")
mem.store("service_owner", "platform-team", scope="project")
# Retrieve by key, scope
policy = mem.get("deployment_policy", scope="agent")
# Substring search across scopes
for entry in mem.search("budget"):
print(f"[{entry.scope}] {entry.key} = {entry.value}")
import { IshClient, MemoryStore } from "ish-harness";
const client = new IshClient();
const mem = new MemoryStore(client);
mem.store("deployment_policy", "Review migrations before rollout", "agent");
mem.store("primary_region", "eu-west-1", "project");
mem.store("rollback_check", "Keep the previous image available", "agent");
mem.store("service_owner", "platform-team", "project");
const policy = mem.get("deployment_policy", "agent");
const { entries } = mem.search("budget");
for (const entry of entries) {
console.log(`[${entry.scope}] ${entry.key} = ${entry.content}`);
}
mem.close();
client.close();
use ish_harness::MemoryStore;
let mem = MemoryStore::new();
mem.store("agent", "deployment_policy", "Review migrations before rollout");
mem.store("project", "primary_region", "eu-west-1");
mem.store("agent", "rollback_check", "Keep the previous image available");
mem.store("project", "service_owner", "platform-team");
if let Some(policy) = mem.get("deployment_policy", Some("agent")) {
println!("deployment_policy = {policy}");
}
for entry in mem.search("budget", None) {
println!("[{}] {} = {}", entry.scope, entry.key, entry.content);
}
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()
mem, err := ish.NewMemoryStore(client, "")
if err != nil {
panic(err)
}
defer mem.Close()
_ = mem.Store("deployment_policy", "Review migrations before rollout", "agent")
_ = mem.Store("primary_region", "eu-west-1", "project")
_ = mem.Store("rollback_check", "Keep the previous image available", "agent")
_ = mem.Store("service_owner", "platform-team", "project")
if policy, err := mem.Get("deployment_policy", "agent"); err == nil && policy != nil {
fmt.Println(*policy)
}
if res, err := mem.Search("budget", ""); err == nil {
for _, entry := range res.Entries {
fmt.Printf("[%s] %s = %s\n", entry.Scope, entry.Key, entry.Content)
}
}
}
using Ish.Harness;
using var client = new IshClient();
using var mem = new MemoryStore(client);
mem.Store("deployment_policy", "Review migrations before rollout", "agent");
mem.Store("primary_region", "eu-west-1", "project");
mem.Store("rollback_check", "Keep the previous image available", "agent");
mem.Store("service_owner", "platform-team", "project");
var policy = mem.Get("deployment_policy", "agent");
var search = mem.Search("budget");
foreach (var entry in search.Entries)
{
Console.WriteLine($"[{entry.Scope}] {entry.Key} = {entry.Content}");
}
import io.github.ishharness.IshClient;
import io.github.ishharness.MemoryStore;
import java.nio.file.Path;
try (var client = new IshClient(Path.of(System.getenv("ISH_NATIVE_LIBRARY")));
var mem = new MemoryStore(client)) {
mem.store("deployment_policy", "Review migrations before rollout", "agent");
mem.store("primary_region", "eu-west-1", "project");
mem.store("rollback_check", "Keep the previous image available", "agent");
mem.store("service_owner", "platform-team", "project");
String policy = mem.get("deployment_policy", "agent");
var search = mem.search("budget");
for (var entry : search.entries()) {
System.out.printf("[%s] %s = %s%n", entry.scope(), entry.key(), entry.content());
}
}
The constructor stays in-memory unless persistence is explicitly supplied. Durable stores use the same SQLite WAL or StorageConnector backend as agent traces. Recreate a store with the same namespace after restart to recover its entries. Context entries and memories are stored separately even when they share one persistence handle.
Find saved entries
search(query, scope?) performs case-insensitive substring matching against
each entry's key and content. A scope argument limits results to that exact
scope; results follow insertion order. Short queries work, but search does not
rank by meaning or infer related terms. Store concise notes with useful keys,
then search with words likely to appear in the note. For passage retrieval over
larger documents, use DocumentIndex instead.
Keep memories separate by scope
scope is a free-form category matched by exact equality, defaulting to
"agent" when omitted. It separates categories of knowledge, not access or
retention: persistence is controlled by the configured backend and
authorization remains the application's responsibility. Two entries may share
the same key under different scopes without overwriting one another. A
lookup without a scope returns the earliest matching entry.
| Scope | Common use |
|---|---|
agent | Agent-owned operating rules, learned tool notes, and reusable heuristics. This is the default scope. |
project | Decisions, environment facts, and conventions shared by agents working on one project. |
domain | Knowledge reused by agents with the same specialist role. |
global | Shared rules or constants when broad access is intentional. |
user | Individual preferences when an application explicitly needs user-specific memory. |
Isolate Memory Namespaces
Use a distinct namespace for each agent or project that must have isolated
long-term memory. scope is an exact-match category inside one namespace; it
is not an authorization boundary. Enforce tenant access in the application and
use distinct namespaces when separate tenants must not see one another's
memory.
Memory APIs Across SDKs
Notice that Rust's MemoryStore::store(scope, key, content) takes scope
first, whereas Python, TypeScript, Go, C#, and Java take (key, value/content, scope).
An unscoped get(key) returns the value from the most recently written scope
for that key. Use get(key, scope=...) when the exact scope matters; scoped
lookups never fall through to another scope.
Agent Memory Tools
When attached to an agent, MemoryStore avoids injecting full entry payloads
into every prompt. Instead, get_system_prompt_block() emits only a compact
index header:
[Available Memories (N items): \key1`, `key2`. Use `recall_memory` to fetch details.]`
Two Rust-backed tools let the agent manage reusable knowledge during a run:
recall_memory(query, scope?)(read_only = true,parallel_safe = true): Runsrecall_formatted(query, scope)and returns[SCOPE] key: contentlines joined by newlines.persist_memory(key, content, scope?)(mutates = true,parallel_safe = false): Writes intoMemoryStoreunderscope(ordefault_scope,"agent") and updates the trigram index immediately.
This makes long-term memory agent-managed in normal use: the model can recall relevant notes and proactively save stable findings without a person manually writing each entry. Saving still happens through an explicit tool call. The runtime does not silently turn every message into a memory, and durable storage still requires a persistence store and namespace. The model may decide not to save a particular fact, so provide clear instructions or approval rules when your application requires predictable memory updates.
Python (Agent(..., memory=mem)) and Rust (Agent::builder(model).memory(mem))
attach both tools and the prompt key-list block automatically; TypeScript, Go,
C#, and Java wire agentTools() / attachTools(...) alongside
systemPromptBlock() on the agent or request.
- Python
- TypeScript
- Rust
- Go
- C#
- Java
import asyncio
from ish import Agent, MemoryStore
async def main() -> None:
mem = MemoryStore()
mem.store("deployment_policy", "Review migrations before rollout", scope="agent")
agent = Agent(
name="assistant",
model="gpt-4o-mini",
instructions="Use saved deployment guidance. Save stable new rollout rules when useful.",
memory=mem,
)
try:
result = await agent.run("What should be checked before deployment?")
print(result.content)
finally:
agent.close()
mem.close()
asyncio.run(main())
import { Agent, IshClient, MemoryStore } from "ish-harness";
const client = new IshClient();
const mem = new MemoryStore(client);
mem.store("deployment_policy", "Review migrations before rollout", "agent");
const agent = new Agent({
name: "assistant",
model: { provider: "openai_chat", name: "gpt-4o-mini" },
instructions: `Use saved deployment guidance. Save stable new rollout rules when useful.\n\n${mem.systemPromptBlock()}`,
tools: mem.agentTools(),
});
const result = await agent.run("What should be checked before deployment?");
console.log(result.content);
agent.close();
mem.close();
client.close();
use std::{env, error::Error, sync::Arc};
use ish_harness::{Agent, MemoryStore, OpenAIModel};
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let model = OpenAIModel::new(
"gpt-4o-mini".into(),
"https://api.openai.com/v1".into(),
env::var("OPENAI_API_KEY")?,
0.2,
);
let mem = MemoryStore::new();
mem.store("agent", "deployment_policy", "Review migrations before rollout");
let agent = Agent::builder(Arc::new(model))
.name("assistant")
.instructions("Use saved deployment guidance. Save stable new rollout rules when useful.")
.memory(mem)
.build()?;
let result = agent.run("What should be checked before deployment?").await?;
println!("{}", result.content);
Ok(())
}
package main
import (
"context"
"fmt"
ish "github.com/ish-harness/ish-harness/sdks/go"
)
func main() {
client, err := ish.NewClient()
if err != nil {
panic(err)
}
defer client.Close()
mem, err := ish.NewMemoryStore(client, "agent")
if err != nil {
panic(err)
}
defer mem.Close()
if err := mem.Store("deployment_policy", "Review migrations before rollout", "agent"); err != nil {
panic(err)
}
promptBlock, err := mem.GetSystemPromptBlock()
if err != nil {
panic(err)
}
tools, err := mem.AgentTools()
if err != nil {
panic(err)
}
ctx := context.Background()
result, err := client.Run(ctx, ish.AgentRunRequest{
AgentName: "assistant",
Model: &ish.AgentModel{Provider: "openai_chat", Name: "gpt-4o-mini"},
SystemPrompt: ish.StringPtr("Use saved deployment guidance. Save stable new rollout rules when useful.\n\n" + promptBlock),
Tools: tools,
UserPrompt: ish.StringPtr("What should be checked before deployment?"),
})
if err != nil {
panic(err)
}
fmt.Println(result["content"])
}
using Ish.Harness;
using var client = new IshClient();
using var mem = new MemoryStore(client);
mem.Store("deployment_policy", "Review migrations before rollout", "agent");
var result = client.Run(new AgentRunRequest
{
AgentName = "assistant",
Model = new AgentModel { Provider = "openai_chat", Name = "gpt-4o-mini" },
SystemPrompt = $"Use saved deployment guidance. Save stable new rollout rules when useful.\n\n{mem.GetSystemPromptBlock()}",
Tools = mem.AgentTools(),
UserPrompt = "What should be checked before deployment?",
});
Console.WriteLine(result.GetProperty("content").GetString());
import io.github.ishharness.IshClient;
import io.github.ishharness.MemoryStore;
import java.nio.file.Path;
try (var client = new IshClient(Path.of(System.getenv("ISH_NATIVE_LIBRARY")));
var mem = new MemoryStore(client)) {
mem.store("deployment_policy", "Review migrations before rollout", "agent");
var request = new IshClient.AgentRequest(
"gpt-4o-mini",
"Use saved deployment guidance. Save stable new rollout rules when useful.\n\n" + mem.systemPromptBlock(),
"What should be checked before deployment?")
.agentName("assistant")
.provider("openai_chat");
mem.attachTools(request);
var result = client.runAgent(request);
System.out.println(result.path("content").asText());
}