Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

remember items[]: compact per-item receipts (9x smaller in the agent's context), hints once, bare-string items

garrytan5855e916edd3
diff --git a/docs/protocol/MEMORY_VERBS_v1.md b/docs/protocol/MEMORY_VERBS_v1.md
index 557bb5ae42..7ebefab980 100644
--- a/docs/protocol/MEMORY_VERBS_v1.md
+++ b/docs/protocol/MEMORY_VERBS_v1.md
@@ -284,9 +284,10 @@ Optional response fields; clients must ignore any they do not know.
#### remember items: several facts in one call (additive)
-`items` (1 to 20 objects) replaces `fact` for a batch, typically right before
-context compaction. Each item takes `fact` plus optional `entity`, `kind`,
-`ttl`, `visibility`, `provenance` and `infer_entity`; top-level `provenance`,
+`items` (1 to 20) replaces `fact` for a batch, typically right before
+context compaction. Each item is a fact string or an object with `fact` plus
+optional `entity`, `kind`, `ttl`, `visibility`, `provenance` and
+`infer_entity`; top-level `provenance`,
`kind`, `ttl`, `visibility` and `infer_entity` are the defaults. Passing both
`fact` and `items` is `invalid_params`.
@@ -297,9 +298,11 @@ item index, so replaying the same `request_id` replays each child's outcome and
writes nothing twice.
Response: `{ protocol_version, request_id, items[], saved, failed, partial,
-next? }`. Each `items[]` entry is the single-fact response plus `index` and its
-child `request_id`, or `{ index, request_id, status: "failed", error: { code,
-message } }`. `partial: true` means some items saved and some failed; resend
+hints?, next? }`. Each `items[]` entry is a compact receipt `{ index,
+request_id, status, id?, entity_slug?, warnings?, valid_until?, state? }`
+(`state` and `retry_after_ms` only when the write is not yet committed), or
+`{ index, request_id, status: "failed", error: { code, message } }`. Hints the
+single-fact response would repeat per item appear once in `hints`. `partial: true` means some items saved and some failed; resend
only the failed items, in a new call with a new `request_id`.
### entity(name) — read, zero LLM, p99 < 100ms
diff --git a/llms-full.txt b/llms-full.txt
index c7730a4745..15c67dbef9 100644
--- a/llms-full.txt
+++ b/llms-full.txt
@@ -8807,9 +8807,10 @@ Optional response fields; clients must ignore any they do not know.
#### remember items: several facts in one call (additive)
-`items` (1 to 20 objects) replaces `fact` for a batch, typically right before
-context compaction. Each item takes `fact` plus optional `entity`, `kind`,
-`ttl`, `visibility`, `provenance` and `infer_entity`; top-level `provenance`,
+`items` (1 to 20) replaces `fact` for a batch, typically right before
+context compaction. Each item is a fact string or an object with `fact` plus
+optional `entity`, `kind`, `ttl`, `visibility`, `provenance` and
+`infer_entity`; top-level `provenance`,
`kind`, `ttl`, `visibility` and `infer_entity` are the defaults. Passing both
`fact` and `items` is `invalid_params`.
@@ -8820,9 +8821,11 @@ item index, so replaying the same `request_id` replays each child's outcome and
writes nothing twice.
Response: `{ protocol_version, request_id, items[], saved, failed, partial,
-next? }`. Each `items[]` entry is the single-fact response plus `index` and its
-child `request_id`, or `{ index, request_id, status: "failed", error: { code,
-message } }`. `partial: true` means some items saved and some failed; resend
+hints?, next? }`. Each `items[]` entry is a compact receipt `{ index,
+request_id, status, id?, entity_slug?, warnings?, valid_until?, state? }`
+(`state` and `retry_after_ms` only when the write is not yet committed), or
+`{ index, request_id, status: "failed", error: { code, message } }`. Hints the
+single-fact response would repeat per item appear once in `hints`. `partial: true` means some items saved and some failed; resend
only the failed items, in a new call with a new `request_id`.
### entity(name) — read, zero LLM, p99 < 100ms
diff --git a/src/core/remember-batch.ts b/src/core/remember-batch.ts
index ec06f1f3b6..9b6a3c1cbc 100644
--- a/src/core/remember-batch.ts
+++ b/src/core/remember-batch.ts
@@ -10,6 +10,9 @@
* deterministic child request_id derived from the caller's request_id and
* the item index, so replaying the same request_id replays each child
* (committed children return their receipt, nothing is written twice);
+ * - each item's receipt is compact (status, fact id, entity, warnings, and
+ * the write state only when it is not committed); repeated hints appear
+ * once at the top level;
* - publication is per item: the response reports each item's status and
* `partial: true` when some failed. Replaying the same request_id returns
* the same per-item outcomes; failed items are resubmitted in a new call
@@ -52,6 +55,8 @@ export async function runRememberBatch(ctx: OperationContext, p: Record<string,
const shared: Record<string, unknown> = {};
for (const key of ['provenance', 'source_id', 'kind', 'ttl', 'visibility', 'infer_entity']) if (p[key] !== undefined) shared[key] = p[key];
const normalized = items.map((raw, index) => {
+ // A bare string is the common shorthand for one fact.
+ if (typeof raw === 'string') return { ...shared, fact: raw };
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
throw verbError('invalid_params', `items[${index}] must be an object.`, 'Each item is { "fact": "...", optional entity, kind, ttl, visibility, provenance }.');
}
@@ -69,11 +74,21 @@ export async function runRememberBatch(ctx: OperationContext, p: Record<string,
if (ctx.dryRun) return { dry_run: true, action: 'remember', items: normalized.length, protocol_version: 1 };
const requestId = typeof p.request_id === 'string' && p.request_id ? p.request_id : randomUUID();
const results: BatchItemResult[] = [];
+ const hints = new Set<string>();
for (const [index, item] of normalized.entries()) {
const child = childRequestId(requestId, index);
try {
const out = await single(ctx, { ...item, request_id: child }) as Record<string, unknown>;
- results.push({ ...out, index, request_id: child, status: String(out?.status ?? 'saved') });
+ // Compact per-item receipt: a batch lands in the agent's context, so it carries what the agent acts on, not the full single-fact envelope.
+ if (typeof out?.hint === 'string') hints.add(out.hint);
+ results.push({
+ index, request_id: child, status: String(out?.status ?? 'saved'),
+ ...(out?.id !== undefined ? { id: out.id } : {}),
+ ...(out?.entity_slug !== undefined ? { entity_slug: out.entity_slug } : {}),
+ ...(Array.isArray(out?.warnings) && out.warnings.length ? { warnings: out.warnings } : {}),
+ ...(out?.valid_until ? { valid_until: out.valid_until } : {}),
+ ...(typeof out?.state === 'string' && out.state !== 'committed' ? { state: out.state, retry_after_ms: out.retry_after_ms ?? null } : {}),
+ });
} catch (e) {
if (!(e instanceof OperationError)) throw e;
results.push({ index, request_id: child, status: 'failed', error: { code: e.code, message: e.message, ...(e.detail ? { detail: e.detail } : {}) } });
@@ -87,6 +102,7 @@ export async function runRememberBatch(ctx: OperationContext, p: Record<string,
saved: results.length - failed,
failed,
partial: failed > 0 && failed < results.length,
+ ...(hints.size ? { hints: [...hints] } : {}),
...(failed > 0 ? { next: 'Fix each failed item as its error says, then send only the failed items in a new remember call with a new request_id; the saved items are already stored.' } : {}),
};
}
diff --git a/test/remember-batch.test.ts b/test/remember-batch.test.ts
index 566e12337a..da574d6526 100644
--- a/test/remember-batch.test.ts
+++ b/test/remember-batch.test.ts
@@ -63,3 +63,20 @@ describe('remember items[] batch', () => {
}
});
});
+
+describe('remember items[] shorthand and receipts', () => {
+ test('a bare string item is one fact with the shared provenance', async () => {
+ const { handler, writes } = fakeSingle();
+ const out = await runRememberBatch(ctx, { provenance: 'p', items: ['Prefers tea', { fact: 'Ships Fridays' }] }, handler, ve);
+ expect(out.saved).toBe(2);
+ expect(writes.map(w => w.fact)).toEqual(['Prefers tea', 'Ships Fridays']);
+ });
+
+ test('item receipts are compact: status and id, no full single-fact envelope', async () => {
+ const handler = async (c: OperationContext, p: Record<string, unknown>) => (c.dryRun ? { dry_run: true }
+ : { status: 'inserted', id: '7', entity_slug: null, warnings: ['NO_ENTITY'], hint: 'link it', outcome: { big: 'x'.repeat(500) }, state: 'committed', protocol_version: 1, fact: p.fact });
+ const out = await runRememberBatch(ctx, { provenance: 'p', items: [{ fact: 'a' }, { fact: 'b' }] }, handler, ve) as { items: Array<Record<string, unknown>>; hints: string[] };
+ expect(Object.keys(out.items[0]).sort()).toEqual(['entity_slug', 'id', 'index', 'request_id', 'status', 'warnings']);
+ expect(out.hints).toEqual(['link it']);
+ });
+});