This document explains how to integrate s3mem-harness into an external agent runtime such as OpenClaw.
s3mem-harness should sit between:
- the agent runtime that produces step logs
- the downstream planner / answerer / policy model
Recommended flow:
- The runtime emits step logs.
- The adapter normalizes them into structured trajectory steps.
S3MemHarnessserializes them into episodic memories.- At answer time,
S3MemHarness.query(...)returns a compact evidence bundle. - The downstream LLM or planner consumes only this bundle instead of the full trajectory.
This keeps the integration simple and preserves the main value of S3Mem:
- structured write
- anchor-sensitive retrieval
- compact evidence routing
Use this if you already have full trajectories on disk.
from s3mem_harness import S3MemHarness
harness = S3MemHarness()
harness.ingest_trajectory(steps, adapter="openclaw", episode_id="episode_001")
result = harness.query(question, mode="s3mem", top_k=24, token_budget=768)Best for:
- batch evaluation
- log replay
- retrospective analysis
Use this when the agent is still running and you want memory to grow incrementally.
from s3mem_harness import S3MemHarness
harness = S3MemHarness()
for raw_step in stream_of_agent_steps:
harness.ingest_trajectory([raw_step], adapter="openclaw", episode_id="episode_live", append=True)
# later
result = harness.query(question, mode="s3mem", top_k=24, token_budget=768)Best for:
- long-running agents
- continual memory accumulation
- answer-on-demand systems
Use this when the agent runtime and answer-time stack are separated.
from s3mem_harness import S3MemHarness
harness = S3MemHarness()
harness.ingest_trajectory(steps, adapter="openclaw", episode_id="episode_001")
harness.save_jsonl("memory.jsonl")
other = S3MemHarness()
other.load_jsonl("memory.jsonl")
result = other.query(question)Best for:
- multi-process pipelines
- serving systems
- caching memory separately from the agent loop
The harness is designed to feed a downstream model with a compact, structured evidence package.
Suggested prompt skeleton:
You are answering a question about an agent trajectory.
Question:
{question}
Selected evidence steps:
{selected_steps}
Compressed evidence:
{compressed_text}
Support objects:
{support_objects}
Support relations:
{support_relations}
Evidence chain:
{evidence_chain}
Answer using only the evidence above. If evidence is insufficient, say so.
Use this for the main plugin behavior.
It enables:
- structured memory text
- reranking
- seed/anchor-aware retrieval
- compact evidence packing
Use this if you want structured memory text but a weaker evidence harness.
Best for:
- ablation
- integration comparison
Use this as a plain summary-based baseline.
Best for:
- control comparisons
- debugging
The harness works best when the caller can provide structured question metadata.
Example:
{
"question": "What did the agent do one step after obtaining alarmclock 3?",
"metadata": {
"answer_type": "action_after_gain_item",
"item": "alarmclock 3",
"occurrence": "first",
"delta": 1
}
}If metadata is unavailable, the harness still runs, but retrieval is more generic.
For OpenClaw-like systems, the cleanest integration point is usually:
- after each environment step is logged
- before the final answerer or planner is called
Recommended minimum fields per step:
stepobservationactioninfo.locationinfo.inventoryinfo.objects
Recommended optional fields:
info.eventinfo.gained_itemsinfo.relationsinfo.reward
This repository includes:
examples/openclaw_trajectory.json- small synthetic example
examples/openclaw_real_trace_excerpt.json- real OpenClaw-compatible excerpt derived from an ALFWorld expert rollout
examples/openclaw_integration_demo.py- end-to-end integration demo
- Use
append=Truewhen maintaining one long-running memory store. - Use
save_jsonl()to persist memory across processes. - Keep
token_budgetsmall for latency-sensitive systems. - Increase
top_konly if recall is the bottleneck. - Prefer
s3memmode unless you are explicitly running a baseline.
This plugin is not tied to a single benchmark. It is designed to be embedded into any step-structured agent runtime that can expose observations, actions, and optional state metadata.