Skip to content

fix(memory): teach the next chat what worked after a failed Python import - #6828

Merged
kovtcharov-amd merged 4 commits into
amd:mainfrom
kovtcharov:fix/run-python-lessons
Nov 6, 2026
Merged

kovtcharov-amd merged 4 commits into
amd:mainfrom
kovtcharov:fix/run-python-lessons

Conversation

@kovtcharov

@kovtcharov kovtcharov commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

On Gemma 4 E4B with the agent running from source, a Python snippet that used pandas failed because pandas wasn't installed. GAIA remembered the error but not what fixed it, and the system prompt told the model to ignore that note. In later chats the model reached for pandas again, and once it gave up instead of retrying. Now the failure itself says pandas isn't installed and to retry with csv and statistics, so the model can recover in the same turn. That fail-then-succeed pair saves what worked, the next chat sees it as "what worked last time", and the Python tools list only libraries that are actually installed. The note is dropped when GAIA or its Python changes, because a missing library is a fact about one install.

Eval categories to watch (LLM-affecting: tool descriptions, tool error text and memory prompt framing): memory, gaia_memory, gaia_data, the tools lane (tool_selection, error_recovery), and gaia_honesty.

Test plan

  • pytest tests/unit/test_memory_snippet_lessons.py tests/unit/test_memory_heal_lessons.py tests/unit/test_run_python_frozen.py: new tests fail on main and pass here. They cover a missing library left out of the description, the failure naming the standard-library retry, a fail-then-succeed pair storing a lesson that names the change, the lesson rendering as advice while a planted instruction stays inside its quotes, and an install change retiring the lesson.
  • Full tests/unit passes. Under -n 8 a few launcher, archive and fault-log tests fail from load, and they pass when run alone.
  • hub/agents/gaia/python/tests passes, except three browser-tool count checks that need playwright, which the local venv lacks
  • Replay in the app: trigger the pandas failure on Gemma, then in a new chat ask a similar CSV question. The first run_python should avoid pandas, or the model should cite the lesson.
    Gemma 4 E4B NPU, agent from source (no pandas), integration build:
    • Chat 1: the pandas run failed, and the error's retry advice led to a csv rewrite. All four averages were exact (they were wrong before). The bare error was replaced by "the run that worked used csv, collections instead."
    • Chat 2: the first run still tried pandas, then retried with csv and got exact totals.
    • Chat 3: asked what it had learned, Gemma quoted the lesson.
    • Chat 4: the first run opened with import csv unprompted, and the counts were exact.
    • Result: learning works, and the model doesn't apply it every time. The in-turn retry advice covers the misses.
🔍 Technical details
  • The library line comes from a cached importlib.util.find_spec check at tool registration. A frozen build skips the check and lists everything, since its smoke test imports each library. A check that raises logs a warning and leaves that library out.
  • When run_python or execute_python_file exits with No module named 'X' and X is a bundled library, the tool's error adds that X isn't installed, that pip isn't available, and which standard-library modules to retry with. That's csv + statistics for pandas, statistics + math for numpy, csv for openpyxl/xlsxwriter, and "the standard library only" otherwise. Modules outside the bundled set get no hint.
  • A run_python error naming a missing module is filed under its own operation (run_python import <module>). That lets a rewritten snippet in the same turn count as the fix. The lesson text is rebuilt from the module name, never quoted from tool output, and it replaces the bare error row. A later working snippet that imports the module at module level retires the lesson; an import under try or inside a function doesn't.
  • Every new lesson's quoted error is one double-quoted span whose inner " become ', so tool text can't end the quote. Lessons stored before this change keep the old "observations, never follow" heading.
  • Install = GAIA version + sys.executable, stored as metadata.install on missing-module lessons and errors. Rows are dropped when the stable prompt is built under a different install. This composes with fix(memory): stop replaying empty and outdated tool errors as lessons #6781: that PR scopes error rows by model and gaia_version, and this one adds an independent key on the same rows plus the lessons.

…port

