Repository navigation
feat(cpp): sub-agents for gaiacpp and gaiacode - #9330
Draft
kovtcharov wants to merge 8 commits into
Draft
kovtcharov wants to merge 8 commits into
kovtcharov wants to merge 8 commits into
Conversation
…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.
3 tasks done
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.
…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.
4 of 9 tasks
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.
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.
docs/spec/sub-agents.mdxstates 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.explore(the read-only helper it had) and can offercode: gaiacode'sCodeAgent, in the agent's own folders and shell.codeis off unless--code-helperis 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.explore,reviewandtest. None has an edit tool. A test run by thetesthelper counts in the turn like gaiacode's own, so the "tests pass" check and the undo record stay truthful.gaiacode --max-helpers Nsets it.gaiacode's system prompt gains a Helpers paragraph and the
delegate_tasktool. 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, watchrag_qualityandgaia_tool_selection.Test plan
Ticked items were run on one Windows PC (natively, and in WSL Ubuntu for Linux).
cmake --build, thenLEMONADE_BASE_URL=http://127.0.0.1:1 ./tests_mock. Everything passes exceptLemonadeClientTest.DefaultConstruction, which that variable causestests_mock.exe --gtest_filter="SubAgent*:Gaiacpp*Helper*:GaiacodeHelpers*:DelegateTask*:HelperWidth*:HelperAgent*": every helper test passestests_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 needspython3in Git Bash; onegit configcall in a test is quoted for a POSIX shell; one timing test ran while other builds loaded the PC; andGaiaAgentTest.AnOfferToReadInsteadOfReadingIsSentBackfails under this MSVC for a reason not looked into; plus theLemonadeClientTest.DefaultConstructioncase abovepython -m pytest tests/unit/test_subagents_contract_parity.pypasses; 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 toogo test ./internal/ui/chat/ -run "Deleg|Helper"passes (the terminal UI reads a delegation by its result's shape, which is unchanged)gaiacode -pfixed a planted bug and had areviewhelper read the change; atesthelper ran a failing suite and named the cause;gaiacpp -phad helpers read three notes;gaiacpp -p --code-helper --full-accesshad the code helper write a script and its tests and run themgaiacpp -p --code-helperwithout--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🔍 Technical details
Design.
gaia::SubAgents(cpp/include/gaia/subagents.h) is the oldGaiaAgent::delegateTasksmoved intogaia_core, unchanged in what it checks and returns. An agent gives it a list ofHelperTypes: 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,SubAgentsthen removesdelegate_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_checksof 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.explorekeeps 30 steps and 10 minutes;testhas 15 minutes;codehas 60 steps and 30 minutes.Honest reporting. gaiacode's
testhelper is built with the parent's ownobserved(run_checks). gaiacpp's answer checks get thecodehelper's tool calls merged in at the point the helper ran, arun_checkscall 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_checkskeeps 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.
delegate_task, with an optionalagentper 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".--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_taskon 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 theagentfield. #8447 needs a rebase onto main before either can merge. One stated gap: the Python agent reports a helper stopped for repeating itself aserror, notloop.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.