Repository navigation
Conversation
7 tasks
itomek
enabled auto-merge
May 7, 2026 13:32
itomek
force-pushed
the
973-custom-python-agents-crash-with-unexpected-keyword-argument-rag_documents
branch
from
May 7, 2026 13:52
d681283 to
f97799e
Compare
Custom Python agents loaded from ~/.gaia/agents/<name>/agent.py crashed at instantiation with TypeError on rag_documents because python_factory forwarded every kwarg blindly to the user's class. Built-in chat_factory already filtered against ChatAgentConfig dataclass fields; the asymmetry was the bug. Mirror the chat_factory filter in python_factory by introspecting the target class __init__ chain via inspect.signature over klass.__mro__. Edge cases handled: PEP 570 positional-only, C-extension __init__ (be permissive), classes with no own __init__ (filter to empty). Compute the accepted-kwargs set once at registration time so introspection failures surface during agent load, not on the user's first message. allowed_paths is a sandbox capability — silently dropping it relaxes the session-intended file-access constraint. Log such drops at WARNING (with the class name and remediation hint), per CLAUDE.md "no silent fallbacks". Other dropped kwargs stay at debug level. Fixes #973
… signature get_or_refresh() has always returned str (not Tuple[str, int]). The original b9166b4 implementation was incorrect — it did tuple unpacking of a str return, which would have crashed in production with ValueError. The #965 Gmail PR fixed oauth_pkce.py to use single assignment but left the tests mocking the old tuple contract, causing test_returns_token_dict_shape to fail with: assert ('tok-abc', 9999999999) == 'tok-abc' Fix: update all four get_or_refresh mocks in test_oauth_pkce.py from tuple returns to string returns, and remove the now-incorrect expires_at assertion and docstring entry.
itomek
force-pushed
the
973-custom-python-agents-crash-with-unexpected-keyword-argument-rag_documents
branch
from
May 7, 2026 14:10
f97799e to
597065b
Compare
itomek-amd
approved these changes
May 7, 2026
itomek
deleted the
973-custom-python-agents-crash-with-unexpected-keyword-argument-rag_documents
branch
May 7, 2026 14:27
theonlychant
pushed a commit
to theonlychant/gaia
that referenced
this pull request
May 7, 2026
## Why this matters Ships the v0.17.6 patch: a new Email Triage Agent with Gmail (every email body stays on local Lemonade), the OAuth PKCE foundation that backs it, settings UI card layout, and a sweep of installer fixes that close the remaining first-launch failures uncovered after v0.17.5. Custom Python agents that follow the template's `super().__init__(**kwargs)` pattern no longer crash on the first message in the Agent UI. Full notes: `docs/releases/v0.17.6.mdx`. ## What's New - **Email Triage Agent with Gmail** ([amd#965](amd#965)) — `EmailTriageAgent` with 25 tools across read / organize / reply / delete / calendar mixins. Every email body processed locally on Lemonade; seven destructive tools confirmation-gated; three layers of prompt-injection defense; SQLite undo log via `DatabaseMixin`. - **OAuth PKCE foundation for Google connections** ([amd#926](amd#926)) — Self-contained `gaia.connections` module: refresh tokens in the OS keychain (Keychain / DPAPI / SecretService), per-agent grants in `~/.gaia/connections/grants.json`, async token cache with refresh rotation. Baseline for the v0.17.7 connectors framework. - **Settings UI card layout** ([amd#969](amd#969)) — Outlined cards with accent left-stripe replace margin-separated blocks across all settings sections; light + dark themes both updated. ## Bug Fixes - **Custom Python agents crashed on first message** ([amd#974](amd#974), closes [amd#973](amd#973)) — `python_factory` now introspects the target class's `__init__` chain and only forwards kwargs the chain accepts, so the bare `super().__init__(**kwargs)` template pattern no longer crashes with `unexpected keyword argument 'rag_documents'`. - **Windows installer failed at `ensure-uv`** ([amd#968](amd#968), closes [amd#966](amd#966)) — `uv` binary now bundled for `win-x64`; packaged Windows rescue installer included. - **macOS installer failed at `ensure-uv` on clean Apple Silicon** ([amd#967](amd#967), closes [amd#941](amd#941)) — Pinned `uv` v0.5.14 (`aarch64-apple-darwin`) shipped in the DMG; new `dmg-structural-smoke` CI job blocks future drift. - **AppImage users hit `gaia: command not found`** ([amd#942](amd#942), closes [amd#782](amd#782)) — Startup writes a `~/.local/bin/gaia` shim so `gaia` is on PATH after first launch (skips creation if already present). - **Windows fell back to Qwen instead of Gemma 4 default** ([amd#949](amd#949), closes [amd#948](amd#948)) — Model-resolution logic fixed so Gemma loads correctly on Windows. ## Tooling & Docs - **`gaia-release` skill** ([amd#939](amd#939)) — Phased release flow with hard gates before every irreversible step; encodes the manual pre-tag verification that caught two release-blocking bugs in v0.17.4. - **Internal-task issue template** ([amd#906](amd#906)) — Third issue template for agent-assignable internal work. - **Outlook via Power Automate plan** ([amd#954](amd#954)) — Enterprise-bypass spec for v0.17.7 Outlook integration. - **PR description guidance sharpened** ([amd#947](amd#947)) — `CLAUDE.md` "tight and value-focused" rule with anti-patterns. - **Stale `macOS uv fetch removed` orphan comment removed** ([amd#975](amd#975)). ## Thanks External contributors in this release: - [@theonlychant](https://github.com/theonlychant) — installer fixes ([amd#968](amd#968), [amd#942](amd#942), [amd#949](amd#949)) - [@BlueriteSoul](https://github.com/BlueriteSoul) — reported AppImage `gaia: command not found` ([amd#782](amd#782)) - [@nuts23](https://github.com/nuts23) — reported Windows Gemma/Qwen fallback ([amd#948](amd#948)) ## Release checklist - [x] `util/validate_release_notes.py docs/releases/v0.17.6.mdx --tag v0.17.6` passes - [x] `src/gaia/version.py` → `0.17.6` - [x] `src/gaia/apps/webui/package.json` → `0.17.6` - [x] Navbar label in `docs/docs.json` → `v0.17.6 · Lemonade 10.2.0` - [x] All 14 commits in the range (v0.17.5..HEAD) are represented in the notes - [ ] Review from @kovtcharov-amd addressed
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.
Why this matters
Before: any custom Python agent under
~/.gaia/agents/<name>/agent.pywhose__init__did baresuper().__init__(**kwargs)— the pattern the agent template ships with — crashed on the first message in the Agent UI:The UI session layer always injects four session-context kwargs (
rag_documents,library_documents,allowed_paths,ui_session_id) into everyregistry.create_agent(...)call. Built-inchat_factoryfiltered these againstChatAgentConfigdataclass fields; user-loadedpython_factoryforwarded them blindly straight into the baseAgent.__init__which has no**kwargs. Every custom agent was unusable from the UI.After:
python_factoryintrospects the target class's__init__chain over its MRO and only forwards kwargs the chain accepts — same idea aschat_factory, just againstinspect.signatureinstead of dataclass fields. Custom agents instantiate cleanly. Authors who wantrag_documents(or any other session kwarg) declare it in their own__init__and the filter passes it through. Introspection runs once at agent load time, so a broken__init__surfaces during registration, not on the user's first prompt.allowed_pathsis a sandbox capability — silently dropping it would relax the session-intended file-access constraint. Per CLAUDE.md "no silent fallbacks", drops of security-relevant kwargs log at WARNING with the class name and a remediation hint; other drops stay at DEBUG.Fixes #973
Test plan
tests/unit/agents/test_registry_python_factory.pycovering: helper edge cases (PEP 570 positional-only, dataclass__init__, C-extension, no-__init__-in-MRO, mixin chain, full passthrough), the literal production-failure kwarg set ({model_id, rag_documents, library_documents, allowed_paths, ui_session_id}), debug log of dropped kwargs, WARNING log on droppedallowed_paths, declaring-agent passthrough with no false-positive warning, and an end-to-end regression for built-inchat.tests/unit/agents/test_registry.py(41 tests) passes unchanged — no regression in built-in agent registration.python util/lint.py --black --isort --flakeclean.tests/fixtures/custom_agents/minimal/agent.pyto~/.gaia/agents/minimal/, launchgaia chat --ui, switch to theminimalagent, send a prompt. Expect noTypeErrorand a normal response; tail~/.gaia/logs/ui.logforregistry: python_factory droppedat DEBUG. (Run by reviewer or release-manager — requires a Lemonade backend.)