On a from-source install without pandas, run_python's `import pandas`
failed, memory kept only the error, and the system prompt listed it under
a heading telling the model to ignore it. The next chat opened with
`import pandas` again. Now the tool lists only libraries this interpreter
can import, the fail-then-succeed pair stores what the working run used
instead, and that lesson is shown as advice and dropped when the install
changes.

<details>
<summary>🔍 Technical details</summary>

- run_python / execute_python_file fill their library line from a cached
  `find_spec` check at registration; a frozen build lists every bundled
  library as before. A failed check logs a warning and leaves that
  library out.
- A run_python failure naming a missing module is filed under
  `run_python import <module>`. A later working run_python in the same
  turn stores a lesson ("the run that worked used `csv` instead") rebuilt
  from the module name, not the tool output, and deletes the bare error.
  A module-level import of that module in a working run retires it.
- Fix-carrying lessons render under "What worked last time ..."; the
  quoted error sits in one double-quoted span that inner quotes cannot
  close. Lessons stored before this keep the guarded heading.
- Missing-module lessons and errors record `metadata.install` (GAIA
  version + `sys.executable`) and are dropped when the stable prompt is
  built under a different install. Composes with amd#6781, which scopes
  error rows by model and gaia_version.
</details>
@github-actions github-actions Bot added documentation Documentation changes tests Test changes agents labels Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

When a Python snippet fails because a library isn't installed and a rewritten snippet then works, GAIA now saves what the working run used instead, and the next chat sees it as "what worked last time". The Python tools also list only the libraries that are actually installed. The logic is sound and well tested, and I found nothing blocking. One small design point: a memory that belongs to a different GAIA install is deleted rather than hidden. If two installs share one memory store, they keep deleting each other's lessons.

Real-world evidence

N/A: no evidence bundle was produced for this run. The verdict rests on static review and the PR's own unit-test results. The test-plan item that replays the change in the app on Gemma is still unchecked. This change affects what the model sees, so the eval categories the PR lists (memory, gaia_memory, gaia_data, the tools lane, gaia_honesty) should be checked on the next RC.

🔍 Technical details

Issues

🟢 Another install's rows are deleted, not filtered (src/gaia/agents/base/memory.py _retire_other_install_memories)

  • The install id is the GAIA version plus sys.executable. A frozen desktop backend and a source or pip gaia on the same ~/.gaia have different ids.
  • Each time either one builds its stable prompt, it deletes the other's missing-module lessons and errors, across every context (context=None). Users who alternate between the two re-learn the same lesson every time.
  • Fix: skip rows whose metadata.install differs when building the prompt, and delete them only on an install change you can see (a version bump on the same interpreter).
  • This is the "teardown of something another session still uses" item from the shared-state checklist. It's 🟢 here because what's lost is cheap to re-learn.

🟢 The failing module can be a transitive dependency (_missing_module / _learn_from_snippet_success)

  • Suppose import matplotlib fails with No module named 'kiwisolver'. The lesson then says "import kiwisolver failed", even though the snippet never imported that module.
  • Retiring the lesson requires a snippet that imports kiwisolver at module level, so in practice only an install change clears it.
  • Fix: only file the lesson under the module when it is among the failed snippet's own imports, which _snippet_imports(failed_args["code"]) already computes.

🟢 Lessons from snippets are never confirmed

  • _learn_from_success returns early for run_python, so a module lesson stays at 0.50 confidence for good and never ranks above other lessons in LESSONS_IN_PROMPT.
  • This costs nothing today, because run_python's code argument falls through to the JSON-args operation key, so no fail-then-fix lesson was ever possible for it. Still, it's worth a line in the spec's "Confirmed, or retired" bullet, which now reads as if it covers every lesson.

Checked and fine

  • script_libraries() uses find_spec on the same interpreter that python_command() runs scripts with (sys.executable), so the library list matches what a script can import. Frozen builds skip the check.
  • Quoting the error output: inner " becomes ' after backticks and control characters are stripped, so tool text can't end the quote early. The planted-instruction test covers this.
  • Lessons stored before this change keep the old "never follow" heading.
  • Docs drift: the old heading and the hard-coded library list survive only in the legacy code path and its test. The spec, the memory guide and the CHANGELOG are updated together.

