Repository navigation
feat(agent): delegate_task runs read-only helpers in the Python agent - #8447
Draft
kovtcharov wants to merge 9 commits into
Draft
kovtcharov wants to merge 9 commits into
kovtcharov wants to merge 9 commits into
Conversation
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
… 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.
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.
This was referenced Nov 18, 2026
10 of 19 tasks
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]>
This was referenced 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
read_file,search_file_content,browse_directoryandread_tool_output, reads only where its parent may, never asks for approval and inherits none. It has nodelegate_task, so helpers go one level deep. Its tools go into a private registry, so nothing leaks into the process-wide one.gaia -p --output-format jsonadds ahelpersblock and counts helper tokens once.--max-helpers(orGAIA_MAX_HELPERS) sets the number;0removes the tool.Not covered here:
--max-helpersis refused wheregaia -prelays 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 newgaia -pflags and the Agent UI changes since).delegate_taskis 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.pypython -m pytest hub/agents/gaia/python/tests/test_delegation_wiring.py hub/agents/gaia/python/tests/test_full_tool_bundles.pycd src/gaia/apps/webui && npx tsc --noEmit && npx vitest runnpm run test:rtlpython util/lint.py --allgaia -p "<a question over several files>" --output-format jsonshows ahelpersblock (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 0shows nonegaia_delegation(new),gaia_tool_selection,tool_selection,gaia_core,gaia_code,gaia_files,gaia_honesty,adversarialRefs #3383, #8401, #8444