Skip to content

feat(agent): delegate_task runs read-only helpers in the Python agent - #8447

Draft
kovtcharov wants to merge 9 commits into
amd:mainfrom
kovtcharov:kalin/python-delegate-task
Draft

kovtcharov wants to merge 9 commits into
amd:mainfrom
kovtcharov:kalin/python-delegate-task

Conversation

@kovtcharov

@kovtcharov kovtcharov commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

The Python agent could not split a job: every file it read stayed in its own context, so a long reading job filled the window. It can now hand parts of a job to helpers, each working in its own context, and get back only their conclusions. The agent decides whether to split, and is told to do work one script covers itself. The tool contract (arguments, result, limits, JSON output) is the same as the native agent's in #8444.

  • Helpers can only read. A helper is built with read_file, search_file_content, browse_directory and read_tool_output, reads only where its parent may, never asks for approval and inherits none. It has no delegate_task, so helpers go one level deep. Its tools go into a private registry, so nothing leaks into the process-wide one.
  • The tool does the splitting. The agent sends one brief with the files it covers and the tool shares them out, about one long file per helper.
  • Width follows the model. Eight at once on a cloud model. One at a time on a local model, on the side slot so the conversation's prompt cache stays in place: this agent sends one request at a time to a local model, so local helpers give the context saving, not a speed-up. Running local helpers side by side belongs to Local agent swarms: give each agent its own model-server slot and size the window for the swarm #8401.
  • The agent trusts what comes back. The result tells it to answer from the conclusions and not read the material again; a helper quotes the words that prove its answer.
  • Failures are loud. A helper that fails, times out or returns nothing is reported as failed with the reason.
  • You can see it. In the Agent UI the running row shows "3 of 4 helpers done", the finished row shows the summary in a warning tone when some helpers fell short, and opening it lists each helper with its task, conclusion or failure reason, steps and time. gaia -p --output-format json adds a helpers block and counts helper tokens once. --max-helpers (or GAIA_MAX_HELPERS) sets the number; 0 removes the tool.
  • Small models wait for evidence. A compact model is not offered the tool unless a helper count is given.

Not covered here: --max-helpers is refused where gaia -p relays to the agent's own binary through the daemon. A helper's reply that is a bare JSON object is now taken as its answer; the same reply from the main agent still goes round the loop, which is a separate fix to the base agent that needs the agent evals.

Brought up to main in one merge commit (the package rename to gaiapy, the sidecar move, the new gaia -p flags and the Agent UI changes since). delegate_task is the flagship's 107th tool; the capability matrix and API types are regenerated from the merged code. The ticked items below were run on Windows after the merge. Stacked on it, kovtcharov#14 aligns the tool to the sub-agent contract the native agents share (#9330).

