loki-mode 6.83.1 → 7.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -34,6 +34,7 @@
34
34
  | UI components, design tokens, .loki/magic/, Gate 12 | `magic-modules.md` |
35
35
  | Legacy healing, modernization, archaeology | `healing.md` |
36
36
  | Plan deepening, knowledge extraction | `compound-learning.md` |
37
+ | Managed Agents memory, multiagent council, flag hierarchy | `memory.md` |
37
38
 
38
39
  ## Module Descriptions
39
40
 
@@ -0,0 +1,185 @@
1
+ # Memory Integration (v7.0.0+)
2
+
3
+ Loki Mode ships two memory layers:
4
+
5
+ 1. **Local memory** (`.loki/memory/`) -- project-scoped, authoritative, versioned
6
+ by git. Always on.
7
+ 2. **Managed Agents memory** (Anthropic cloud store) -- optional mirror +
8
+ cross-project read. Opt-in behind flags. Filesystem-mounted at
9
+ `/mnt/memory/` inside a Managed Agents session.
10
+
11
+ Local is the source of truth. Managed is a scoped projection with audit
12
+ history and cross-project visibility.
13
+
14
+ ## Flag hierarchy
15
+
16
+ ```
17
+ LOKI_MANAGED_AGENTS=false <- parent (required for any managed path)
18
+ |
19
+ +-- LOKI_MANAGED_MEMORY=false <- memory shadow-write + REASON augment
20
+ | |
21
+ | +-- LOKI_MANAGED_MEMORY_HYDRATE=false <- session-boot pull from store
22
+ |
23
+ +-- LOKI_EXPERIMENTAL_MANAGED_AGENTS=false <- umbrella for multiagent (research preview)
24
+ |
25
+ +-- LOKI_EXPERIMENTAL_MANAGED_REVIEW=false <- code-review council via callable_agents
26
+ +-- LOKI_EXPERIMENTAL_MANAGED_COUNCIL=false <- completion council via callable_agents
27
+ ```
28
+
29
+ **Every child on + parent off is fail-fast (exit 2).** Do not silent-downgrade.
30
+
31
+ ## Schema mapping
32
+
33
+ Loki's local schemas map 1:1 to paths inside a Managed Agents memory store:
34
+
35
+ | Local schema (memory/schemas.py) | Store path | Default scope |
36
+ |----------------------------------|------------|---------------|
37
+ | `EpisodeTrace` | `/episodic/{date}/{task_id}.json` | user read_write |
38
+ | `SemanticPattern` | `/patterns/{pattern_id}.json` | org read_only |
39
+ | `ProceduralSkill` | `/skills/{skill_id}.json` | org read_only |
40
+ | `FrictionPoint` | `/anti_patterns/{id}.json` | org read_only |
41
+ | `FailureMode` | `/anti_patterns/{id}.json` | org read_only |
42
+
43
+ **Never ship a read_write `semantic` store.** Prompt injection into a
44
+ read_write shared store poisons every future session.
45
+
46
+ ## How RARV-C uses managed memory
47
+
48
+ ### REASON phase (read augment)
49
+
50
+ `autonomy/run.sh::retrieve_memory_context` (around line 7865) always runs
51
+ local retrieval first. When `LOKI_MANAGED_AGENTS=true` and
52
+ `LOKI_MANAGED_MEMORY=true`, it then runs a 5-second subprocess that calls
53
+ `python3 -m memory.managed_memory.retrieve --query "$goal"` and appends
54
+ any related prior learnings AFTER the local results (local wins on
55
+ duplicate paths).
56
+
57
+ Failures emit a `managed_agents_fallback` event and the harness continues
58
+ with local-only augment. Timeouts emit a distinct event and never block
59
+ the iteration.
60
+
61
+ ### REFLECT/VERIFY phase (shadow-write)
62
+
63
+ `autonomy/run.sh::auto_capture_episode` (around line 8110) writes the
64
+ episode to `.loki/memory/` first, then reads the `importance` score from
65
+ the EpisodeTrace. If `importance >= 0.6` AND both flags on, a background
66
+ subprocess runs
67
+
68
+ ```
69
+ timeout 15 python3 -m memory.managed_memory.shadow_write --path $episode
70
+ ```
71
+
72
+ Non-blocking (`& disown`). On 409 (`content_sha256` precondition
73
+ mismatch), the shadow-writer re-reads, merges, retries once, and on final
74
+ failure emits a `managed_agents_fallback` event.
75
+
76
+ ### Completion council (augment + verdict)
77
+
78
+ `autonomy/completion-council.sh::council_should_stop` (line 1359)
79
+ optionally augments its prompt with related prior verdicts from the
80
+ managed store, and shadow-writes the approved verdict at the write site.
81
+ Same flag gates as memory.
82
+
83
+ ### Session-boot hydrate
84
+
85
+ `autonomy/run.sh::init_loki_dir` (around line 3049) pulls semantic
86
+ patterns + skills from the managed store ONCE at session startup when
87
+ `LOKI_MANAGED_MEMORY_HYDRATE=true`. Idempotent via
88
+ `.loki/managed/hydrate.lock` sentinel. Local wins on conflict.
89
+
90
+ ## Multiagent council (research preview)
91
+
92
+ When `LOKI_EXPERIMENTAL_MANAGED_REVIEW=true`, `run_code_review()` routes
93
+ through `providers/managed.py::run_council(pool, context, timeout_s)`.
94
+ Each reviewer runs in its own Managed Agents session thread with isolated
95
+ context; tool-confirmation payloads replace the file-polling aggregation
96
+ from v6.83.1. Verdicts are still written to the legacy
97
+ `.loki/quality/reviews/$id/*.txt` layout so the dashboard reviews panel
98
+ keeps working (single-writer invariant).
99
+
100
+ Same pattern for `LOKI_EXPERIMENTAL_MANAGED_COUNCIL` on completion
101
+ council (`council_managed_should_stop` in completion-council.sh).
102
+
103
+ Both are **research preview**. Expect beta-header churn. Never default on.
104
+
105
+ ## Cross-session learning
106
+
107
+ With managed memory on, a new project gets access to:
108
+ - `.loki/memory/semantic/patterns.json` from prior projects (org store, RO)
109
+ - `.loki/memory/skills/*.json` (org store, RO)
110
+ - `.loki/memory/anti_patterns/*.json` (org store, RO)
111
+
112
+ Promotions from user-RW to org-RO go through an explicit
113
+ `loki_memory_promote` MCP tool that requires human approval. Never
114
+ auto-promote.
115
+
116
+ ## PII redaction
117
+
118
+ MCP tool `loki_memory_redact(pattern, scope="all")` matches a regex
119
+ across memory versions and calls `memory_versions.redact(...)` on
120
+ matches. Produces a structured audit event. Requires
121
+ `LOKI_MANAGED_MEMORY=true`.
122
+
123
+ ## Observability
124
+
125
+ Single event stream: `.loki/managed/events.ndjson` (append-only,
126
+ rotated at 10 MB). Single writer:
127
+ `memory/managed_memory/events.py::emit_managed_event`.
128
+
129
+ Events:
130
+ - `managed_memory_retrieve`, `managed_memory_retrieve_empty`
131
+ - `managed_memory_shadow_write`, `managed_memory_shadow_write_409`
132
+ - `managed_memory_hydrate`, `managed_memory_hydrate_timeout`
133
+ - `managed_memory_redact`
134
+ - `managed_agents_fallback` (with op + reason + detail)
135
+ - `managed_session_created`, `managed_session_thread_created`,
136
+ `managed_session_thread_idle`
137
+ - `managed_agent_materialized`
138
+
139
+ Dashboard endpoints (read-only, view-layer merge):
140
+ - `GET /api/managed/events?limit&since&type`
141
+ - `GET /api/managed/status`
142
+ - `GET /api/managed/memory_versions/:memory_id`
143
+
144
+ ## Honest disclosure: what is NOT tested
145
+
146
+ - **Live Anthropic Managed Agents API.** Automated CI uses
147
+ `memory/managed_memory/fakes.py` + `FakeMultiagentSession`. A staging
148
+ smoke test with real `ANTHROPIC_API_KEY` + beta access is required
149
+ before any feature leaves the `LOKI_EXPERIMENTAL_*` gate.
150
+ - **Multiagent `callable_agents` happy path.** Research preview; beta
151
+ shape may differ.
152
+ - **409 precondition merge against a real server.** Covered by fake tests.
153
+ - **Cross-project org-store distribution.** Manually seeded stores work;
154
+ auto-promotion heuristic is future work.
155
+ - **Long-horizon (multi-hour) citation quality.** Requires real API usage.
156
+ - **Beta header rotation behavior.** Header is centralized in
157
+ `memory/managed_memory/_beta.py`; when Anthropic rotates, update once.
158
+
159
+ ## Rollback
160
+
161
+ - `LOKI_MANAGED_AGENTS=false` (default): every managed path is a no-op.
162
+ Identical to v6.83.1 behavior.
163
+ - Per-feature: set the child flag to `false`.
164
+ - API unreachable: automatic fallback to local path with a loud event.
165
+
166
+ ## Troubleshooting
167
+
168
+ | Symptom | Fix |
169
+ |---------|-----|
170
+ | `ERROR: ... requires LOKI_MANAGED_AGENTS=true` | Set parent flag to true. |
171
+ | No managed events in `.loki/managed/events.ndjson` | Check all flags on; check `ANTHROPIC_API_KEY` set; check SDK installed (`pip show anthropic`). |
172
+ | 400 on startup beta-header probe | Beta header rotated by Anthropic. Update `memory/managed_memory/_beta.py::BETA_HEADER`. |
173
+ | Hydrate runs every iteration instead of once | Sentinel file `.loki/managed/hydrate.lock` missing write permission. |
174
+
175
+ ## References
176
+
177
+ - `memory/managed_memory/` -- package (sole SDK import site, with `providers/managed.py`)
178
+ - `providers/managed.py` -- multiagent session orchestration
179
+ - `agents/managed_registry.py` -- lazy agent materialization
180
+ - `mcp/managed_tools.py` -- MCP tools (`loki_memory_redact`)
181
+ - `CHANGELOG.md` -- per-release honest disclosure
182
+
183
+ ---
184
+
185
+ **v7.0.0** | Opt-in, additive, rollback-safe. Default behavior unchanged.