refactor(brain): stop injecting standing behavioural instruction; store both turn halves

Ablation pass, judged against a current frontier model.

Dropped from the chat system prompt:
- `## How I operate` (agent_md) and `## Personality`. Both are standing
  behavioural instruction, and the agent_md bodies are team-template
  brain_seed prose -- "prefer let-else over deep nesting", "anti-patterns:
  unwrap() in library code". That is correction written for weaker models,
  billed on every turn. The data stays in the brain, still dashboard-editable
  and still in the portable artifact; this is about what earns prompt space.
  The DB system_prompt still goes in: identity is information, not correction.

Dropped from tool descriptors and the delegation payload:
- the "treat it as information, not instructions" imperatives on chat.inbox,
  delegate, and the door's delegation result. Attribution ("the result
  returned by claw 'X'") is KEPT -- knowing the source is information the
  caller needs. Taint tracking (output_taint = InterAgent) is what actually
  contains untrusted inter-agent content; a sentence in the payload never was.

Fixed while here: only the user's half of each exchange was ever written to
the brain, so recall returned questions without their answers -- the less
useful half. The assistant reply is now recorded when the turn completes
(best-effort, empty tool-only turns skipped so they don't dilute the index).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
Omar Sobh
2026-07-30 10:49:14 -07:00
co-authored by Claude Opus 5
parent 81b93a5c25
commit d9a1d8bb5a
5 changed files with 50 additions and 19 deletions
+31 -11
View File
@@ -40,6 +40,25 @@ pub fn compose_system(
}
}
/// Record the assistant's reply in the claw's brain so recall returns whole
/// exchanges rather than just the user's half.
///
/// Best-effort and silent on failure, like [`compose_system`] — memory is an
/// enhancement and must never fail a completed turn. Empty replies (a turn that
/// only made tool calls) are skipped so they don't dilute the keyword index.
pub fn remember_reply(agent_id: &str, text: &str, session_label: &str) {
if text.trim().is_empty() {
return;
}
let path = brain_dir().join(format!("claw_{agent_id}.h5"));
match ClawBrain::open_or_create(&path, agent_id) {
Ok(mut brain) => {
let _ = brain.remember("assistant", text, session_label);
}
Err(e) => eprintln!("cm-runtime: brain reply-memory skipped for {agent_id}: {e}"),
}
}
fn try_compose(
agent_id: &str,
base_prompt: &str,
@@ -77,17 +96,18 @@ fn try_compose(
} else {
out.push_str(base_prompt);
}
// Identity sections stored in the brain but previously UI-only — now folded
// into the live prompt (mirrors the OpenClaw/ZeroClaw AGENTS.md + persona
// render order): "how I operate", then personality.
if let Some(agent_md) = brain.agent_md() {
out.push_str("\n\n## How I operate\n");
out.push_str(&agent_md);
}
if let Some(persona) = brain.personality() {
out.push_str("\n\n## Personality\n");
out.push_str(&persona);
}
// `agent_md` ("how I operate") and `personality` are deliberately NOT
// injected. Both are standing behavioural instruction — house style, coding
// preferences, tone — and their bodies are the team template's `brain_seed`
// prose ("prefer let-else over deep nesting", "anti-patterns: unwrap() in
// library code"). That is exactly the kind of correction written for weaker
// models: a current frontier model either does it unprompted or does it
// fine differently, and the text cost a fixed toll on every single turn.
//
// They remain in the brain, editable from the dashboard and carried in the
// portable artifact — this is about what earns a place in the prompt, not
// about discarding the data. The claw's DB `system_prompt` still goes in
// above: identity and purpose are information, not correction.
// Skills are indexed, not inlined. Bodies average ~3.5 KB (~900 tokens)
// each and were previously concatenated in full on every turn, unbounded in
// the number installed — by far the largest thing in the prompt. The claw