Test plan

  • python -m pytest tests/unit/agents/test_delegate_task.py tests/unit/agents/test_tool_scope.py tests/unit/test_print_mode.py tests/unit/chat/ui/test_delegate_task_rows.py
  • python -m pytest hub/agents/gaia/python/tests/test_delegation_wiring.py hub/agents/gaia/python/tests/test_full_tool_bundles.py
  • cd src/gaia/apps/webui && npx tsc --noEmit && npx vitest run
  • npm run test:rtl
  • python util/lint.py --all
  • gaia -p "<a question over several files>" --output-format json shows a helpers block (a hosted model through Lemonade, run on this branch with feat(agent): delegate_task follows the shared sub-agent contract kovtcharov/gaia#14 on top: three helpers read three notes side by side)
  • --max-helpers 0 shows none
  • In the Agent UI, a delegating turn shows progress on the tool's row and a per-helper list when opened, in English and Arabic
  • Eval categories to watch on the next RC: gaia_delegation (new), gaia_tool_selection, tool_selection, gaia_core, gaia_code, gaia_files, gaia_honesty, adversarial

Refs #3383, #8401, #8444

The Python agent could not split a job: everything it read stayed in its own
context. It can now give tasks to helpers, each in its own context, and get
back only their conclusions, with the same tool contract as the native agent.

A helper is built with read_file, search_file_content, browse_directory and
read_tool_output and nothing else, registered into a private registry so
nothing leaks into the process-wide one. It reads only where its parent may,
its console denies every confirmation, and it has no delegate_task, so
helpers go one level deep. Cloud models run eight helpers at once; a local
model runs one at a time, on the side slot, because this process sends one
request at a time to a local model. A helper that fails, times out or returns
nothing is reported as failed. gaia -p gains --max-helpers and a helpers block
in its JSON output, and helper tokens count toward the turn's totals once. A
compact model is not offered the tool unless a helper count is given.

Refs amd#3383
@github-actions github-actions Bot added documentation Documentation changes cli CLI changes eval Evaluation framework changes tests Test changes security Security-sensitive changes performance Performance-critical changes agents labels Nov 17, 2026
… and harder tests

The result's summary is now the line a person reads and the model's advice is
its own field; progress goes out as a phased status so a UI can show it on the
running tool. Also reads a task list sent as JSON text, runs one helper on the
NPU whatever is asked, sizes conclusions so sixteen fit one result, and adds
path-escape and failure stress tests.
…come

A delegation showed as a wrench row reading "4 helpers": progress was
dropped, a part-failed result looked like a clean success, and which helper
did what never reached the browser. The running row now shows "3 of 4 helpers
done, 1 failed", the finished row shows the summary in a warning tone when
some helpers fell short, and opening it lists each helper with its task,
conclusion or failure reason, steps and time. The list survives a reload and
works for the native agent behind the Agent UI too. The model's advice never
reaches the browser.

Helpers are also told how long their answer may be, so their conclusions reach
the parent whole, and the guidance tells the agent to size a job before
deciding to split it.
@github-actions github-actions Bot added the electron Electron app changes label Nov 18, 2026
A small model hands every file to one helper, which then does the whole job
alone. A task that names more files than one helper should read is now
grouped by size and shared out, the same brief to each helper, and each
helper's row starts with the files it had.
…ong file per helper

Brings the Python agent in line with what real runs on the native agent
showed. The model is told to send one task that lists the files and the tool
shares them out, about one long file per helper and up to 64 helpers, spread
across the helpers there are. The result tells the agent to answer from its
helpers' conclusions and not read the material again, and a helper quotes the
words that prove its answer and says which files it read in full.
… the step limit

A brief often asks a helper for JSON. The agent loop read any JSON object as
its own thought/tool/answer format, found none of those keys, and asked again
without saying why until the helper ran out of steps. The answer still came
back, but as a partial one at many times the tokens. A helper's JSON reply
with none of the loop's own keys is now its answer.
kovtcharov-amd pushed a commit that referenced this pull request Nov 18, 2026
## Summary

A base `Agent` now treats a JSON object with none of the loop's protocol
fields as the model's answer, so a Python agent that returns a bare JSON
object ends the turn instead of asking again until the step limit.

## Why

Issue #8460: a plain Python agent asked for JSON receives a correct
object such as `{"notes_01.md": {"owner": "Ada", "budget": 4200}}`. The
decoder returned it as a protocol dict, the loop found no `answer` and
no tool call, silently asked again, and ran to the step limit. The
helper-only change in #8447 covers `HelperAgent`; this puts the same
rule in the shared base decoder. The helper override becomes redundant
on rebase.

## Linked issue

Closes #8460

## Changes

- Add `_PROTOCOL_KEYS` as `_ENVELOPE_KEYS` plus `answer`, `tool_calls`,
and `needs_plan`. `needs_plan` is included because the loop reads it
directly, so a standalone `{"needs_plan": true}` is not turned into an
answer.
- Add a thin `_decode_llm_response` wrapper over the existing decoder
body, now `_decode_llm_response_fields`. A decoded dict with no protocol
key becomes `{"thought": "", "goal": "", "answer": <raw reply>}`; every
other reply is returned unchanged.
- Add `tests/unit/agents/test_bare_json_answer.py` covering the direct,
lenient, and extracted JSON paths, protocol replies that must not be
wrapped, and a loop test that makes exactly one model request.
- The helper override in #8447 is idempotent with this base fix and can
be dropped when that PR rebases. This PR does not modify that branch.

## Test plan

- [x] Before the fix: `.venv/bin/python -m pytest
tests/unit/agents/test_bare_json_answer.py -q` reproduced the bug. The
bare object was returned unchanged instead of as an answer, and the loop
test asked the model twice (`assert 2 == 1`) before the scripted queue
raised `AssertionError: the model was asked more often than scripted`.
- [x] After the fix: `.venv/bin/python -m pytest
tests/unit/agents/test_bare_json_answer.py -q` gives `13 passed`.
- [x] `.venv/bin/python -m pytest
tests/unit/agents/test_thought_only_reply.py
tests/unit/agents/test_parse_error_recovery.py
tests/unit/agents/test_step_cap_usage.py
tests/unit/agents/test_tool_call_extraction.py
tests/unit/agents/test_parallel_tool_calls.py
tests/unit/agents/test_answer_beside_tool_calls.py -q` gives `118
passed`.
- [x] `PATH="$PWD/.venv/bin:$PATH" .venv/bin/python -m pytest
tests/unit/agents/ -q` gives `8063 passed, 69 skipped, 6 xfailed`. An
earlier run without the venv on PATH failed 45 tests in two files that
shell out to `python`; both files pass 466 of 466 with the venv on PATH.
- [ ] Full `pytest tests/unit/` was not completed locally. The agent
suite is the surface this change touches, and CI runs the full unit
lane.
- [x] `PATH="$PWD/.venv/bin:$PATH" .venv/bin/python util/lint.py --all`
gives 16 of 18 checks passing. Black, isort, Flake8, and Test Lane
Coverage pass. The two failures are the pre-existing Pylint E1120 errors
at `src/gaia/utils/awake_clock.py:47` and
`src/gaia/utils/terminal.py:109`. MyPy reports 2213 warnings and the
ratchet passes.
- [x] `.venv/bin/python util/check_test_lane_coverage.py` passes: 1862
test files are named by a lane or allowlisted. The new file is collected
by `pytest tests/unit/` in `test_unit.yml`.
- [x] `git diff --check` passes, and the added lines have no em or en
dashes.

Pending eval categories, not run here:

- [ ] `python util/run_eval_lane.py --category gaia_core --agent-model
Gemma-4-E4B-it-GGUF --judge-model claude-sonnet-4-6`
- [ ] `python util/run_eval_lane.py --category tool_selection
--agent-model Gemma-4-E4B-it-GGUF --judge-model claude-sonnet-4-6`

Prerequisites: a running Lemonade Server with `Gemma-4-E4B-it-GGUF`, and
a Claude judge credential in `CLAUDE_CODE_OAUTH_TOKEN` or
`ANTHROPIC_API_KEY`. Run the categories one at a time, one backend per
eval.

**Merge gate: both categories are pending. Do not merge until both
pass.** The matching CI jobs are `Scenario eval - gaia-code` and
`Scenario eval - tools` in `.github/workflows/eval_flagship.yml`; they
do not run on pull requests.

## Evidence

- [ ] **Agent exposed in the Agent UI** (Chat, Email, ...): N/A. This
changes the shared reply decoder, not UI code. A live Agent UI run needs
the same Lemonade model as the pending eval categories, which this
machine does not have.
- [ ] **MCP tools / servers**: N/A. No MCP surface changed.
- [ ] **CLI**: N/A. No CLI surface changed.
- [ ] **HTTP API / REST**: N/A. No REST surface changed.

The end-to-end evidence for this change is the two eval categories
above. They are pending and not claimed as passed.

## Checklist

- [x] I have linked a GitHub issue above (`Closes #8460`).
- [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/`). Lint ran and the agent suite ran; the full
`tests/unit/` run was not completed locally.
- [x] I have attached real-world evidence matched to the surface I
changed, or marked each surface N/A. Each surface is marked N/A above;
the eval categories are pending.
- [ ] Documentation was not changed. This is a bug fix that restores the
existing plain-text fallback; no new user-facing option or documented
behavior was added.

Signed-off-by: Niladri Das <[email protected]>
rapuckett pushed a commit to rapuckett/gaia that referenced this pull request Nov 19, 2026
## Summary

A base `Agent` now treats a JSON object with none of the loop's protocol
fields as the model's answer, so a Python agent that returns a bare JSON
object ends the turn instead of asking again until the step limit.

## Why

Issue amd#8460: a plain Python agent asked for JSON receives a correct
object such as `{"notes_01.md": {"owner": "Ada", "budget": 4200}}`. The
decoder returned it as a protocol dict, the loop found no `answer` and
no tool call, silently asked again, and ran to the step limit. The
helper-only change in amd#8447 covers `HelperAgent`; this puts the same
rule in the shared base decoder. The helper override becomes redundant
on rebase.

## Linked issue

Closes amd#8460

## Changes

- Add `_PROTOCOL_KEYS` as `_ENVELOPE_KEYS` plus `answer`, `tool_calls`,
and `needs_plan`. `needs_plan` is included because the loop reads it
directly, so a standalone `{"needs_plan": true}` is not turned into an
answer.
- Add a thin `_decode_llm_response` wrapper over the existing decoder
body, now `_decode_llm_response_fields`. A decoded dict with no protocol
key becomes `{"thought": "", "goal": "", "answer": <raw reply>}`; every
other reply is returned unchanged.
- Add `tests/unit/agents/test_bare_json_answer.py` covering the direct,
lenient, and extracted JSON paths, protocol replies that must not be
wrapped, and a loop test that makes exactly one model request.
- The helper override in amd#8447 is idempotent with this base fix and can
be dropped when that PR rebases. This PR does not modify that branch.

## Test plan

- [x] Before the fix: `.venv/bin/python -m pytest
tests/unit/agents/test_bare_json_answer.py -q` reproduced the bug. The
bare object was returned unchanged instead of as an answer, and the loop
test asked the model twice (`assert 2 == 1`) before the scripted queue
raised `AssertionError: the model was asked more often than scripted`.
- [x] After the fix: `.venv/bin/python -m pytest
tests/unit/agents/test_bare_json_answer.py -q` gives `13 passed`.
- [x] `.venv/bin/python -m pytest
tests/unit/agents/test_thought_only_reply.py
tests/unit/agents/test_parse_error_recovery.py
tests/unit/agents/test_step_cap_usage.py
tests/unit/agents/test_tool_call_extraction.py
tests/unit/agents/test_parallel_tool_calls.py
tests/unit/agents/test_answer_beside_tool_calls.py -q` gives `118
passed`.
- [x] `PATH="$PWD/.venv/bin:$PATH" .venv/bin/python -m pytest
tests/unit/agents/ -q` gives `8063 passed, 69 skipped, 6 xfailed`. An
earlier run without the venv on PATH failed 45 tests in two files that
shell out to `python`; both files pass 466 of 466 with the venv on PATH.
- [ ] Full `pytest tests/unit/` was not completed locally. The agent
suite is the surface this change touches, and CI runs the full unit
lane.
- [x] `PATH="$PWD/.venv/bin:$PATH" .venv/bin/python util/lint.py --all`
gives 16 of 18 checks passing. Black, isort, Flake8, and Test Lane
Coverage pass. The two failures are the pre-existing Pylint E1120 errors
at `src/gaia/utils/awake_clock.py:47` and
`src/gaia/utils/terminal.py:109`. MyPy reports 2213 warnings and the
ratchet passes.
- [x] `.venv/bin/python util/check_test_lane_coverage.py` passes: 1862
test files are named by a lane or allowlisted. The new file is collected
by `pytest tests/unit/` in `test_unit.yml`.
- [x] `git diff --check` passes, and the added lines have no em or en
dashes.

Pending eval categories, not run here:

- [ ] `python util/run_eval_lane.py --category gaia_core --agent-model
Gemma-4-E4B-it-GGUF --judge-model claude-sonnet-4-6`
- [ ] `python util/run_eval_lane.py --category tool_selection
--agent-model Gemma-4-E4B-it-GGUF --judge-model claude-sonnet-4-6`

Prerequisites: a running Lemonade Server with `Gemma-4-E4B-it-GGUF`, and
a Claude judge credential in `CLAUDE_CODE_OAUTH_TOKEN` or
`ANTHROPIC_API_KEY`. Run the categories one at a time, one backend per
eval.

**Merge gate: both categories are pending. Do not merge until both
pass.** The matching CI jobs are `Scenario eval - gaia-code` and
`Scenario eval - tools` in `.github/workflows/eval_flagship.yml`; they
do not run on pull requests.

## Evidence

- [ ] **Agent exposed in the Agent UI** (Chat, Email, ...): N/A. This
changes the shared reply decoder, not UI code. A live Agent UI run needs
the same Lemonade model as the pending eval categories, which this
machine does not have.
- [ ] **MCP tools / servers**: N/A. No MCP surface changed.
- [ ] **CLI**: N/A. No CLI surface changed.
- [ ] **HTTP API / REST**: N/A. No REST surface changed.

The end-to-end evidence for this change is the two eval categories
above. They are pending and not claimed as passed.

## Checklist

- [x] I have linked a GitHub issue above (`Closes amd#8460`).
- [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/`). Lint ran and the agent suite ran; the full
`tests/unit/` run was not completed locally.
- [x] I have attached real-world evidence matched to the surface I
changed, or marked each surface N/A. Each surface is marked N/A above;
the eval categories are pending.
- [ ] Documentation was not changed. This is a bug fix that restores the
existing plain-text fallback; no new user-facing option or documented
behavior was added.

Signed-off-by: Niladri Das <[email protected]>
kovtcharov-amd added a commit to kovtcharov/gaia that referenced this pull request Nov 20, 2026
…md#8444)

gaiacpp could not split a job: everything it read stayed in its own
context, and a job too large for one context window failed or crawled.
It can now hand parts of a job to helpers that work side by side, each
in its own context, and get back only their conclusions. On a
find-across-many-documents job a cloud model finishes several times
sooner with helpers and names the same documents; on a long reading job
a small local model gets right what it otherwise gets wrong. The agent
decides whether to split, and is told to do work one script covers
itself.

- **Helpers can only read.** A helper is built with `file_read`,
`file_search` and `read_tool_output`, inside the folders the agent is
confined to. No shell, writes, web or memory, and no `delegate_task` of
its own. It never asks for approval and inherits none, so
`--dangerously-skip-permissions` and saved answers do not reach it.
- **The tool does the splitting.** The agent sends one brief with the
files it covers; the tool shares them out, about one long file per
helper, and runs as many at once as the model serves: its slot count up
to four locally, eight on a cloud model, one on the NPU. The agent is
told how much there is to read and how large its window is, so it can
size a job before deciding. Background for the width numbers:
amd#8401 (comment).
- **The agent trusts what comes back.** The result tells it to answer
from the conclusions and not read the material again; a helper quotes
the words that prove its answer and says which files it read in full.
- **Failures are loud.** A helper that fails, times out or returns
nothing is reported as failed with the reason, and the summary counts
them.
- **You can see it.** The terminal UI counts finished helpers on its
status line and lists each helper's outcome under the step with Ctrl+O.
`--output-format json` counts helper tokens and adds a `helpers` block;
the step log records each helper's calls and conclusion.
- **Small models wait for evidence.** A compact model is not offered the
tool unless a helper count is given.
- **Two fixes found along the way.** A cloud reply cut off while
reasoning ended the whole turn through Lemonade; it is now asked again.
A hosted model reached through Lemonade was sized as if it had the local
default window.

Left for later: many independent workers in one process (amd#8396), one
shell per session (amd#8395, now the largest cost in a delegating run),
loading a model with slots sized for a swarm (amd#8401). The same tool in
the Python agent is amd#8447.

## Test plan
- [ ] `ctest --test-dir cpp/build -C Release --output-on-failure` (new:
`HelperWidth*`, `ModelCapacity*`, `HelperAgent*`, `DelegateTask*`,
`GaiacppCli.AHelperRun*`, `GaiacppSidecar.TheHelperSetting*`,
`GaiacppStdio.ADelegation*`, `AgentResilience.ACloudReplyCutOff*`)
- [ ] `python cpp/tests/chaos/chaos_gaiacpp.py --binary <gaiacpp> --runs
200 --jobs 4` (now includes delegation steps)
- [ ] `cd tui && go build ./... && go vet ./... && go test ./...`
- [ ] `gaiacpp -p "<a question over a folder of long documents>"
--output-format json` shows a `helpers` block; `--max-helpers 0` shows
none
- [ ] In the terminal UI, a delegating turn shows "N of M done" on the
status line and, with Ctrl+O, one line per helper

Refs amd#3383, amd#8401, amd#8396, amd#8395, amd#4838

---------

Co-authored-by: Kalin Ovtcharov <[email protected]>
@kovtcharov-amd kovtcharov-amd added the enhancement New feature or request label Nov 29, 2026
Brings the Python agent's delegate_task up to main: the flagship package is
now gaiapy, the sidecar relay moved to gaia.ui.sidecar, gaia -p gained
--disallowed-tools, --no-web and --no-skills, and the Agent UI changed around
the helper rows. delegate_task stays the flagship's 107th tool and the
delegation bundle its 29th; the capability matrix and the API types are
regenerated from the merged code. gaiacpp's delegate_task now shares the
Python agent's label instead of a native-only one.
…s 107 tools

Merging main put the entry inside 0.3.7, which shipped with GAIA 0.27.0 without it. It moves to Unreleased, and the tool count follows the merged registry.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents cli CLI changes documentation Documentation changes electron Electron app changes enhancement New feature or request eval Evaluation framework changes performance Performance-critical changes security Security-sensitive changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants