Skip to content

feat(cpp): sub-agents for gaiacpp and gaiacode - #9330

Draft
kovtcharov wants to merge 8 commits into
amd:mainfrom
kovtcharov:kalin/gaia-sub-agents-aa6ea3
Draft

kovtcharov wants to merge 8 commits into
amd:mainfrom
kovtcharov:kalin/gaia-sub-agents-aa6ea3

Conversation

@kovtcharov

@kovtcharov kovtcharov commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

gaiacpp could hand reading to helpers, but gaiacode could not, and no helper could write: the code lived inside GaiaAgent. Now both agents use one mechanism, and one written contract covers the Python agent too. gaiacode gets helpers that read, review and run tests in their own context, so what they read never fills its window, and gaiacpp can hand a coding job (a script, a small program with its tests) to gaiacode's coding agent.

Stacked on #8795, so the first two commits here are #8788 and #8795; only the later ones are new. It will be re-stacked on the shared base agent from #8808 when that lands.

  • One contract for all three harnesses. docs/spec/sub-agents.mdx states the tool, the kinds of helper, what a helper inherits and never gets, the bounded result, how many run at once, approvals, limits and failure reporting. A parity test compares its values with the C++ header and with the Python agent's module (feat(agent): delegate_task runs read-only helpers in the Python agent #8447), so none of the three can drift. The Python half of that test skips, saying why, until feat(agent): delegate_task runs read-only helpers in the Python agent #8447 is in the tree.
  • gaiacpp keeps explore (the read-only helper it had) and can offer code: gaiacode's CodeAgent, in the agent's own folders and shell. code is off unless --code-helper is passed, because no model is proven for gaiacode yet; with it off, gaiacpp's tool schema and system prompt are unchanged. With it on, the helper runs alone, each call that needs approval is put to the user, and every call passes gaiacpp's own check first, so internet-off and the rule on commands GAIA cannot check still hold.
  • gaiacode gains explore, review and test. None has an edit tool. A test run by the test helper counts in the turn like gaiacode's own, so the "tests pass" check and the undo record stay truthful.
  • Helpers at once now differ more between local and cloud models: a local model's slot count up to 8 (was 4), 64 on a cloud model (was 8), still one on the NPU. gaiacode --max-helpers N sets it.

gaiacode's system prompt gains a Helpers paragraph and the delegate_task tool. No eval was run here; gaiacode has no eval baseline yet. gaiacpp's prompt and tool schema change only with --code-helper; without it, what changes for gaiacpp is how many helpers run at once, a helper's read cap on a small context window, and a failed helper's error text shrinking with the result. Where an eval scores the native agent, watch rag_quality and gaia_tool_selection.

Test plan

Ticked items were run on one Windows PC (natively, and in WSL Ubuntu for Linux).

  • Linux: cmake --build, then LEMONADE_BASE_URL=http://127.0.0.1:1 ./tests_mock. Everything passes except LemonadeClientTest.DefaultConstruction, which that variable causes
  • Windows (MSVC, Ninja, built without OpenSSL): tests_mock.exe --gtest_filter="SubAgent*:Gaiacpp*Helper*:GaiacodeHelpers*:DelegateTask*:HelperWidth*:HelperAgent*": every helper test passes
  • Windows, whole tests_mock.exe: no helper test fails. The failures are in tests this change does not touch: the file-snapshot, undo and skill-signing tests need OpenSSL, which this local build lacks; one test needs python3 in Git Bash; one git config call in a test is quoted for a POSIX shell; one timing test ran while other builds loaded the PC; and GaiaAgentTest.AnOfferToReadInsteadOfReadingIsSentBack fails under this MSVC for a reason not looked into; plus the LemonadeClientTest.DefaultConstruction case above
  • Windows: python -m pytest tests/unit/test_subagents_contract_parity.py passes; with the Python agent's module from feat(agent): delegate_task runs read-only helpers in the Python agent #8447 beside it, its Python half passes too
  • Windows: go test ./internal/ui/chat/ -run "Deleg|Helper" passes (the terminal UI reads a delegation by its result's shape, which is unchanged)
  • Real model (a hosted model through Lemonade Server), native Windows binaries and again on Linux: gaiacode -p fixed a planted bug and had a review helper read the change; a test helper ran a failing suite and named the cause; gaiacpp -p had helpers read three notes; gaiacpp -p --code-helper --full-access had the code helper write a script and its tests and run them
  • Linux, gaiacpp -p --code-helper without --full-access: the helper's test run was refused by gaiacpp's rule on commands it cannot check, and the answer said the tests were not run
  • A live run watched in the terminal UI or the Agent UI: not run. It needs a daemon of its own wired to a development build of gaiacpp, which was not set up here
  • macOS build: not run
  • A local model or the NPU: not run, so as not to evict the model other work on this PC was using
🔍 Technical details

Design. gaia::SubAgents (cpp/include/gaia/subagents.h) is the old GaiaAgent::delegateTasks moved into gaia_core, unchanged in what it checks and returns. An agent gives it a list of HelperTypes: a name, a factory for the agent that does the work, and switches (exclusive, writes, asksUser, reportsCalls). It lives in the core, not in a base class, so it does not depend on #8808; a base class can own the member later.

What a helper gets and never gets. It starts from the brief and the listed paths, never the conversation. It returns one conclusion, clipped so that every helper's fits one tool result, with the rest kept for read_tool_output. Whatever built it, SubAgents then removes delegate_task, gives it an empty in-memory approval store, and sets its confirm callback: the parent's for a kind that asks, an always-refuse one otherwise. A kind that asks must also run alone. A call with a runs-alone kind runs one helper at a time and is not shared out across files.

Approvals, stop, time. A forwarded approval takes one card at a time, and the time the user takes is added to that helper's deadline. gaiacpp has no run_checks of its own, so a code helper's test run is shown to the user as the shell line it runs, with its folder, and is judged by gaiacpp's check as that line. A helper's call never asks the user to open another folder. The parent's cancel is every helper's cancel check. explore keeps 30 steps and 10 minutes; test has 15 minutes; code has 60 steps and 30 minutes.

Honest reporting. gaiacode's test helper is built with the parent's own observed(run_checks). gaiacpp's answer checks get the code helper's tool calls merged in at the point the helper ran, a run_checks call read as the shell run it was, in the folder it ran in, so an edit the parent makes afterwards un-backs the claim and a passing run in one folder does not back a claim about another. run_checks keeps its result short enough that the record a turn keeps is never cut, so a long failing run still counts against the claim.

Design choices worth a look.

  • One tool, delegate_task, with an optional agent per task. The field appears only when more than one kind is offered, and the first kind is the default, so a model that ignores it gets the reader. An unknown kind is refused, never swapped; an empty string is read as "no kind".
  • No writing helper for gaiacode: two writers on one tree need shared ordering, undo and test-claim tracking, and splitting a coding task is where small models fail most.
  • No user-defined helper files, no background helpers, no forced "finish" tool. Each is a second place where tool access or completion is decided; none is needed for the kinds here.
  • A helper's read cap is about half its context window, at most 60,000 characters, so a small window is not overrun by one file.
  • With --code-helper, gaiacpp runs gaiacode's agent in-process, so the gaiacpp binary links gaiacode's agent, test runner and GitHub code. The GitHub tools are off in the helper; splitting them out fits the base-agent port better than this change.

The Python agent. It has no delegate_task on main; #8447 adds one built to the same shape. A small change on top of it (on the fork, against the #8447 branch) names the contract values, raises the cloud width to 64 and reads the agent field. #8447 needs a rebase onto main before either can merge. One stated gap: the Python agent reports a helper stopped for repeating itself as error, not loop.

Known limits. gaiacpp keeps no undo record of file changes, a code helper's included. The file tools' stale-read ledger is process-wide, so a helper and its parent share it. gaiacpp's advice refusals (read a small table first, a repeated command) look only at the parent's own calls, so a code helper can meet one once without cause. Neither app shows a helper's kind yet. A code helper's test-run approval can still offer "always", which is then taken as once. A test record gaiacpp cannot read (a command close to the size a turn keeps) is skipped by its claim check, so it does not replace an earlier failing run of the same command; that errs toward "could not confirm".

Seen on the way, not changed here. gaiacode's test-claim check sent back an answer that reported a failing run as a list ("4 passed, 2 failed"), reading it as a claim that the tests pass.

…n it didn't make

gaiacode is GAIA's coding agent as one native binary: it reads, edits and searches a repository, runs its tests and reads the results, and holds its answer to what the turn actually ran. An answer that says the tests pass needs a real passing run after the last edit, measured from the working tree, or it is sent back and then flagged.

- Headless (-p) mode with the workspace pre-check before any approval.
- Test runners: pytest, go, cargo, npm, ctest, mocha, rspec, phpunit, JUnit, dotnet, swift.
- The shell checks gaiacpp makes (planted file names, guarded files, a script's own dollars) move to gaia_core so both agents share one copy.
- File edits are recorded in the store the Agent UI reads, so Changes and Undo work.
- git never stops for a password or passphrase.

Rebased onto main as one commit; the earlier history is in the pull request.
gaiacode works with GitHub itself, over its REST API with no gh CLI needed: it reads issues and pull requests, reads CI checks and job logs, and, once the user approves, comments, opens pull requests and issues, submits reviews with comments on lines of the change, and re-runs a CI job. It ships three skills (fix-ci, issue-to-pr, pr-review) and offers only the skills whose tools it has.

- Tokens go only to the host they belong to; text to be posted is checked for credentials.
- A review is pinned to the commit it read and refused when the pull request has moved on.
- Headless runs make a write only when --allow-github-writes names its kind.

Rebased onto main as one commit; the earlier history is in the pull request.
gaiacpp could hand reading to helpers, but the code lived inside GaiaAgent, so
gaiacode had none and no helper could write. The mechanism is now one class in
gaia_core, gaia::SubAgents, that both agents own.

An agent lists the kinds of helper it offers. gaiacpp keeps its reader
("explore") and gains "code": gaiacode's CodeAgent, for a coding job inside a
larger task. gaiacode gains "explore", "review" and "test". A kind that runs
commands or writes works alone, and its approval requests go to the parent's
user; a reader never asks. No helper gets delegate_task, the parent's saved
approvals, or a folder the parent lacks, and the code helper's calls pass the
parent's own check first, so internet-off and the rule on commands GAIA cannot
check still hold.

A test run by a helper counts in the parent's turn: gaiacode's test helper uses
the parent's own run_checks, and gaiacpp's answer checks see the code helper's
calls in the order they happened.

Helpers at once: a local model's slot count up to 8 (was 4), 64 on a cloud
model (was 8), still one on the NPU. gaiacode takes --max-helpers.
The helpers were three implementations with nothing holding them together.
docs/spec/sub-agents.mdx now states the contract once (tool, kinds, limits,
result, approvals, failures), the C++ header names its values, and a parity
test compares the page, the header and the Python agent's module.

gaiacpp's code helper is off unless --code-helper is passed: no model is proven
for gaiacode yet, and with it off gaiacpp's tool schema and prompt are what
they were.

A code helper's test run is now judged, and shown to the user for approval, as
the shell line it runs in the folder it runs in, and its result says where it
ran, so a passing run in one folder cannot back a claim about another. A
helper's call no longer asks the user to open a folder, a kind that asks the
user must work alone, a call with such a kind is not shared out across files,
a failed helper's error shrinks with the rest of the result, and a helper's
read cap follows its context window.
@github-actions github-actions Bot added the tests Test changes label Nov 29, 2026
…contract says

An "always" given on a code helper's test run covered more than its card
showed; it is now taken as once. run_checks reports the folder the command left
the shell in, as bash_execute does, so a `cd` inside the command decides which
folder the run was about, and a record clipped past its end backs no claim.

The contract page said things the code did not do: gaiacpp offers the code kind
only when asked, a helper can also stop at its reply limit, the test kind has
no edit tool rather than no way to change a file, and the user's permission
mode answers a helper's request as it does the agent's own. The parity test now
checks that no reason outside the contract is reported, that each agent starts
from the contract's limits, and that the opt-in kind is off by default.

GAIA_CODE_HELPER with a value gaiacpp cannot read is an error, not "off".
…ests pass

A code helper's test run with hundreds of failures made a record too long to
keep whole, and a clipped record was dropped, so a later, narrower passing run
could back "tests pass". A clipped record of a run that failed is now kept,
since it can only speak against a claim; only a clipped pass backs nothing.
run_checks names at most 50 failing tests and counts the rest, so the record
stays whole in the first place.

The contract page no longer overstates how a many-file task is shared out, and
the parity test checks that both native agents read GAIA_MAX_HELPERS.
…f-read

A code helper's test record too long to keep whole lost the runner's summary
with its end, so a failing run of a command that names no test runner, or a
failure hidden behind exit 0, was still skipped by the parent's claim check.
The record's start keeps the folder, the exit code and the failure count; a
failed run is now rebuilt from those as a small, whole record. A clipped
passing run still backs nothing.

The test makes a record long enough to be clipped and says so if it is not.
…cuts it

A turn keeps the first 20,000 characters of a tool result as written out, where
a colour code or a backslash takes several. A test run with coloured or long
output went past that, lost its summary, and the claim check then read it
wrongly in either direction. run_checks now shortens its output from the start,
then the list of failing names, until the whole result fits, so the summary at
the end stays.

The fallback for a record that is still cut (a very long command) counts only a
run that exited with an error; anything else backs no claim.

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

cpp documentation Documentation changes enhancement New feature or request tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants