The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
docs(agent/experience): add documentation for experience operations and store
Steven Enamakelc58bad177448
diff --git a/crates/openhuman-core/src/agent/experience/README.md b/crates/openhuman-core/src/agent/experience/README.mdindex d4b9800ca0..d143bc15d2 100644--- a/crates/openhuman-core/src/agent/experience/README.md+++ b/crates/openhuman-core/src/agent/experience/README.md@@ -55,7 +55,7 @@ None: no `bus.rs`; this module does not publish or subscribe to `DomainEvent`s.Records are stored through the `Memory` trait (no dedicated DB), served by `DriverMemory` over the memory driver bound for the workspace subtree:- Namespace: `agent_experience` (`AGENT_EXPERIENCE_NAMESPACE`).-- Value: **base64 of the `AgentExperience` JSON**, `MemoryCategory::Custom("agent_experience")`. Base64 keeps the memory layer's bare-numeric PII scrubber from rewriting a Luhn-valid millisecond timestamp and corrupting the JSON (#5209); reads fall back to plain JSON for legacy rows.+- Value: the `AgentExperience` JSON, `MemoryCategory::Custom("agent_experience")`. The memory layer's corroborated PII policy leaves 13-digit millisecond timestamps alone (#6855); reads still accept the base64-wrapped rows written before that (#5209).## Dependencies@@ -75,7 +75,7 @@ Records are stored through the `Memory` trait (no dedicated DB), served by `Driv## Notes / gotchas-- Two redaction layers at write time: `capture::build_experience` masks `Bearer …`, `sk-…`, and `token=/password:` pairs with `types::redact_text`; `store::put` then runs the full `memory::safety::sanitize_text` scrubber (private keys, vendor secrets, national-ID / phone / card PII) over the free-text fields. The base64 payload means the memory layer's own content scrub is a no-op, so the store-level scrub is what preserves the invariant.+- Two redaction layers at write time: `capture::build_experience` masks `Bearer …`, `sk-…`, and `token=/password:` pairs with `types::redact_text`; `store::put` then runs the full `memory::safety::sanitize_text` scrubber (private keys, vendor secrets, national-ID / phone / card PII) over the free-text fields.- Retrieval scoring is **lexical, not embedding-based**: term sets keep only tokens length > 2, normalized lowercase; score combines tool overlap (weighted highest), tag overlap, query-term overlap over summary+lesson+hints, plus small agent/entrypoint match boosts and a confidence prior. `max_hits == 0` short-circuits to empty. The live-turn path additionally drops hits with no `match_reasons`.- `render_experience_hits` is hard byte-capped (`max_bytes`) with UTF-8-boundary-safe truncation, so the injected prompt block can't blow the context budget.- The capture hook is gated by an `enabled` flag passed at construction; when disabled `on_turn_complete` is a no-op, and capture failures only `log::warn!` (never fail the turn).diff --git a/crates/openhuman-core/src/agent/experience/ops.rs b/crates/openhuman-core/src/agent/experience/ops.rsindex 97c1f5ce32..0662a2e8ef 100644--- a/crates/openhuman-core/src/agent/experience/ops.rs+++ b/crates/openhuman-core/src/agent/experience/ops.rs@@ -44,12 +44,9 @@ use std::sync::Arc;/// [`MemoryGuard`](crate::memory::guard::MemoryGuard) truncates/// `store` content at `capture_max_chars`, which/// `MemoryHooksConfig::default()` sets to **500**. An `AgentExperience` is-/// stored as base64 of its serialized JSON — precisely so the free-text-/// scrubber cannot rewrite a Luhn-valid millisecond timestamp and corrupt the-/// payload (#5209) — and truncated base64 does not decode, so the record would-/// silently vanish on read. That is the same class of bug #5209 fixed, so the-/// pre-#5560 behaviour is preserved exactly: no policy layer between this store-/// and the driver. The store runs the full scrubber over its own free-text+/// stored as its serialized JSON, and truncated JSON does not parse, so the+/// record would silently vanish on read. So the pre-#5560 behaviour is+/// preserved exactly: no policy layer between this store and the driver. The store runs the full scrubber over its own free-text/// fields before serialization (`store::redact_experience`), which is what/// keeps that safe rather than merely unguarded.///diff --git a/crates/openhuman-core/src/agent/experience/store.rs b/crates/openhuman-core/src/agent/experience/store.rsindex 6eb6791b52..e66cc2ea5e 100644--- a/crates/openhuman-core/src/agent/experience/store.rs+++ b/crates/openhuman-core/src/agent/experience/store.rs@@ -9,34 +9,14 @@ use std::sync::Arc;pub const AGENT_EXPERIENCE_NAMESPACE: &str = "agent_experience";-/// Encode a serialized experience so its structured payload survives the memory-/// layer's free-text content sanitizer.-///-/// `Memory::store` runs every document's `content` through the secret/PII-/// scrubber (`tinycortex … safety::sanitize_text`), whose *bare-numeric* PII-/// patterns (credit-card via Luhn, CPF, CNPJ) match any 11–19-digit run. A-/// serialized `AgentExperience` embeds `created_at_ms` / `updated_at_ms` as bare-/// 13-digit millisecond timestamps, so whenever `now_ms()` happens to be-/// Luhn-valid (~10% of the time) the scrubber rewrites the number to a-/// `[REDACTED_PII_*]` token — corrupting the JSON so it no longer parses back on-/// read. The record then silently vanishes from [`AgentExperienceStore::list`],-/// making recall non-deterministic run-to-run (issue #5209).-///-/// Base64 has no 11+-digit bare-numeric runs (and no `Bearer`/`sk-` literals),-/// so the sanitizer is a guaranteed no-op over the encoded payload and the-/// round-trip is lossless. The store still redacts the sensitive free-text-/// fields itself via [`redact_experience`] before serialization, so this does-/// not weaken secret handling.-fn encode_experience_payload(json: &str) -> String {- base64::engine::general_purpose::STANDARD.encode(json.as_bytes())-}-/// Decode a stored experience payload.///-/// New records are base64(JSON) (see [`encode_experience_payload`]); legacy-/// records are plain JSON. A JSON object starts with `{`, which is not in the-/// base64 alphabet, so the base64 decode fails cleanly on legacy content and we-/// fall back to parsing it as plain JSON — no ambiguity, no migration step.+/// Records are plain JSON. Rows written before the engine's bare-card gate+/// became corroborated (#6855) were base64(JSON) to dodge a Luhn-valid 13-digit+/// millisecond timestamp being rewritten to `[REDACTED_PII_*]` (#5209); they are+/// still read here. A JSON object starts with `{`, which is not in the base64+/// alphabet, so the base64 decode fails cleanly on plain content and we fall+/// back to parsing it directly: no ambiguity, no migration step.fn decode_experience_payload(stored: &str) -> Result<AgentExperience, String> {if let Ok(bytes) = base64::engine::general_purpose::STANDARD.decode(stored.trim()) {if let Ok(text) = std::str::from_utf8(&bytes) {@@ -94,7 +74,6 @@ impl AgentExperienceStore {experience = redact_experience(experience);let content = serde_json::to_string(&experience).map_err(|e| e.to_string())?;- let content = encode_experience_payload(&content);self.memory.store(AGENT_EXPERIENCE_NAMESPACE,@@ -243,26 +222,15 @@ fn storage_key(id: &str) -> String {}/// Redact secrets/PII from every captured free-text field before the record is-/// serialized and stored.-///-/// Previously the memory layer's own content scrubber ran over the stored JSON-/// blob, so any secret in any field was redacted at write time. We now-/// base64-encode the payload before [`Memory::store`] (so a Luhn-valid-/// millisecond timestamp can no longer be misread as a credit card and corrupt-/// the JSON — #5209), which makes that store-time scrub a no-op over the-/// payload. To preserve the security invariant we must therefore run the SAME-/// full scrubber ([`sanitize_text`] — private-key blocks,-/// Bearer/`sk-`/Stripe/npm/OAuth secrets, and the full national-ID / phone /-/// credit-card PII set) over the sensitive free-text fields ourselves, here,-/// before serialization. A secret placed in any of these is then redacted in-/// both the stored record and what recall returns.+/// serialized and stored, so a secret in any of them is gone from both the+/// stored record and what recall returns.///-/// Scope note: only free-text/description fields are scrubbed. The numeric-/// timestamp/confidence fields are left untouched — scrubbing structural-/// numbers is exactly what caused the corruption we fixed. `id` is the storage-/// key (scrubbing it would desync key vs. content; a secret-bearing key is-/// rejected up front by the memory layer's `has_likely_secret` guard) and-/// key (scrubbing it would desync key vs. content); it is left intact.+/// The full scrubber ([`sanitize_text`]: private-key blocks, Bearer/`sk-`/+/// Stripe/npm/OAuth secrets, national-ID / phone / card PII) runs under the+/// host's corroborated policy, which leaves bare 13-digit epoch-millisecond+/// timestamps alone. Only free-text fields are scrubbed: the numeric+/// timestamp/confidence fields are structural, and `id` is the storage key+/// (scrubbing it would desync key and content), so both stay intact.fn redact_experience(mut experience: AgentExperience) -> AgentExperience {fn scrub(value: &str) -> String {sanitize_text(value).value