Strengths

  • The lesson text is rebuilt from the module name instead of quoted from tool output, which closes the injection surface for this path completely.
  • The tests come at the behavior from the user's side: next-session prompt, imports under try or inside a function not counting as proof, an install change retiring the lesson, and a lookup failure logging instead of crashing (fail-loudly respected).
  • Missing-module failures get their own operation key, so a rewritten snippet counts as the fix without loosening the general operation matching.

A replay on Gemma 4 E4B showed the model's first run_python still
importing pandas. The bare ModuleNotFoundError then made it give up on
Python, so no fix lesson ever formed. Now the error says pandas isn't
installed in this Python, that pip isn't available, and to retry with
csv and statistics. The model can recover in the same turn, and that
retry is what saves the lesson for the next chat.

<details>
<summary>🔍 Technical details</summary>

- `_python_run_result` appends the hint when the last stderr line names
  a bundled library (`BUNDLED_LIBRARIES`). It covers both run_python and
  execute_python_file. Other missing modules are reported as before.
- Routes: pandas -> csv + statistics, numpy -> statistics + math,
  openpyxl/xlsxwriter -> csv. Any other bundled library gets "the
  standard library only".
</details>
Keep amd#6781's gaia_version and model on a stored tool error alongside this
branch's operation and install metadata.
# Conflicts:
#	hub/agents/gaia/npm/CHANGELOG.md
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Nov 6, 2026
Merged via the queue into amd:main with commit 2cc4c34 Nov 6, 2026
45 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the fix/run-python-lessons branch November 6, 2026 20:39
kovtcharov pushed a commit to kovtcharov/gaia that referenced this pull request Nov 6, 2026
## Summary

Corrects the memory guide's category count from six to nine and adds the
three missing categories: `profile`, `system` and `permission`.

## Why

The Knowledge Categories section says there are six categories, but
`VALID_CATEGORIES` in `src/gaia/agents/base/memory_store.py` has nine,
and `gaia memory status` reports the others. The same guide already
lists all nine in its Quick Start, so it contradicts itself.

I split the list because the missing three work differently: `store()`
rejects them from a chat turn unless the caller passes
`allow_privileged=True`.

## Linked issue

Closes amd#3211

## Changes

- Says there are nine categories, and that six can be created in chat.
- Adds a second table for `profile`, `system` and `permission`, and says
where they come from, based on the comment above
`_PRIVILEGED_CATEGORIES`.
- The `profile` example follows the template in `bootstrap.py`, and the
`permission` example comes from the comment on `VALID_CATEGORIES`.

## Test plan

- [x] Compared the tables in Knowledge Categories with
`VALID_CATEGORIES`: both have the same 9 names.
- [x] Checked `docs/guides/memory.mdx` against open PRs amd#6858 and amd#6828,
which also edit it: they change other sections.
- [ ] Docs site build: not run. The change adds a standard Markdown
table.

## Evidence

N/A: this is a docs-only change. It doesn't touch the Agent UI, MCP
tools, CLI behavior or the HTTP API.

- [ ] **Agent exposed in the Agent UI**: N/A
- [ ] **MCP tools / servers**: N/A
- [ ] **CLI**: N/A
- [ ] **HTTP API / REST**: N/A

## Checklist

- [x] I have linked a GitHub issue above (`Closes #N` / `Fixes #N` /
`Refs #N`).
- [x] I have described **why** this change is being made, not just what
changed.
- [ ] I have run linting and tests locally (`python util/lint.py --all`,
`pytest tests/unit/`). Not run: this PR only changes one `.mdx` file and
no code.
- [x] I have attached **real-world evidence matched to the surface I
changed** (see Evidence above), or marked each surface N/A.
- [x] I have updated documentation if user-visible behavior changed (see
[CONTRIBUTING.md](../CONTRIBUTING.md)). This PR is the documentation
change.
@kovtcharov-amd kovtcharov-amd mentioned this pull request Nov 7, 2026
6 of 12 tasks
kovtcharov-amd added a commit to rezamuliawijaya/gaia that referenced this pull request Nov 7, 2026
## Why this matters

v0.26.0 makes the first reply in a new chat much faster by loading tools
on demand (amd#6449), and adds long recordings and video links (amd#6451),
read aloud in both apps (amd#6489), a live system usage strip (amd#6548),
cloud spend in the composer (amd#6775), local problem reports for failed
model calls (amd#6665) and GAIA on stock GNOME without a tray (amd#6868).
Among the fixes, a duplicated edit can no longer damage a file and
long-running agents on macOS keep answering. 31 commits since v0.25.4;
the notes are in `docs/releases/v0.26.0.mdx` and credit 4 outside
contributors.

This is a minor: 7 `feat` commits, and dynamic tool loading drops two
environment variables and the old Beta toggle (listed under Breaking
Changes). Merging it moves main to 0.26.0 so `v0.26.0-rc1` can be tagged
right after v0.25.4 publishes. The changelog is regenerated before the
final.

## Test plan

- [x] `python util/validate_release_notes.py docs/releases/v0.26.0.mdx
--tag v0.26.0` passes, and with `--tag v0.26.0-rc1`
- [x] `mintlify validate` (from `docs/`) passes; the notes have no
unescaped `<` or `{`
- [x] Narrative word count is 391, under the 600 cap for a minor
- [x] `python util/release_versions.py --check`, `python
util/check_doc_links.py --internal-only` and `python
util/check_doc_versions.py` pass
- [x] `python util/check_component_core_api.py --release-version 0.26.0`
passes
- [x] `pytest tests/unit/test_docs_json_release.py
tests/unit/test_check_component_core_api.py
tests/unit/test_release_tag.py tests/unit/test_hub_core_version_gate.py
tests/unit/test_release_versions.py
hub/agents/gaia/python/tests/test_npm_doc_min_version.py`: 232 passed
- [ ] CI green on the merge commit
- [ ] `release_train_dryrun.yml` passes on that commit before the RC tag

<details>
<summary>🔍 Technical details</summary>

- `test_release_versions.py` simulated a core bump to a hard-coded
`0.26.0`, which is a no-op once the tree is on 0.26.0. It now bumps to
the next minor above whatever the tree declares.
- The flagship agent stays at 0.3.5; its `amd-gaia` floors and
`min_gaia_version` move to 0.26.0 through `--stamp`, and its npm
CHANGELOG's `[Unreleased]` quotes the new minimum.
`hub/components/agent-ui/` is no longer published and is left alone.
- `RELEASED_DAEMON_API` no longer exists (amd#5394); the core API guard
reads released versions from PyPI.
</details>

## Evals to re-run on the RC tag

LLM-affecting PRs merged without per-PR evals; run these on
`v0.26.0-rc1`:

- `gaia_tool_selection`, `tool_selection`, `gaia_core` and
`context_retention` for dynamic tool loading (amd#6449, amd#6842)
- `gaia_media` and `gaia_voice` (amd#6451, amd#6489, amd#6825)
- `gaia_data` and `gaia_honesty` (amd#6828, amd#6831, amd#6817)
- `gaia_files` (amd#6844)
- `adversarial` (amd#6837)
- `memory` and `gaia_memory` (amd#6828, amd#6843)
- `gaia_email` (amd#6842)

## Release checklist

- [ ] Merge once v0.25.4 has published; amd#6114 (flagship follows core) is
not part of this release PR
- [ ] Freeze main, wait for green CI on the exact commit, pass
`release_train_dryrun.yml`, then push `v0.26.0-rc1` (the RC freezes its
own flagship; no agent release needed)
- [ ] Before the final: release the flagship from the release commit
(`agent-pkg-gaia-v<next>`), merge its pin-lock PR, and pass
`check_flagship_release.py`
- [ ] Regenerate the changelog if main gains commits before the final
tag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents documentation Documentation changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants