Skip to content

refactor(agents): let agents declare their own confirmation-required tool sets (#1440) - #1963

Merged
kovtcharov merged 3 commits into
mainfrom
refactor/per-agent-confirmation-tools-1440
Jul 9, 2026
Merged

kovtcharov merged 3 commits into
mainfrom
refactor/per-agent-confirmation-tools-1440

Conversation

@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Why this matters

Adding a destructive tool to any GAIA agent used to require editing a central hard-coded list in the base framework: TOOLS_REQUIRING_CONFIRMATION in agent.py carried eight email/calendar-specific tool names (send_draft, send_now, forward_message, permanent_delete, accept_invite, decline_invite, create_event_from_email, quarantine_phishing_message), coupling the framework to one agent's domain. A third-party agent had no way to self-declare a tool as confirmation-gated without patching core.

Now the base set holds only generic dangerous tools (shell / file mutation). Each agent declares its own gated tools on a CONFIRMATION_REQUIRED_TOOLS class attribute; Agent.confirmation_required_tools() merges (unions) it with the base set, and _execute_tool gates on the merged set. Net gating behavior is identical — the email agent's effective confirmation set is the same 17 tools it gated before; only ownership moved onto EmailTriageAgent.

Test plan

  • pytest tests/unit/agents/test_confirmation_required_tools.py — new unit tests: base set is generic-only, merge produces the union, subclass declaration doesn't mutate the shared base set, gated tool body never runs on denial, undeclared tool isn't gated
  • pytest tests/unit/agents/test_email_agent_confirmation.py tests/integration/test_never_auto_send.py tests/integration/test_email_rest_api_e2e.py — existing gating guards pass against the merged set (53 passed)
  • Verified EmailTriageAgent.confirmation_required_tools() == the pre-refactor 17-tool union (9 base + 8 email)
  • black --check / isort --check / flake8 clean on src/gaia + tests
  • Regenerated openapi.email.json (docstring reference updated) — contract drift test passes

Two unrelated failures in the touched files (test_email_agent.py::test_no_unexpected_tool_set on memory-mixin tools, and a phishing undo-window test that only fails under cross-test ordering) were confirmed pre-existing on a clean tree.

Closes #1440

…tool sets (#1440)

Email/calendar tool names (send_draft, send_now, forward_message,
permanent_delete, accept_invite, decline_invite, create_event_from_email,
quarantine_phishing_message) were hard-coded into the base
TOOLS_REQUIRING_CONFIRMATION set, coupling the framework to one agent's
domain. Any agent's destructive tool had to be added to a central list in
the base module.

The base set now holds only generic dangerous tools (shell / file
mutation). Each agent declares its own gated tools on the class attribute
CONFIRMATION_REQUIRED_TOOLS; Agent.confirmation_required_tools() unions the
two, and _execute_tool gates on the merged set. Net gating behavior is
identical — the email agent's effective set is the same 17 tools as before.
@github-actions github-actions Bot added documentation Documentation changes tests Test changes agents agent::email Email agent changes labels Jul 8, 2026
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Verdict: Approve

This moves the eight email/calendar tool names off the framework's central hard-coded confirmation list and onto the email agent itself, where they belong — a third-party agent can now self-declare its destructive tools without patching core. Gating behavior is unchanged: the email agent's effective set is the same 17 tools it gated before, just owned by the right class. Well-scoped, and the docstrings + OpenAI spec + both spec docs were all updated in the same PR so nothing drifts.

One thing worth keeping in mind for later (not blocking): the merge is a simple class-attribute override, so if a future agent ever spreads CONFIRMATION_REQUIRED_TOOLS declarations across several mixins, only one would win rather than unioning. The email agent centralizes its declaration on the agent class, so it's a non-issue today.

🔍 Technical details

Correctness — no issues found

  • confirmation_required_tools() (src/gaia/agents/base/agent.py:1897) wraps the module-level TOOLS_REQUIRING_CONFIRMATION (a mutable set) in frozenset() before unioning, so a subclass's frozenset can't mutate the shared base — and test_subclass_declaration_does_not_mutate_base locks that in.
  • The classmethod reads cls.CONFIRMATION_REQUIRED_TOOLS, so normal attribute resolution picks up the subclass override. The only runtime consumer, _execute_tool (agent.py:1981), now correctly gates on self.confirmation_required_tools().
  • Grepped for a parallel hardcoded list on the UI/REST side that could drift out of sync — there isn't one. The SSE path overrides console.confirm_tool_execution, not the tool set, so the gating decision stays centralized in the base agent. The REST send gate enforces its own token check independently (api_routes.py), correctly not relying on this set.

🟢 Minor (non-blocking)

  • Mixin-composition limitation (agent.py:297): CONFIRMATION_REQUIRED_TOOLS uses attribute shadowing, not an MRO-aware union — if gated-tool declarations are ever split across multiple mixins on one agent, only the MRO-first one survives. Fine for the current single-declaration pattern; worth a docstring note if/when a second agent adopts this.
  • test_undeclared_tool_is_not_gated (test_confirmation_required_tools.py:507) asserts result != {"status": "denied"}, which passes trivially since read_status returns the string "OK". Consider asserting result == "OK" (or that the tool body ran) for a tighter guarantee. Optional.

Strengths

  • Test coverage matches the refactor precisely: base-set-is-generic-only, the union, no base mutation, gate-fires-and-body-never-runs-on-denial, and undeclared-tool-not-gated. The _ProbeAgent in test_never_auto_send.py correctly moved its send_now declaration onto the class.
  • Every doc surface that named the old symbol was updated together — agent-ui.mdx, autonomous-agent-mode.md, all four tool-module docstrings, api_routes.py, and the regenerated openapi.email.json — so the package won't ship self-contradicting confirmation docs.

…nfirmation-tools-1440

# Conflicts:
#	src/gaia/agents/base/agent.py
The behavior-e2e harness spawned gaia.ui.server with unread
subprocess.PIPE stdout/stderr. The server logs several KB during
startup; on the Windows runner the OS pipe buffer (~4-8 KB) filled and
the server blocked on write, so the ASGI lifespan never finished and
/api/health never came up — the 30 s 'did not become healthy' timeout.

Redirect the child's output to a file (never blocks) under an artifacts
subdir so it uploads for diagnosis, widen the health budget to 90 s for
a cold first-run, and surface the server log tail on every failure path.

Once the server booted, the harness client timeout (180 s) was below the
server's own 600 s inference ceiling, so a still-running builder request
was cut client-side and wedged the single worker. Align the client
timeout to 620 s so the server-side bound governs.
@kovtcharov

Copy link
Copy Markdown
Contributor

Merged main into the branch (plain merge commit, no rebase) so the review history stays intact, and fixed the behavior-e2e failure at its root. The PR is now mergeable (no longer conflicting).

Conflict resolution. The only real conflict was in src/gaia/agents/base/agent.py: while this PR was open, #1609 added a new confirmation-gated tool (schedule_send) to the base TOOLS_REQUIRING_CONFIRMATION set. That's exactly the coupling this PR removes, so I kept the base set generic-only and migrated schedule_send into the email agent's own CONFIRMATION_REQUIRED_TOOLS — preserving both main's new behavior and this PR's per-agent-declaration intent. Also updated the two spots that asserted the old location (test_email_schedule.py, the schedule_tools.py docstring) and added schedule_send to the email agent's gated-tools test. Net gating behavior is unchanged.

What fixed behavior-e2e. Two stacked bugs, both pre-existing and unrelated to the refactor — the second was masked by the first:

  1. Server never became healthy (the visible 30 s timeout). The harness spawned gaia.ui.server with unread subprocess.PIPE stdout/stderr. The server logs several KB during startup; on the Windows runner the OS pipe buffer (~4–8 KB) filled, the server blocked on write, the ASGI lifespan never finished, and /api/health never came up. It passed locally only because the pipe buffer is larger there. Fix: redirect the child's output to a file (never blocks), surface the log tail on every failure path, and widen the health budget to 90 s for a cold first-run.

  2. Once the server booted, every scenario run timed out. The harness client timeout (180 s) was below the server's own 600 s inference ceiling (_get_chat_response wraps process_query in asyncio.wait_for(timeout=600)), so a still-running builder request was cut client-side and left in flight — wedging the single worker so later runs timed out too. Fix: align the client timeout to 620 s so the server-side bound governs and returns a clean response.

🔍 Verification
  • Confirmation/schedule suites: tests/unit/agents/test_confirmation_required_tools.py, test_email_agent_confirmation.py, tests/integration/test_never_auto_send.py, hub/agents/python/email/tests/test_email_schedule.py — 59 passed.
  • Full tests/unit/ — 6372 passed; the only failures are pre-existing local-env artifacts (a running Lemonade + py3.12 dep versions) that reproduce on main and pass in CI.
  • python util/lint.py --all — clean.
  • The behavior-e2e server-start deadlock is confirmed gone (the earlier run progressed past startup into the scenario for the first time); re-validating the timeout fix on a dispatched run.

@kovtcharov

Copy link
Copy Markdown
Contributor

Re-validated behavior-e2e on the head SHA: both infrastructure bugs are fixed — the server now boots and all 5 scenario runs complete cleanly in ~200 s (no more startup deadlock, no more ReadTimeout wedging).

The run still reports failure, but for a reason that is not an infrastructure issue and is unrelated to this PR: on the builder scenario the model (Qwen3.5-35B-A3B-GGUF) reliably scaffolds the agent file on only 1 of 5 runs — the other 4 reply conversationally ("Hi! I'm the Gaia Builder… I'll scaffold a starter agent template for you") without calling the write tool. That's honest_failure, not false_success — the #1428 safety invariant (never claim success without the side-effect) holds. This is a builder-agent prompt/model instruction-following signal that predates and is orthogonal to the per-agent-confirmation refactor (this PR touches neither src/gaia/agents/builder/ nor the builder's gating), so fixing it belongs in a separate prompt/eval change rather than here.

behavior-e2e is also a non-required, self-hosted check ("activates once #1297 lands"), so it doesn't gate merge. All other checks are green.

@kovtcharov
kovtcharov enabled auto-merge July 9, 2026 00:18
@kovtcharov
kovtcharov added this pull request to the merge queue Jul 9, 2026
Merged via the queue into main with commit 73e02e7 Jul 9, 2026
48 of 50 checks passed
@kovtcharov
kovtcharov deleted the refactor/per-agent-confirmation-tools-1440 branch July 9, 2026 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent::email Email agent changes agents documentation Documentation changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(agents): let agents declare their own confirmation-required tool sets

2 participants