Datasets:
Download rebuttal/code/MFM-kabx/a5b7d8c.format-patch from Ced-Collab/KiCadData: direct link, hf CLI and curl.
- Browser
- Download file 33.8 kB
-
https://huggingface.co/datasets/Ced-Collab/KiCadData/resolve/main/rebuttal/code/MFM-kabx/a5b7d8c.format-patch
- Command line
-
hf download hf://datasets/Ced-Collab/KiCadData/rebuttal/code/MFM-kabx/a5b7d8c.format-patch
-
curl -L -o a5b7d8c.format-patch https://huggingface.co/datasets/Ced-Collab/KiCadData/resolve/main/rebuttal/code/MFM-kabx/a5b7d8c.format-patch
33.8 kB
| From a5b7d8ce68c3448aec0b8fb201f54cbc8d06b6c3 Mon Sep 17 00:00:00 2001 | |
| From: Hither1 <suhither@gmail.com> | |
| Date: Sat, 24 Oct 2026 15:10:06 -0400 | |
| Subject: [PATCH] KiCad mfm: --no-history-images, --flat-retrieval and | |
| --no-consolidation | |
| The three ablations of the mfm / mfm-carry arms, each removing one thing | |
| and saying so in the prompt; with none on, the arm is byte-identical | |
| (the KiCad release pins record the same). | |
| - --no-history-images: no episode keeps its screenshot and no earlier | |
| task's screenshot is carried (index rows have image null); every image | |
| in the workspace but the current turn's is removed before each call. | |
| - --flat-retrieval: no tools/episodes.py and no [RECALL] / [SEEN BEFORE] | |
| push, within or across tasks; the same episodes/, index.jsonl and | |
| previous/index.jsonl, read with ordinary text search. | |
| - --no-consolidation (mfm-carry): an earlier task is carried as the | |
| harness's record only -- no notes/ across tasks, no situation table, | |
| none of the files the model wrote. | |
| Ported from the 09-30 Opus wave's uncommitted edits onto this branch; | |
| EpisodeStore gains images= and push= beside the Minecraft tool=. | |
| Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> | |
| --- | |
| CUA-KiCad/gym_codex/mfm_prompts.py | 48 ++++++++++ | |
| CUA-KiCad/gym_codex/prolong_agent.py | 66 ++++++++++++-- | |
| CUA-KiCad/gym_codex/run_eval.py | 42 +++++++++ | |
| mfm/memory/carry.py | 126 +++++++++++++++++++++++---- | |
| mfm/memory/store.py | 21 +++-- | |
| 5 files changed, 275 insertions(+), 28 deletions(-) | |
| diff --git a/CUA-KiCad/gym_codex/mfm_prompts.py b/CUA-KiCad/gym_codex/mfm_prompts.py | |
| index e573087..a781ab3 100644 | |
| --- a/CUA-KiCad/gym_codex/mfm_prompts.py | |
| +++ b/CUA-KiCad/gym_codex/mfm_prompts.py | |
| @@ -15,6 +15,54 @@ screenshot the batch was decided on, the same file the `[SCREEN]` line names). \ | |
| tiles their screenshots. Use it instead of parsing the log by hand when the question \ | |
| is "have I seen this screen / tried this before".""" | |
| +#: The memory paragraph under the KiCad ablations (`ProlongGuiAgent(history_images=False)`, | |
| +#: `flat_retrieval=True`), each a checked edit of MFM_MEMORY_NOTE. | |
| +_NOTE_IMAGE_CLAUSE = (", `outcome.json` (the feedback and whether the screen changed after it, " | |
| + "tags) and `observation/image.png` (the 1920x1080 screenshot the batch " | |
| + "was decided on, the same file the `[SCREEN]` line names). ") | |
| +_NOTE_TOOL_CLAUSE = ("`./tools/episodes.py --last 5 | --steps A B | --tag feedback | --tag " | |
| + "screen_unchanged | --grep text` lists matching episodes one per line with " | |
| + "their paths; `--sheet out.png` tiles their screenshots. Use it instead of " | |
| + "parsing the log by hand when the question is \"have I seen this screen / " | |
| + "tried this before\".") | |
| +assert MFM_MEMORY_NOTE.count(_NOTE_IMAGE_CLAUSE) == 1 and MFM_MEMORY_NOTE.count(_NOTE_TOOL_CLAUSE) == 1 | |
| + | |
| + | |
| +def mfm_memory_note(*, images: bool = True, flat: bool = False) -> str: | |
| + text = MFM_MEMORY_NOTE | |
| + if not images: | |
| + text = text.replace(_NOTE_IMAGE_CLAUSE, | |
| + " and `outcome.json` (the feedback and whether the screen changed " | |
| + "after it, tags). No screenshot is kept in this run: an episode has " | |
| + "no `observation/image.png`, and an earlier turn's frame is removed " | |
| + "when the next turn starts. ") | |
| + if flat: | |
| + text = text.replace(_NOTE_TOOL_CLAUSE, | |
| + "`index.jsonl` is their flat chronological record: one JSON line per " | |
| + "episode, in order, with its step, action, outcome summary, tags, " | |
| + "what you said you saw (`perception`) and meant (`intent`), what the " | |
| + "next turn said the action did (`effect`), and its paths. There is " | |
| + "NO query tool in this run: grep `index.jsonl` and " | |
| + "`episodes/*/outcome.json` the way you grep the log when the " | |
| + "question is \"have I seen this screen / tried this before\".") | |
| + elif not images: | |
| + text = text.replace("with their paths; `--sheet out.png` tiles their screenshots.", | |
| + "with their paths.") | |
| + return text | |
| + | |
| + | |
| +#: The system prompt's [SCREEN] marker under `history_images=False`. | |
| +SCREEN_MARKER = """\ | |
| + [SCREEN] frames/<file> -- the screenshot at the start of that turn, on disk. The | |
| + *current* turn's screenshot is attached directly to this message; the paths let | |
| + you re-open an earlier screen and compare.""" | |
| +SCREEN_MARKER_NO_IMAGES = """\ | |
| + [SCREEN] frames/<file> -- the screenshot at the start of that turn. The *current* | |
| + turn's screenshot is attached directly to this message and is the only one kept | |
| + on disk in this run: an earlier turn's file is removed when the next turn | |
| + starts, so no earlier screen can be re-opened.""" | |
| + | |
| + | |
| PLAN_QUEUE_NOTE = """\ | |
| You may plan several batches in one turn: write `./actions.json` as \ | |
| `{"plan": [batch, batch, ...]}` where each `batch` is the usual `{"actions": [...]}` \ | |
| diff --git a/CUA-KiCad/gym_codex/prolong_agent.py b/CUA-KiCad/gym_codex/prolong_agent.py | |
| index 7757617..cec9223 100644 | |
| --- a/CUA-KiCad/gym_codex/prolong_agent.py | |
| +++ b/CUA-KiCad/gym_codex/prolong_agent.py | |
| @@ -33,11 +33,11 @@ from typing import Any, Optional | |
| from gym_codex import prompts_prolong | |
| from gym_codex.actions import ParsedBatch, parse_batch | |
| from gym_codex.mfm_prompts import (CONVENTIONS_NOTE, DESIGN_EXISTING, DESIGN_NOTE, | |
| - DESIGN_PROMPT, MFM_MEMORY_NOTE, | |
| - PLAN_QUEUE_NOTE, RECALL_NOTE) | |
| + DESIGN_PROMPT, PLAN_QUEUE_NOTE, RECALL_NOTE, | |
| + SCREEN_MARKER, SCREEN_MARKER_NO_IMAGES, mfm_memory_note) | |
| from mfm.agent.base import MemoryAgent, Observation, Plan | |
| from mfm.backend import errors as backend_errors | |
| -from mfm.memory.carry import CarrySink | |
| +from mfm.memory.carry import IMAGE_SUFFIXES, CarrySink | |
| from mfm.memory.log import install_zoom_tool | |
| from mfm.memory.store import EpisodeStore | |
| from prolong_search.codex_backend import CodexTurn | |
| @@ -102,7 +102,9 @@ class ProlongGuiAgent(MemoryAgent): | |
| recall: bool = False, log_only: bool = False, | |
| carry_outcomes: bool = False, | |
| design: bool = False, design_effort: str = "high", | |
| - conventions: bool = False, cli: str = "codex") -> None: | |
| + conventions: bool = False, cli: str = "codex", | |
| + history_images: bool = True, flat_retrieval: bool = False, | |
| + consolidation: bool = True) -> None: | |
| # PRO-LONG (`prolong-logonly`): the record lives beside the workspace the model | |
| # works in, and `EpisodeLog.publish` takes the model's own files back every | |
| # turn (mfm/memory/log.py), so the log is the only memory. | |
| @@ -126,6 +128,24 @@ class ProlongGuiAgent(MemoryAgent): | |
| # The conventions paragraph (`--conventions`): GND symbol on every return, no | |
| # labels the task does not ask for, designators in the task's order. | |
| self.conventions = conventions | |
| + # The MFM ablations (`run_eval.py --no-history-images / --flat-retrieval / | |
| + # --no-consolidation`), each removing one thing and saying so in the prompt: | |
| + # no screenshot of an earlier turn or task is kept (the current one is still | |
| + # attached); no query tool and no [RECALL]/[SEEN BEFORE] push (the rows are still | |
| + # written); an earlier task's record is carried without the files the model wrote, | |
| + # `notes/` or the situation table. | |
| + self.history_images = bool(history_images) | |
| + self.flat_retrieval = bool(flat_retrieval) | |
| + self.consolidation = bool(consolidation) | |
| + self.ablations = (([] if self.history_images else ["no_history_images"]) | |
| + + (["flat_retrieval"] if self.flat_retrieval else []) | |
| + + ([] if self.consolidation else ["no_consolidation"])) | |
| + if self.ablations and not episodes: | |
| + raise ValueError("the MFM ablations need the episode store (an mfm arm)") | |
| + if not self.consolidation and not carry_dir: | |
| + raise ValueError("consolidation=False ablates what is carried across tasks: " | |
| + "it needs an mfm-carry arm") | |
| + self.image_sweeps = 0 | |
| visible, record = prepare_workspace(Path(workspace), view=log_only) | |
| log = EpisodeLog(record, attachment_markers=("SCREEN",), attachment_dirs=("frames",), | |
| log_only=log_only) | |
| @@ -136,10 +156,13 @@ class ProlongGuiAgent(MemoryAgent): | |
| # The MFM arm: the episode store beside the log, and (its one deliberate | |
| # deviation from the log arm's protocol) a | |
| # multi-batch plan drained one batch per step with the flush rules below. | |
| - self.store = EpisodeStore(record, recall=recall) if episodes else None | |
| + self.store = (EpisodeStore(record, recall=recall, tool=not self.flat_retrieval, | |
| + images=self.history_images, push=not self.flat_retrieval) | |
| + if episodes else None) | |
| self.plan_queue = plan_queue | |
| - note = MFM_MEMORY_NOTE if episodes else "" | |
| - if episodes and recall: | |
| + note = (mfm_memory_note(images=self.history_images, flat=self.flat_retrieval) | |
| + if episodes else "") | |
| + if episodes and recall and not self.flat_retrieval: | |
| note += "\n\n" + RECALL_NOTE | |
| if plan_queue: | |
| note = (note + "\n\n" if note else "") + PLAN_QUEUE_NOTE.replace("{plan_cap}", str(PLAN_CAP)) | |
| @@ -148,7 +171,9 @@ class ProlongGuiAgent(MemoryAgent): | |
| # records and a persistent notes/ inside this task's workspace. Same material | |
| # for prolong-carry and mfm-carry; the store is the only difference. | |
| self.carry = (CarrySink(Path(carry_dir), task_id or Path(workspace).parent.name, | |
| - record, outcomes=carry_outcomes) if carry_dir else None) | |
| + record, outcomes=carry_outcomes, images=self.history_images, | |
| + push=not self.flat_retrieval, consolidation=self.consolidation) | |
| + if carry_dir else None) | |
| if cli == "claude": | |
| # prolong_search/claude_backend.py: CodexTurn's surface on `claude -p`, with a | |
| # per-episode config dir beside the workspace. The codex branch below is the | |
| @@ -211,6 +236,8 @@ class ProlongGuiAgent(MemoryAgent): | |
| self.turn += 1 | |
| step = step_idx + 1 | |
| rel = self.log.save_attachment(f"frames/step_{step:04d}.png", screenshot_png or b"") | |
| + if not self.history_images: | |
| + self._sweep_history_images(keep=rel) | |
| feedback = self._pending_feedback | |
| self._pending_feedback = None | |
| title = f"Turn {self.turn} | Step {step}/{max_steps}" | |
| @@ -251,6 +278,11 @@ class ProlongGuiAgent(MemoryAgent): | |
| out["design"] = self.design_result or {"ok": False, "error": "not run"} | |
| if self.conventions: | |
| out["conventions"] = True | |
| + if getattr(self, "ablations", None): | |
| + # Only when one is on: the full arm's audit keys do not move. | |
| + out["ablations"] = list(self.ablations) | |
| + if not self.history_images: | |
| + out["history_image_sweeps"] = self.image_sweeps | |
| return out | |
| def finish(self, reward: Any = None, error: Any = None, **outcome: Any) -> None: | |
| @@ -263,8 +295,26 @@ class ProlongGuiAgent(MemoryAgent): | |
| return {"id": f"call_{self._call_seq:04d}", "type": "function", | |
| "function": {"name": name, "arguments": args}} | |
| + def _sweep_history_images(self, keep: str) -> None: | |
| + """`history_images=False`: before the model is called, remove every image file in | |
| + the workspace except this turn's screenshot -- earlier turns' frames, and any | |
| + crop or copy the model saved. The store and the carry never write one.""" | |
| + roots = {self.visible, self.record_dir} | |
| + keep_paths = {(r / keep).resolve() for r in roots} | |
| + gone = 0 | |
| + for root in roots: | |
| + for p in root.rglob("*"): | |
| + if (p.suffix.lower() in IMAGE_SUFFIXES and p.is_file() | |
| + and p.resolve() not in keep_paths): | |
| + p.unlink(missing_ok=True) | |
| + gone += 1 | |
| + self.image_sweeps += gone | |
| + | |
| def system_prompt(self) -> str: | |
| text = prompts_prolong.build_system_prompt(self.max_steps) | |
| + if not getattr(self, "history_images", True): | |
| + assert text.count(SCREEN_MARKER) == 1, "the [SCREEN] marker drifted" | |
| + text = text.replace(SCREEN_MARKER, SCREEN_MARKER_NO_IMAGES) | |
| if self.log_only: | |
| text = _log_only_edit(text, _LOG_ONLY_SYSTEM_EDITS) | |
| if self.conventions: | |
| diff --git a/CUA-KiCad/gym_codex/run_eval.py b/CUA-KiCad/gym_codex/run_eval.py | |
| index 52a6122..1714cec 100644 | |
| --- a/CUA-KiCad/gym_codex/run_eval.py | |
| +++ b/CUA-KiCad/gym_codex/run_eval.py | |
| @@ -188,9 +188,23 @@ def _make_agent(args, task_dir: Path): | |
| if args.agent.endswith("-carry"): | |
| kw["carry_dir"] = task_dir.parent / "carry" | |
| kw["task_id"] = task_dir.name | |
| + kw.update(_ablation_kw(args)) | |
| return make_agent(args.agent, **kw, **ARMS[args.agent]) | |
| +def _ablation_kw(args) -> dict: | |
| + """The agent keywords of the ablation options that are on (nothing for a full arm, | |
| + so its construction, rows and summary are exactly as before).""" | |
| + kw = {} | |
| + if getattr(args, "no_history_images", False): | |
| + kw["history_images"] = False | |
| + if getattr(args, "flat_retrieval", False): | |
| + kw["flat_retrieval"] = True | |
| + if getattr(args, "no_consolidation", False): | |
| + kw["consolidation"] = False | |
| + return kw | |
| + | |
| + | |
| #: cua.bench's KiCad grader only ever reads /home/cua/kicad_project (a .net there, | |
| #: else the first .kicad_sch exported via kicad-cli). Its setup creates that | |
| #: directory only while copying an initial project, so the 15 design-from-scratch | |
| @@ -462,6 +476,24 @@ async def main() -> int: | |
| "each task's workspace under <out>/carry; tasks run in order at " | |
| "concurrency 1). The options of the two MFM arms are " | |
| "gym_codex.memory_agents.ARMS") | |
| + abl = p.add_argument_group( | |
| + "ablations of the MFM arms", | |
| + "Each removes one thing from mfm / mfm-carry and says so in the prompt; the rest of " | |
| + "the arm is unchanged.") | |
| + abl.add_argument("--no-history-images", action="store_true", | |
| + help="without historical images: no episode keeps its screenshot, no " | |
| + "earlier task's screenshot is carried, and every image in the " | |
| + "workspace but the current turn's is removed before each call. " | |
| + "The current screenshot is still attached") | |
| + abl.add_argument("--flat-retrieval", action="store_true", | |
| + help="without structured episode retrieval: no tools/episodes.py and no " | |
| + "[RECALL] or [SEEN BEFORE] block; the same episodes/ and index.jsonl, " | |
| + "read with ordinary text search") | |
| + abl.add_argument("--no-consolidation", action="store_true", | |
| + help="without long-term consolidation (mfm-carry): an earlier task is " | |
| + "carried as the harness's record only (log, episodes, index, " | |
| + "screenshots) -- no notes/ across tasks, no situation table, none " | |
| + "of the files the model wrote") | |
| p.add_argument("--cli", choices=("codex", "claude"), default="codex", | |
| help="which CLI carries the model: codex " | |
| "(default), or claude -- Anthropic models through Claude Code " | |
| @@ -496,6 +528,11 @@ async def main() -> int: | |
| args.max_steps = _DEFAULT_BUDGETS.get(args.env_id, _FALLBACK_BUDGET) | |
| if _cli_error(args): | |
| p.error(_cli_error(args)) | |
| + if _ablation_kw(args) and args.agent not in ("mfm", "mfm-carry"): | |
| + p.error("--no-history-images/--flat-retrieval/--no-consolidation are ablations of " | |
| + "the mfm arms") | |
| + if args.no_consolidation and args.agent != "mfm-carry": | |
| + p.error("--no-consolidation ablates what is carried across tasks: it needs mfm-carry") | |
| logger.info("env=%s budget=%d steps", args.env_id, args.max_steps) | |
| import lite.gym as gym # after sbatch has set up PATH/PODMAN_* for the shim | |
| @@ -554,6 +591,11 @@ async def main() -> int: | |
| "max_steps": args.max_steps, "domain": args.domain, "env_id": args.env_id, | |
| "task_order_seed": args.task_order_seed} | |
| summary.update(_cli_kw(args)) | |
| + if _ablation_kw(args): | |
| + summary["ablations"] = [n for f, n in (("no_history_images", "no_history_images"), | |
| + ("flat_retrieval", "flat_retrieval"), | |
| + ("no_consolidation", "no_consolidation")) | |
| + if getattr(args, f)] | |
| options = ARMS.get(args.agent, {}) | |
| if options: | |
| summary["design"] = {"design_turn": options["design"], | |
| diff --git a/mfm/memory/carry.py b/mfm/memory/carry.py | |
| index 6d50375..8dcbbe0 100644 | |
| --- a/mfm/memory/carry.py | |
| +++ b/mfm/memory/carry.py | |
| @@ -44,6 +44,14 @@ if TYPE_CHECKING: # pragma: no cover | |
| _NOT_CARRIED = frozenset({"previous", "notes", "tools", "AGENTS.md", "actions.json", | |
| "last_message.txt", "workspace.codexhome"}) | |
| +#: Under `consolidation=False`, the only parts of a finished task that are carried: the | |
| +#: record the harness wrote (the log with the model's briefings in it, the episodes, | |
| +#: their index and the screenshots), none of the files the model wrote for itself. | |
| +_RECORD_ONLY = frozenset({"logs.txt", "episodes", "index.jsonl", "frames"}) | |
| + | |
| +#: Image files, as the "without historical images" ablation sees them. | |
| +IMAGE_SUFFIXES = frozenset({".png", ".jpg", ".jpeg", ".bmp", ".gif", ".webp", ".tif", ".tiff"}) | |
| + | |
| CARRY_NOTE = """\ | |
| This is one task of a sequence in the same application. `previous/<task>/` holds the \ | |
| complete record of every task finished before this one, oldest first: its `logs.txt`, \ | |
| @@ -81,6 +89,65 @@ what followed then, two steps ahead: if it matches what you intend, queue those | |
| as one plan instead of rediscovering them one screenshot at a time.""" | |
| +def _edit(text: str, old: str, new: str) -> str: | |
| + assert text.count(old) == 1, f"carry note drifted; cannot ablate: {old[:60]!r}" | |
| + return text.replace(old, new) | |
| + | |
| + | |
| +def carry_note(*, images: bool = True, consolidation: bool = True) -> str: | |
| + """CARRY_NOTE for this run's ablations (the full arm's when both are on); `{count}` | |
| + stays a placeholder for `prompt_note`.""" | |
| + text = CARRY_NOTE | |
| + if not images: | |
| + text = _edit(text, "its `logs.txt`, the screenshots that log names (under " | |
| + "`previous/<task>/frames/`), and whatever", | |
| + "its `logs.txt` (no screenshot of an earlier task is kept in this run), " | |
| + "and whatever") | |
| + if not consolidation: | |
| + text = _edit(text, "and whatever that task wrote in its workspace.", | |
| + "and its episodes -- the record only: what that task wrote in its " | |
| + "workspace is not carried in this run.") | |
| + text = _edit(text, "`notes/` is yours and persists across tasks: read what is in " | |
| + "`notes/` first, and before you finish write down what worked and " | |
| + "what cost steps (recipes, stable coordinates, mistakes to avoid). ", | |
| + "`notes/` does NOT persist across tasks in this run: every task starts " | |
| + "with it empty, and nothing you write in this task reaches the next one " | |
| + "except through this task's log. ") | |
| + return text | |
| + | |
| + | |
| +def carry_outcomes_note(*, consolidation: bool = True) -> str: | |
| + if consolidation: | |
| + return CARRY_OUTCOMES_NOTE | |
| + return _edit(CARRY_OUTCOMES_NOTE, | |
| + "Read it with `notes/` before the first action, and when you write notes at " | |
| + "the end, write down what the scores support and mark what you are only " | |
| + "assuming.", "Read it before the first action.") | |
| + | |
| + | |
| +#: Under flat retrieval: the merged index without the query tool. | |
| +CARRY_STORE_NOTE_FLAT = """\ | |
| +`previous/index.jsonl` indexes every episode of the finished tasks, one JSON line each \ | |
| +with its task and the same fields as `index.jsonl`; there is no query tool in this run: \ | |
| +grep it the way you grep the logs.""" | |
| + | |
| +#: CARRY_RECALL_NOTE in its two parts: the situation table (consolidation) and the | |
| +#: [RECALL] block (structured retrieval). Each ablation removes its own part. | |
| +_SITUATIONS_PART, _RECALL_PART = CARRY_RECALL_NOTE.split("Read it before the first action. ") | |
| +_SITUATIONS_PART += "Read it before the first action." | |
| +assert CARRY_RECALL_NOTE == _SITUATIONS_PART + " " + _RECALL_PART | |
| + | |
| + | |
| +def carry_recall_note(*, push: bool = True, consolidation: bool = True) -> str: | |
| + if push and consolidation: | |
| + return CARRY_RECALL_NOTE | |
| + if consolidation: | |
| + return _SITUATIONS_PART | |
| + if push: | |
| + return _RECALL_PART[0].upper() + _RECALL_PART[1:] | |
| + return "" | |
| + | |
| + | |
| @dataclass(frozen=True) | |
| class CarriedRecord: | |
| """One finished record to carry over: where it is now, what it is called under | |
| @@ -110,22 +177,27 @@ _PATH_FIELDS = ("path", "image", "attachment") | |
| def link_record(src: Path, dst: Path, *, skip: frozenset[str] = frozenset(), | |
| - skip_hidden: bool = False) -> int: | |
| + skip_hidden: bool = False, keep: frozenset[str] | None = None, | |
| + images: bool = True) -> int: | |
| """Hard-link every file under `src` into `dst` (copy where linking fails). | |
| `skip` names top-level entries of the record that are its machinery rather than its | |
| history; `skip_hidden` drops top-level dotfiles as well (MCU's rule). Both apply at | |
| - the top level only: a name of the record's own, deeper in, is history. Returns the | |
| - number of files placed. | |
| + the top level only: a name of the record's own, deeper in, is history. `keep`, when | |
| + given, is the only top-level names linked; `images=False` links no image file. | |
| + Returns the number of files placed. | |
| """ | |
| n = 0 | |
| for p in src.rglob("*"): | |
| rel = p.relative_to(src) | |
| if rel.parts and (rel.parts[0] in skip | |
| + or (keep is not None and rel.parts[0] not in keep) | |
| or (skip_hidden and rel.parts[0].startswith("."))): | |
| continue | |
| if not p.is_file(): | |
| continue | |
| + if not images and p.suffix.lower() in IMAGE_SUFFIXES: | |
| + continue | |
| target = dst / rel | |
| target.parent.mkdir(parents=True, exist_ok=True) | |
| if target.exists(): | |
| @@ -140,7 +212,8 @@ def link_record(src: Path, dst: Path, *, skip: frozenset[str] = frozenset(), | |
| def seed_previous(prev_dir: Path, records: "list[CarriedRecord]", *, | |
| skip: frozenset[str] = frozenset(), skip_hidden: bool = False, | |
| - write_index: bool = True) -> CarrySeed: | |
| + write_index: bool = True, keep: frozenset[str] | None = None, | |
| + images: bool = True) -> CarrySeed: | |
| """Link the finished records under `prev_dir` and merge their episode indexes. | |
| One `previous/index.jsonl` over every carried episode, each row stamped with its | |
| @@ -154,7 +227,8 @@ def seed_previous(prev_dir: Path, records: "list[CarriedRecord]", *, | |
| if not rec.source.exists(): | |
| continue | |
| seed.linked += link_record(rec.source, prev_dir / rec.name, | |
| - skip=skip, skip_hidden=skip_hidden) | |
| + skip=skip, skip_hidden=skip_hidden, keep=keep, | |
| + images=images) | |
| seed.names.append(rec.name) | |
| idx = rec.source / "index.jsonl" | |
| if not idx.exists(): | |
| @@ -170,6 +244,8 @@ def seed_previous(prev_dir: Path, records: "list[CarriedRecord]", *, | |
| for key in _PATH_FIELDS: | |
| if row.get(key): | |
| row[key] = f"previous/{rec.name}/{row[key]}" | |
| + if not images: | |
| + row["image"] = None # the frame was not carried | |
| seed.rows.append(row) | |
| if seed.rows and write_index: | |
| prev_dir.mkdir(parents=True, exist_ok=True) | |
| @@ -181,7 +257,8 @@ def seed_previous(prev_dir: Path, records: "list[CarriedRecord]", *, | |
| class CarrySink(MemorySink): | |
| def __init__(self, root: Path | str, task_id: str, record_dir: Path | str, | |
| - outcomes: bool = False) -> None: | |
| + outcomes: bool = False, images: bool = True, push: bool = True, | |
| + consolidation: bool = True) -> None: | |
| self.root = Path(root) | |
| self.task_id = str(task_id) | |
| self.record = Path(record_dir) | |
| @@ -190,6 +267,12 @@ class CarrySink(MemorySink): | |
| # protocol decision and not a memory mechanism: without it the carried notes are | |
| # the model's own belief about what worked, never checked against anything. | |
| self.outcomes = bool(outcomes) | |
| + # The KiCad ablations, one each, the same three switches as the store's: | |
| + # `images=False` carries no screenshot of an earlier task; `push=False` puts no | |
| + # [RECALL] / [SEEN BEFORE] line into a turn; `consolidation=False` carries only | |
| + # the harness's record of an earlier task (_RECORD_ONLY), no `notes/` and no | |
| + # situation table. | |
| + self.images, self.push, self.consolidation = bool(images), bool(push), bool(consolidation) | |
| self.root.mkdir(parents=True, exist_ok=True) | |
| (self.root / "notes").mkdir(exist_ok=True) | |
| self.manifest_path = self.root / "manifest.json" | |
| @@ -217,15 +300,18 @@ class CarrySink(MemorySink): | |
| n = len(self.prior()) | |
| count = (f"{n} task(s) are recorded under `previous/` now." if n | |
| else "This is the first task of the sequence: `previous/` is empty and " | |
| - "`notes/` holds nothing yet.") | |
| - note = CARRY_NOTE.format(count=count) | |
| + "`notes/` holds nothing yet." if self.consolidation | |
| + else "This is the first task of the sequence: `previous/` is empty.") | |
| + note = carry_note(images=self.images, consolidation=self.consolidation).format(count=count) | |
| if self.outcomes and n: | |
| - note += "\n\n" + CARRY_OUTCOMES_NOTE | |
| + note += "\n\n" + carry_outcomes_note(consolidation=self.consolidation) | |
| store = self._store(agent) | |
| if store is not None: | |
| - note += "\n\n" + CARRY_STORE_NOTE | |
| + note += "\n\n" + (CARRY_STORE_NOTE if self.push else CARRY_STORE_NOTE_FLAT) | |
| if store.recall: | |
| - note += "\n\n" + CARRY_RECALL_NOTE | |
| + recall = carry_recall_note(push=self.push, consolidation=self.consolidation) | |
| + if recall: | |
| + note += "\n\n" + recall | |
| return note | |
| @staticmethod | |
| @@ -250,10 +336,11 @@ class CarrySink(MemorySink): | |
| [CarriedRecord(name=m["task_id"], source=Path(m["record_dir"]), | |
| tag={"task": m["task_id"]}) | |
| for m in self.prior()], | |
| - skip=_NOT_CARRIED) | |
| + skip=_NOT_CARRIED, keep=None if self.consolidation else _RECORD_ONLY, | |
| + images=self.images) | |
| self.seeded += seed.linked | |
| rows = seed.rows | |
| - if rows and any(r.get("perception") for r in rows): | |
| + if self.consolidation and rows and any(r.get("perception") for r in rows): | |
| # Consolidation: the episodic rows folded into the situation table. | |
| (prev_dir / "situations.md").write_text(to_markdown(situations(rows)), | |
| encoding="utf-8") | |
| @@ -262,6 +349,8 @@ class CarrySink(MemorySink): | |
| self._write_outcomes(prev_dir) | |
| notes_in = self.record / "notes" | |
| notes_in.mkdir(exist_ok=True) | |
| + if not self.consolidation: | |
| + return # notes/ starts empty in every task | |
| for p in (self.root / "notes").rglob("*"): | |
| if p.is_file(): | |
| target = notes_in / p.relative_to(self.root / "notes") | |
| @@ -306,6 +395,8 @@ class CarrySink(MemorySink): | |
| """Across tasks: the model does not pull, so the harness pushes. With the | |
| store's recall on, the earlier tasks' turns that repeated the previous turn's | |
| transition (mfm.memory.recall); otherwise the exact-hash seen-before line.""" | |
| + if not self.push: | |
| + return None | |
| store = self._store(agent) | |
| if store is not None and store.recall: | |
| if not self.previous_rows: | |
| @@ -338,7 +429,7 @@ class CarrySink(MemorySink): | |
| self._published = True | |
| notes_out = self.root / "notes" | |
| notes_in = self.record / "notes" | |
| - if notes_in.exists(): | |
| + if notes_in.exists() and self.consolidation: | |
| for p in notes_in.rglob("*"): | |
| if p.is_file(): | |
| target = notes_out / p.relative_to(notes_in) | |
| @@ -355,10 +446,15 @@ class CarrySink(MemorySink): | |
| out = {"previous_tasks": len(self.prior()), "files_linked": self.seeded, | |
| "previous_episodes": len(self.previous_rows), | |
| "notes_files": sum(1 for p in (self.root / "notes").rglob("*") if p.is_file())} | |
| - if any(r.get("perception") for r in self.previous_rows): | |
| + if self.consolidation and any(r.get("perception") for r in self.previous_rows): | |
| out["situations"] = sum(1 for g in situations(self.previous_rows) if g["n"] >= 2) | |
| if self.outcomes: | |
| # Only when the arm has it: the audit keys of an arm that does not carry | |
| # outcomes must not move (tests/test_carry.py pins them). | |
| out["outcomes"] = True | |
| + ablations = ([] if self.images else ["no_history_images"]) \ | |
| + + ([] if self.push else ["flat_retrieval"]) \ | |
| + + ([] if self.consolidation else ["no_consolidation"]) | |
| + if ablations: | |
| + out["ablations"] = ablations | |
| return out | |
| diff --git a/mfm/memory/store.py b/mfm/memory/store.py | |
| index 130c614..8a75c00 100644 | |
| --- a/mfm/memory/store.py | |
| +++ b/mfm/memory/store.py | |
| @@ -69,12 +69,21 @@ class EpisodeStore(MemorySink): | |
| line with the transition recall of `mfm.memory.recall`. Off, the store is | |
| byte-identical to what the MCU ladder runs on.""" | |
| - def __init__(self, root: Path | str, *, recall: bool = False, tool: bool = True) -> None: | |
| + def __init__(self, root: Path | str, *, recall: bool = False, tool: bool = True, | |
| + images: bool = True, push: bool = True) -> None: | |
| self.root = Path(root) | |
| self.recall = recall | |
| - # `tool=False` (the MCU flat-retrieval ablation): the record is written exactly | |
| - # as before -- episodes/, index.jsonl, every image -- but `tools/episodes.py` is | |
| - # not put in the workspace, so the model reaches the same files by text search. | |
| + # `images=False` (the KiCad "without historical images" ablation): no episode | |
| + # keeps its observation/image.png and the row's `image` is None; the hashes the | |
| + # rows carry are still computed from the frame of the moment. | |
| + self.images = bool(images) | |
| + # `push=False` (the KiCad "without structured episode retrieval" ablation): the | |
| + # rows are written as before, but no [RECALL] or [SEEN BEFORE] line reaches a turn. | |
| + self.push = bool(push) | |
| + # `tool=False` (the MCU "without structured episode retrieval" ablation): the | |
| + # record is written exactly as before -- episodes/, index.jsonl, every image -- | |
| + # but `tools/episodes.py` is not put in the workspace, so the model reaches the | |
| + # same files through ordinary text search only. | |
| self.tool = bool(tool) | |
| self._dhash_at: dict[str, str | None] = {} | |
| self.dir = self.root / "episodes" | |
| @@ -197,6 +206,8 @@ class EpisodeStore(MemorySink): | |
| def turn_note(self, agent: "MemoryAgent", obs: "Observation") -> str | None: | |
| """Within this task: the earlier turns that faced this exact screen, or (recall | |
| on) the earlier turns that repeated the previous turn's transition.""" | |
| + if not self.push: | |
| + return None | |
| if self.recall: | |
| prev = self.previous_row(obs) | |
| rows = [r for r in self.closed if r is not prev] | |
| @@ -269,7 +280,7 @@ class EpisodeStore(MemorySink): | |
| d = self.dir / ep_id | |
| (d / "observation").mkdir(parents=True, exist_ok=True) | |
| (d / "state").mkdir(parents=True, exist_ok=True) | |
| - if obs.attachment and (self.root / obs.attachment).exists(): | |
| + if self.images and obs.attachment and (self.root / obs.attachment).exists(): | |
| _link(self.root / obs.attachment, d / "observation" / "image.png") | |
| _write_json(d / "state" / "state.json", state) | |
| ticks = 1 | |
| -- | |
| 2.43.7 | |