Skip to content

feat(agent): a failed call carries what the task has already learned - #4536

Merged
kovtcharov-amd merged 3 commits into
amd:mainfrom
kovtcharov:kalin/task-lessons
Oct 1, 2026
Merged

kovtcharov-amd merged 3 commits into
amd:mainfrom
kovtcharov:kalin/task-lessons

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

A failed tool call is shown once and then scrolls up the conversation, so the agent walked into the same wall again several steps later: 22% of failed calls in 32 SWE-bench task runs repeated a failure from earlier in the same task. Now each failure is recorded as a lesson: what failed and why, plus what later worked for that program. The full list rides on every later failed result, so the agent sees it exactly when it is exploring. Lessons come only from the harness's record of what ran, never from content a tool returned, and they last for the turn.

6 hard SWE-bench tasks, DeepSeek V4.1 Flash without (2 runs) with
Repeated failures / failed calls 6/22, 5/23 1/13
Steps 215, 233 201
Solved 2/6, 3/6 3/6
Cost $0.52, $0.68 $0.55

It cuts the waste it targets without adding prompt text or model calls. It doesn't by itself solve more tasks.

Depends on #4527, which adds the per-program key this uses. The first commit here is #4527's; review the second.

Test plan

  • python -m pytest tests/unit/agents/test_task_lessons.py tests/unit/agents/test_turn_scope.py

The turn-scope guard ends a turn when one tool keeps failing with new
arguments. A shell tool runs many programs, so 'python -c' refused, then
ls denied outside the sandbox, then pip refused counted as one tool
failing four times, and a SWE-bench task was ended before any edit was
made. A shell line's streak is now keyed on the program it runs; a
single program refused with new arguments still stops as before.
Across 32 SWE-bench task runs, 22% of failed tool calls repeated a failure
the agent had already hit in the same task. Each failure is now recorded
as a lesson (what failed, why, and what later worked for that program),
and the list rides on every later failed result, so the constraints
learned so far are in view exactly when the agent is exploring.
@github-actions github-actions Bot added tests Test changes agents labels Oct 1, 2026
@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

When a tool call fails, the agent now also sees a short list of what has already failed earlier in the turn, and what later worked. This targets a measured problem: the agent kept repeating failures it had already hit. The change is small, capped at 8 lessons, and reset each turn, and the PR's SWE-bench numbers show repeated failures dropping. Nothing blocks merge.

  • One safety claim in the new module is overstated. It says lessons "never" come from content a tool returned. But each lesson quotes the tool's own error text, and some tools put exception or server text there. That text then rides on every later failure in the turn. Either narrow the claim or keep the error text out of lessons.
  • The before/after numbers come from 6 tasks (one "with" run against two "without" runs). That's enough to show the direction. Please say in the PR body which harness and command produced the table so a reviewer can rerun it.

Real-world evidence

N/A: no evidence bundle was produced for this run. The change is inside the agent loop and has no CLI, API, or UI surface of its own. The PR's SWE-bench table is the behavioural evidence. I couldn't run the unit tests here (pytest isn't installed in the review sandbox), so the verdict rests on static review plus that table.

🔍 Technical details

Scope: reviewed the second commit (d592a225), as the description asks. The first commit is #4527's per-program _streak_key.

🟡 Lesson text is tool-returned content (src/gaia/agents/base/task_lessons.py:96-98, :137)
lesson["error"] = _error_brief(result) takes result["error" | "message" | "stderr"]. That is tool output, and it can include exception strings (rag_tools.py:1495: f"Failed to extract text from document: {e}") or an MCP server's error text. It's capped at 200 chars, and FAILURE_STREAK_CORRECTION already echoes last_error once. What's new is that the text is re-attached to every later failure, up to 8 lessons. Correct the docstring so maintainers don't rely on a guarantee that isn't there:

The lessons are keyed and counted from the harness's own records of what ran;
the error text is the tool's own (truncated) error brief. They last for the
turn.

(Or, if the guarantee matters: store only failed_call and the count, and drop error.)

🟢 Lessons persist across mutating calls, but the guard's streaks don't
TurnScopeGuard.record clears every failure streak after a mutating tool runs ("the world changed"). TaskLessons keeps its lessons. That's probably what you want (a lesson is a fact about the environment), but a lesson like "pip install failed" can go stale once a later write fixes the cause. One line in the class docstring would make this a stated choice.

🟢 Retried successes overwrite worked with the newest call
self._lessons[key]["worked"] = _call_text(...) runs on every success for that key, so a long run of python ... calls keeps replacing the example with the latest one. That's harmless, but the first success is usually the more instructive one. You could keep it with if not ...["worked"].

Strengths

  • Reuses fix(agent): count shell failure streaks per program, not per tool #4527's _streak_key / _is_tool_failure / _error_brief, so lessons and streak counting can't disagree about what counts as a failure. A program exiting non-zero is correctly excluded and tested.
  • A first failure adds nothing, which keeps the common single-failure case free of extra tokens.
  • test_the_agent_loop_puts_the_lessons_on_the_next_failure drives the real process_query loop and checks what was actually sent to the model, not just the helper's return value.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Oct 1, 2026
Merged via the queue into amd:main with commit da2d3a7 Oct 1, 2026
41 of 43 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the kalin/task-lessons branch October 1, 2026 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants