loki-mode 6.83.1 → 7.0.2

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,187 @@
1
+ # Memory Integration (v7.0.2+)
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 are MANUAL only at v7.0.x. Use the
113
+ Managed Agents API directly (`memory_stores.memories.create` against the
114
+ org store) with human review. An MCP `loki_memory_promote` tool is on
115
+ the roadmap but NOT shipped in v7.0.x; do not depend on it. Never
116
+ auto-promote.
117
+
118
+ ## PII redaction
119
+
120
+ MCP tool `loki_memory_redact(pattern, scope="all")` matches a regex
121
+ across memory versions and calls `memory_versions.redact(...)` on
122
+ matches. Produces a structured audit event. Requires
123
+ `LOKI_MANAGED_MEMORY=true`.
124
+
125
+ ## Observability
126
+
127
+ Single event stream: `.loki/managed/events.ndjson` (append-only,
128
+ rotated at 10 MB). Single writer:
129
+ `memory/managed_memory/events.py::emit_managed_event`.
130
+
131
+ Events:
132
+ - `managed_memory_retrieve`, `managed_memory_retrieve_empty`
133
+ - `managed_memory_shadow_write`, `managed_memory_shadow_write_409`
134
+ - `managed_memory_hydrate`, `managed_memory_hydrate_timeout`
135
+ - `managed_memory_redact`
136
+ - `managed_agents_fallback` (with op + reason + detail)
137
+ - `managed_session_created`, `managed_session_thread_created`,
138
+ `managed_session_thread_idle`
139
+ - `managed_agent_materialized`
140
+
141
+ Dashboard endpoints (read-only, view-layer merge):
142
+ - `GET /api/managed/events?limit&since&type`
143
+ - `GET /api/managed/status`
144
+ - `GET /api/managed/memory_versions/:memory_id`
145
+
146
+ ## Honest disclosure: what is NOT tested
147
+
148
+ - **Live Anthropic Managed Agents API.** Automated CI uses
149
+ `memory/managed_memory/fakes.py` + `FakeMultiagentSession`. A staging
150
+ smoke test with real `ANTHROPIC_API_KEY` + beta access is required
151
+ before any feature leaves the `LOKI_EXPERIMENTAL_*` gate.
152
+ - **Multiagent `callable_agents` happy path.** Research preview; beta
153
+ shape may differ.
154
+ - **409 precondition merge against a real server.** Covered by fake tests.
155
+ - **Cross-project org-store distribution.** Manually seeded stores work;
156
+ auto-promotion heuristic is future work.
157
+ - **Long-horizon (multi-hour) citation quality.** Requires real API usage.
158
+ - **Beta header rotation behavior.** Header is centralized in
159
+ `memory/managed_memory/_beta.py`; when Anthropic rotates, update once.
160
+
161
+ ## Rollback
162
+
163
+ - `LOKI_MANAGED_AGENTS=false` (default): every managed path is a no-op.
164
+ Identical to v6.83.1 behavior.
165
+ - Per-feature: set the child flag to `false`.
166
+ - API unreachable: automatic fallback to local path with a loud event.
167
+
168
+ ## Troubleshooting
169
+
170
+ | Symptom | Fix |
171
+ |---------|-----|
172
+ | `ERROR: ... requires LOKI_MANAGED_AGENTS=true` | Set parent flag to true. |
173
+ | No managed events in `.loki/managed/events.ndjson` | Check all flags on; check `ANTHROPIC_API_KEY` set; check SDK installed (`pip show anthropic`). |
174
+ | 400 on startup beta-header probe | Beta header rotated by Anthropic. Update `memory/managed_memory/_beta.py::BETA_HEADER`. |
175
+ | Hydrate runs every iteration instead of once | Sentinel file `.loki/managed/hydrate.lock` missing write permission. |
176
+
177
+ ## References
178
+
179
+ - `memory/managed_memory/` -- package (sole SDK import site, with `providers/managed.py`)
180
+ - `providers/managed.py` -- multiagent session orchestration
181
+ - `agents/managed_registry.py` -- lazy agent materialization
182
+ - `mcp/managed_tools.py` -- MCP tools (`loki_memory_redact`)
183
+ - `CHANGELOG.md` -- per-release honest disclosure
184
+
185
+ ---
186
+
187
+ **v7.0.2** | Opt-in, additive, rollback-safe. Default behavior unchanged.