Skip to content

fix(agent): own tool-call markup switches only the session that wrote it - #6272

Merged
kovtcharov-amd merged 2 commits into
mainfrom
fix/markup-switch-session-only
Nov 1, 2026
Merged

kovtcharov-amd merged 2 commits into
mainfrom
fix/markup-switch-session-only

Conversation

@kovtcharov-amd

@kovtcharov-amd kovtcharov-amd commented Nov 1, 2026 •

Copy link
Copy Markdown
Collaborator

Since #6216, a single DeepSeek V4.1 Flash reply in its own tool-call format was enough to put it on native tool schemas permanently, for every later session on that machine. Those sessions then send about 12K more tokens on every call and make more model round trips. The switch to native calls now lasts only for the session where the markup appeared. Nothing is saved, and a machine that already recorded a model recovers on its own.

Test plan

  • tests/unit/test_native_tool_policy.py, adversarial cases: one stray reply in the model's own format affects only that session; many such sessions are never remembered; an existing own_tool_markup_models record is ignored and dropped on the next save; changing models mid-session doesn't carry the switch; a session with no model never counts as switched; Claude-style models still switch from their first reply
  • tests/unit/agents, gateway and tool-call suites (4844 passed, 56 skipped); black/isort clean
  • DeepSeek end to end on a GAIA home with the stale record cleared: stays on the in-text format, and no own_tool_markup_models is written
  • eval_flagship.yml manual dispatch
🔍 Technical details
  • The record appeared after DeepSeek wrote one reply in DSML markup. From then on, every DeepSeek process started with tools= (first call 22.4K tokens vs. 10.4K on the in-text format).
  • The switch now lives on the agent (_own_markup_model) and is keyed to the model that wrote the markup.
  • GatewayState no longer reads own_tool_markup_models, and drops it on the next save.

A gateway model that wrote its own tool-call markup once was put on native
tool schemas for every later session, through a record in gateway.json. A
single DeepSeek reply in its DSML format was enough, so every run after it
carried the full schemas (about 12K more tokens per call) and made more
model round trips, though DeepSeek otherwise follows the in-text format.

- The switch to native calls now lives on the agent and lasts for the rest
  of that session; nothing is written to gateway.json. Claude-style models
  that write their own markup from the first reply still switch at once.
- The switch is tied to the model that wrote the markup, so changing models
  mid-session does not carry it over.
- gateway.json's own_tool_markup_models is no longer read, and is dropped
  on the next save, so a machine that already recorded a model recovers.
@github-actions github-actions Bot added documentation Documentation changes llm LLM backend changes tests Test changes performance Performance-critical changes agents labels Nov 1, 2026
@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Skill audit

Skill Verdict Claimed tier Cleared tiers Findings Rules
hub/agents/email/npm ✅ ALLOW experimental experimental, community 2 medium, 1 info code.suppression, supply.undeclared_dependency
hub/agents/gaia/npm ✅ ALLOW experimental experimental 3 high body.injection.credential_request, body.injection.guardrail_bypass, body.injection.persona_override

✅ All audited skills cleared the tier they claim.

Per-finding detail is withheld here on purpose. Read it in the Security > Code scanning tab, or download the skill-audit-reports artifact from this run. Offending source text is withheld from CI everywhere — reproduce it locally with gaia skill audit <dir> --show-snippets.

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

Before this PR, one stray DeepSeek reply in its own tool-call format moved it to native tool schemas for every later session, costing about 12K extra tokens per call. Now the switch lasts only for the session that wrote the markup, and machines carrying the old record recover on their own. The fix is small and well tested, and the evidence below shows it working.

One thing to fix before merge:

  • The changelog describes a fix this PR doesn't contain. A new entry says run_python can now import a project's own gaia code. Neither this PR nor main has that change: run_python still refuses every import gaia… line. Move the entry into the PR that makes that change, or the release notes will promise a fix that doesn't ship.

Real-world evidence

The evidence stage ran the real gaia gateway CLI and the agent's tool-format check on a no-inference runner.

An old gateway.json that still has the retired key loses it on the next CLI save. Every other field is kept:

$ gaia gateway enable Kimi-K2.6
✅ Enabled Kimi-K2.6
exit=0

(own_tool_markup_models is absent from the saved file afterwards, and tool_calling_models is preserved.)

The switch lasts for one session only:

uses_native_tool_calls, fresh process w/ legacy own_tool_markup_models on disk: False
lemonade_client still exports record_own_tool_markup: False
session 1 native before own markup: False
session 1 native after own markup:  True
session 2 (new) native:             False

The spot-regression checks passed: gateway enable/disable and the no-action usage line all behave as before, and a grep finds no leftover callers of the removed helpers. Pending strix-halo lane: a live gateway model writing its own markup during a real turn. The verdict rests on static review and the evidence above for that path.

🔍 Technical details

Issues

🟡 CHANGELOG entry for an unrelated, unshipped change (hub/agents/gaia/npm/CHANGELOG.md, the second new ### Fixed bullet)
The bullet "run_python can check a project's own code…" isn't backed by this diff. It also contradicts the current code: _GAIA_TOOL_IMPORT_PATTERN in hub/agents/gaia/python/gaia_agent/chat_agent.py:152 still matches every import gaia / from gaia… import, not only from gaia import <tool>. Nothing here adds src/ to the path for run_python or execute_python_file either. It looks like the bullet slipped in from another branch. Drop it here:

- **One stray tool-call reply no longer triples a gateway model's token use.**
  A gateway model that wrote its own tool-call markup once was moved to native
  tool schemas (~12K more tokens per call) for every later session, so a single
  DeepSeek reply in its own format cost every run after it. The switch now
  lasts only for the session that wrote the markup.

🟢 Comment states what isn't there (src/gaia/llm/gateway.py, in GatewayState.load)
The "own_tool_markup_models is not read" comment explains a field that no longer exists. That reasoning belongs in the commit message, which already carries it. Consider removing the comment; the test test_an_older_builds_markup_record_is_ignored_and_dropped_on_save already pins the behaviour.

Strengths

  • The switch is stored on the agent and keyed to the model that triggered it, so changing models mid-session doesn't carry it over. A dedicated test covers this.
  • The fix deletes a whole persistence path (a module-level set, a cross-process union-merge, and its error handling) instead of adding a TTL or reset knob. That leaves less state to go wrong.
  • The adversarial tests cover the cases that matter: a single DSML slip, many sessions in a row, a legacy record left on disk, and an agent with no model. They assert that gateway.json is byte-for-byte unchanged after a switch.

Eval note: this changes which tool format hosted models get, which is an LLM-affecting path. Per the test plan, the DeepSeek 90-task run and the eval_flagship.yml dispatch are still pending. Watch the tool-calling categories on the next RC.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Nov 1, 2026
Merged via the queue into main with commit 87229e3 Nov 1, 2026
67 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the fix/markup-switch-session-only branch November 1, 2026 07:28
kovtcharov pushed a commit to kovtcharov/gaia that referenced this pull request Nov 1, 2026
…est (amd#6298)

Gateway Claude lost about 8 points on repository work after amd#6272, at
2–3× the cost: GAIA + Opus 5.5 dropped from 84 / 81 to 76 / 71 on 30
tasks under two judges, at $1.49 a task instead of $0.73. Since amd#6272,
every gateway session starts on the in-text tool format. Claude follows
that format instead of switching to native calls, and on it Claude
fabricates tool results in its own reply. Gateway Claude now gets native
tool calls from its first request. Other gateway models, such as
DeepSeek, are unchanged.

**Test plan**
- [x] `tests/unit/test_native_tool_policy.py`: `amd.Claude-*` is native
from the first request even if a probe recorded otherwise; DeepSeek,
local models named after Claude, `amd.Claudeish-*` and
`fireworks.claude-*` keep the in-text default. 4 of the new tests fail
without the fix.
- [x] `tests/unit/agents` plus gateway suites (4617 passed, 56 skipped);
black/isort clean
- [x] GAIA + Opus 5.5 end to end on 30 repository-work tasks, 2 runs: 79
/ 73 and 80 / 78 under the two judges (Claude Code + Opus: 82 / 79), at
$0.77 and $0.71 a task and 2.5 min a task, against 76 / 71 at $1.49 and
6.6 min on `main` without the fix
- [x] `eval_flagship.yml` smoke passed (local models are untouched)

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

- On the in-text format, Claude's assistant turns came back as
`{"thought": "<tool_response>{…invented file content…}"}`, degenerating
into repeated lines. Average assistant message: about 4,100 characters,
against about 1,100 when native.
- Before amd#6272, a stale `own_tool_markup_models` entry in `gateway.json`
happened to keep Claude native. amd#6272 correctly stopped persisting that
entry, which exposed the gap.
- The check keys on `gateway_claude_upstream_id`, the same test amd#6217
uses to route Claude to the Anthropic route, so the two can't disagree.
</details>
kovtcharov-amd added a commit to kovtcharov/gaia that referenced this pull request Nov 14, 2026
…truthfully, add gaia -p --time-limit (amd#6296)

When the agent hit its step limit or a loop guard, it stopped without
writing the file the user asked for, and sometimes claimed it had. A
safety refusal was reported to the model as "the user declined", so it
treated GAIA's own limit as the user's decision. After this, a forced
stop gets one write-only step for a requested file that doesn't exist
yet, and an unwritten file is named in the answer instead of being
claimed. Refusals are reported as refusals, a refused delete still
guards its target, and `gaia -p --time-limit` lets a headless run wrap
up before its deadline.

- **Needs a flagship eval before merge.** No system prompt, tool
docstring or schema changes, but the model reads new text: the
write-before-stop and time-limit prompts, the refusal wording, and a
stricter completion gate that can mark more turns incomplete. Run the
categories that cover step-cap and loop-guard endings, file deliverables
and shell denials.
- **`run_python` can now import the project's own code** (`import gaia…`
inside a GAIA checkout, and `src/` layouts). Only reaching for an agent
tool through `gaia` is still refused.

## Test plan
- [x] `pytest tests/unit/agents tests/unit/test_agent*.py` and the
touched test files: 5401 passed, 57 skipped
- [x] `tests/unit/agents/test_forced_stop_deliverable.py`: 17 passed.
The two new tests (existing file gets no rewrite step, instruction not
saved to history) each fail with their fix reverted.
- [x] Independent review: nothing blocking. Its two medium findings are
fixed in the last commit.
- [ ] Flagship eval via `eval_flagship.yml`, compared against
`tests/fixtures/eval_baselines/gaia-flagship/`

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

- Rebased onto current main. The one conflict, in `Agent.__init__`, kept
both `_own_markup_model` and the time-limit fields. The tool-call markup
commit was dropped because it is already on main (amd#6272).
- The write step runs only `write_file` / `write_markdown_file` /
`write_python_file`, one call per missing file, through
`_execute_tool_timed`, so confirmation, policy and read-before-overwrite
checks still apply.
- A refused redirect or overwrite (`echo x > notes.md`) no longer guards
that file unless the refusal names it. This is intentional, and
`docs/guides/gaia.mdx` describes it.
</details>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents documentation Documentation changes llm LLM backend changes performance Performance-critical changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant