Skip to content

fix(showcase/google-adk): use Gemini for A2UI planner instead of OpenAI - #4094

Merged
jpr5 merged 4 commits into
mainfrom
fix/google-adk-use-gemini-for-a2ui
Apr 19, 2026
Merged

jpr5 merged 4 commits into
mainfrom
fix/google-adk-use-gemini-for-a2ui

Conversation

@jpr5

@jpr5 jpr5 commented Apr 19, 2026

Copy link
Copy Markdown
Contributor

Summary

The google-adk package's primary agent uses Gemini via google-adk's LlmAgent, but the secondary generate_a2ui tool was calling OpenAI's gpt-4.1 through openai.OpenAI(). Cross-provider dependency with no architectural justification — the A2UI planner's function-calling + forced tool-choice pattern works equally well via google.genai.

Rewrite to use google.genai.Client.models.generate_content with a ToolConfig forcing the render_a2ui function call (mode="ANY" + allowed_function_names). Drop the openai + httpx direct dependency entirely; google-genai is already pulled in transitively via google-adk and is now pinned explicitly at >=0.8.0.

Replaces short-term hotfix PR #4090 (which pinned openai in requirements.txt after the post-merge Railway deploy of #4083 crashed with ModuleNotFoundError: No module named 'openai'). #4090 is already closed; this PR is the architectural correction that keeps the Gemini-primary package on Gemini end-to-end.

Changes

  • src/agents/main.py — _get_openai_client → _get_genai_client (lru_cache'd google.genai.Client). Rewrote generate_a2ui body to build a types.Tool(function_declarations=[FunctionDeclaration]), force the call via types.ToolConfig(function_calling_config=FunctionCallingConfig(mode="ANY", allowed_function_names=["render_a2ui"])), and read the response from candidates[0].content.parts[*].function_call.args. Narrowed except clause to genai_errors.APIError/ClientError/ServerError + ValueError (for construction-time failures). A2UI_MODEL env var overrides the default gemini-2.5-flash model.
  • entrypoint.sh — OPENAI_API_KEY guard → GOOGLE_API_KEY guard; REQUIRE_OPENAI_API_KEY → REQUIRE_GOOGLE_API_KEY. Warn / fail-fast semantics preserved.
  • requirements.txt — explicit google-genai>=0.8.0 pin; no openai, no httpx.
  • src/app/api/health|debug/route.ts — report GOOGLE_API_KEY status instead of OpenAI/Anthropic/LangSmith (this is a Gemini-only package).
  • playwright.config.ts — inject GOOGLE_API_KEY to the dev-server env, not OPENAI_API_KEY / OPENAI_BASE_URL.
  • tests/python/test_generate_a2ui.py — rewrote 19 tests to mock google.genai.Client in place of openai.OpenAI. Preserves every error branch (a2ui_llm_error, a2ui_empty_response, a2ui_no_tool_call, a2ui_invalid_arguments) plus the happy path. Added A2UI_MODEL override coverage + string-args-parseable-as-JSON fallback.
  • tests/python/test_entrypoint_env_guards.py — migrated to exercise the GOOGLE_API_KEY / REQUIRE_GOOGLE_API_KEY branch.

Test plan

  • Unit tests: 53 passed locally (Python 3.12, google-adk + google-genai + all package deps installed)
  • docker build / scripts/dev-local.sh build google-adk: clean
  • docker compose up -d google-adk against latest image: container starts cleanly (no ModuleNotFoundError); uvicorn healthy; new WARN emitted when GOOGLE_API_KEY unset
  • import agents.main inside the container no longer pulls in any openai.* module
  • L1 (health) + L2 (agent) smoke via LOCAL_PORTS=1 playwright test integration-smoke -g "google-adk": both pass
  • L3 (chat) / L4 (tools) smoke: requires a live GOOGLE_API_KEY; left to CI / reviewer with secrets

The google-adk package's primary agent uses Gemini via google-adk's
LlmAgent, but the secondary `generate_a2ui` tool was calling OpenAI's
gpt-4.1 through openai.OpenAI(). Cross-provider dependency with no
architectural justification — the A2UI planner's function-calling +
forced tool-choice pattern works equally well via google.genai.

Rewrite to use google.genai.Client.models.generate_content with a
ToolConfig forcing the render_a2ui function call (mode="ANY" +
allowed_function_names). Drop the openai + httpx direct dependency
entirely; google-genai is already pulled in transitively via google-adk
and is now pinned explicitly at >=0.8.0.

Replaces short-term hotfix PR #4090 (which pinned openai in
requirements.txt after post-merge Railway deploy of #4083 crashed
with ModuleNotFoundError).

Changes:
- src/agents/main.py: `_get_openai_client` → `_get_genai_client`
  (lru_cached google.genai.Client). Rewrote generate_a2ui to build a
  `types.Tool(function_declarations=[FunctionDeclaration])`, force the
  call via `types.ToolConfig(function_calling_config=...)` and read
  the response from `candidates[0].content.parts[*].function_call.args`.
  Narrowed except clause to `genai_errors.APIError`/`ClientError`/
  `ServerError` + `ValueError` (for construction-time failures).
  A2UI_MODEL env var overrides the default gemini-2.5-flash model.
- entrypoint.sh: `OPENAI_API_KEY` guard → `GOOGLE_API_KEY` guard;
  `REQUIRE_OPENAI_API_KEY` → `REQUIRE_GOOGLE_API_KEY`.
- requirements.txt: explicit `google-genai>=0.8.0` pin; no openai, no
  httpx.
- src/app/api/health|debug/route.ts: report GOOGLE_API_KEY status, not
  OpenAI/Anthropic/LangSmith (this is a Gemini-only package).
- playwright.config.ts: inject GOOGLE_API_KEY to the dev server env, not
  OPENAI_API_KEY / OPENAI_BASE_URL.
- tests/python/test_generate_a2ui.py: rewrote 19 tests to mock
  google.genai.Client in place of openai.OpenAI. Preserves every error
  branch (a2ui_llm_error, a2ui_empty_response, a2ui_no_tool_call,
  a2ui_invalid_arguments) plus happy path. Added A2UI_MODEL override
  coverage.
- tests/python/test_entrypoint_env_guards.py: migrated to exercise the
  GOOGLE_API_KEY / REQUIRE_GOOGLE_API_KEY branch.

Verification:
- Unit tests: 53 passed locally against Python 3.12 (google-adk + google-
  genai + all package deps installed).
- Docker build: clean (showcase-google-adk:local) via
  scripts/dev-local.sh.
- Container startup: `docker compose up -d google-adk` launches cleanly
  (no ModuleNotFoundError); uvicorn reports healthy; entrypoint emits
  the new WARN when GOOGLE_API_KEY is unset.
- L1+L2 smoke against local compose: both pass for google-adk.
- `import agents.main` inside the container no longer pulls in any
  `openai.*` module.
@vercel

vercel Bot commented Apr 19, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment Apr 19, 2026 3:18pm
research-canvas Ready Ready Preview, Comment Apr 19, 2026 3:18pm
travel Ready Ready Preview, Comment Apr 19, 2026 3:18pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
chat-with-your-data Skipped Skipped Apr 19, 2026 3:18pm
form-filling Skipped Skipped Apr 19, 2026 3:18pm

Request Review

@github-actions

Copy link
Copy Markdown
Contributor

📣 Social Copy Generator

Generate social media copies (Twitter/X, LinkedIn, Blog Post) for this PR using Claude.

  • Generate social media copies

@vercel
vercel Bot temporarily deployed to Preview – form-filling April 19, 2026 15:07 Inactive
@vercel
vercel Bot temporarily deployed to Preview – chat-with-your-data April 19, 2026 15:07 Inactive
@vercel
vercel Bot temporarily deployed to Preview – chat-with-your-data April 19, 2026 15:14 Inactive
@vercel
vercel Bot temporarily deployed to Preview – form-filling April 19, 2026 15:14 Inactive
@jpr5
jpr5 merged commit a2fa0bd into main Apr 19, 2026
1 check passed
@jpr5
jpr5 deleted the fix/google-adk-use-gemini-for-a2ui branch April 19, 2026 15:32
jpr5 added a commit that referenced this pull request Apr 19, 2026
…action

The GenerateA2UITool previously hardcoded openai.OpenAI() + gpt-4.1,
which meant non-OpenAI users still needed OPENAI_API_KEY even though
langroid itself is provider-agnostic (LANGROID_MODEL picks provider).

Route the A2UI planner through lm.OpenAIGPT — langroid's universal LLM
abstraction that dispatches to OpenAI / Anthropic / Gemini / any
provider based on the chat_model prefix. A2UI_MODEL env overrides only
the planner model; otherwise inherits from LANGROID_MODEL (default
openai/gpt-4.1).

Adds _A2uiError TypedDict + _a2ui_error constructor to match the error
shape used by sibling google-adk and strands agents. Every failure
branch (LLM exception, no tool call, malformed arguments, non-dict
arguments) now returns a structured {error, message, remediation} dict
instead of leaking provider exceptions. Programmer errors
(AttributeError, TypeError, NameError, SyntaxError) propagate so
regressions are caught in test and server logs.

Sibling to #4094 (google-adk); same smell, softer surface here since
langroid is already multi-provider — this PR just finishes the
abstraction.
jpr5 added a commit that referenced this pull request Apr 19, 2026
…4097)

## MERGE ASAP — main is RED

`Showcase validate` / `Run validate-pins (ratchet)` is failing on main
after PR #4095 (agno SDK upgrade) merged. This PR unblocks main CI.

## What drifted

Pure **set drift** — count unchanged, hash differs:

| field | before | after |
| --- | --- | --- |
| `validatePinsFailCount` | 110 | **110** (unchanged) |
| `validatePinsFailHash` | `c87ecdd6…a45560` | `958bcf24…4ae17` |

From failing run
[24632821166](https://github.com/CopilotKit/CopilotKit/actions/runs/24632821166):

```
validate-pins FAIL: actual=110 baseline=110
validate-pins HASH: actual=958bcf24c27cef69d7856e12deafe92073af7ad716289b2f6e4418827264ae17 baseline=c87ecdd6cc0829f8ef93c6e3cc4bb30aa3a577f99c5c8e9349b7c2dc78a45560
```

## Why

PR #4095 (`fix(showcase/agno): upgrade agno SDK to 2.5.17`) ratcheted
the hash against its own branch state, but other PRs merged in between
(#4094 google-adk, #4092 chown, etc.) shifted the baseline further. End
result: one `[FAIL]` healed while another regressed — net zero on the
counter but the failing tuples changed, so the hash no longer matches.

## What this PR does

Re-ratchets `showcase/scripts/fail-baseline.json` to the hash currently
produced by main. Count stays at 110.

## Risk

Minimal. Single field change in a JSON baseline file. No workflow edits.
No source changes. Does not hide new regressions — if any NEW failure
appears after this merges, the count (not just the hash) will bump and
CI will catch it.

## Test plan

- [x] Extracted actual hash from failing run output, not guessed
- [ ] CI green after merge (unblocks main)
zeekay pushed a commit to Dream-AI-4444/CopilotKit that referenced this pull request Sep 11, 2026
…AI (CopilotKit#4094)

## Summary

The google-adk package's primary agent uses Gemini via `google-adk`'s
`LlmAgent`, but the secondary `generate_a2ui` tool was calling OpenAI's
`gpt-4.1` through `openai.OpenAI()`. Cross-provider dependency with no
architectural justification — the A2UI planner's function-calling +
forced tool-choice pattern works equally well via `google.genai`.

Rewrite to use `google.genai.Client.models.generate_content` with a
`ToolConfig` forcing the `render_a2ui` function call (`mode="ANY"` +
`allowed_function_names`). Drop the `openai` + `httpx` direct dependency
entirely; `google-genai` is already pulled in transitively via
`google-adk` and is now pinned explicitly at `>=0.8.0`.

Replaces short-term hotfix **PR CopilotKit#4090** (which pinned `openai` in
`requirements.txt` after the post-merge Railway deploy of CopilotKit#4083 crashed
with `ModuleNotFoundError: No module named 'openai'`). CopilotKit#4090 is already
closed; this PR is the architectural correction that keeps the
Gemini-primary package on Gemini end-to-end.

## Changes

- **`src/agents/main.py`** — `_get_openai_client` → `_get_genai_client`
(`lru_cache`'d `google.genai.Client`). Rewrote `generate_a2ui` body to
build a `types.Tool(function_declarations=[FunctionDeclaration])`, force
the call via
`types.ToolConfig(function_calling_config=FunctionCallingConfig(mode="ANY",
allowed_function_names=["render_a2ui"]))`, and read the response from
`candidates[0].content.parts[*].function_call.args`. Narrowed `except`
clause to `genai_errors.APIError`/`ClientError`/`ServerError` +
`ValueError` (for construction-time failures). `A2UI_MODEL` env var
overrides the default `gemini-2.5-flash` model.
- **`entrypoint.sh`** — `OPENAI_API_KEY` guard → `GOOGLE_API_KEY` guard;
`REQUIRE_OPENAI_API_KEY` → `REQUIRE_GOOGLE_API_KEY`. Warn / fail-fast
semantics preserved.
- **`requirements.txt`** — explicit `google-genai>=0.8.0` pin; no
`openai`, no `httpx`.
- **`src/app/api/health|debug/route.ts`** — report `GOOGLE_API_KEY`
status instead of OpenAI/Anthropic/LangSmith (this is a Gemini-only
package).
- **`playwright.config.ts`** — inject `GOOGLE_API_KEY` to the dev-server
env, not `OPENAI_API_KEY` / `OPENAI_BASE_URL`.
- **`tests/python/test_generate_a2ui.py`** — rewrote 19 tests to mock
`google.genai.Client` in place of `openai.OpenAI`. Preserves every error
branch (`a2ui_llm_error`, `a2ui_empty_response`, `a2ui_no_tool_call`,
`a2ui_invalid_arguments`) plus the happy path. Added `A2UI_MODEL`
override coverage + string-args-parseable-as-JSON fallback.
- **`tests/python/test_entrypoint_env_guards.py`** — migrated to
exercise the `GOOGLE_API_KEY` / `REQUIRE_GOOGLE_API_KEY` branch.

## Test plan

- [x] Unit tests: 53 passed locally (Python 3.12, `google-adk` +
`google-genai` + all package deps installed)
- [x] `docker build` / `scripts/dev-local.sh build google-adk`: clean
- [x] `docker compose up -d google-adk` against latest image: container
starts cleanly (no `ModuleNotFoundError`); uvicorn healthy; new WARN
emitted when `GOOGLE_API_KEY` unset
- [x] `import agents.main` inside the container no longer pulls in any
`openai.*` module
- [x] L1 (health) + L2 (agent) smoke via `LOCAL_PORTS=1 playwright test
integration-smoke -g "google-adk"`: both pass
- [ ] L3 (chat) / L4 (tools) smoke: requires a live `GOOGLE_API_KEY`;
left to CI / reviewer with secrets
zeekay pushed a commit to Dream-AI-4444/CopilotKit that referenced this pull request Sep 11, 2026
…opilotKit#4097)

## MERGE ASAP — main is RED

`Showcase validate` / `Run validate-pins (ratchet)` is failing on main
after PR CopilotKit#4095 (agno SDK upgrade) merged. This PR unblocks main CI.

## What drifted

Pure **set drift** — count unchanged, hash differs:

| field | before | after |
| --- | --- | --- |
| `validatePinsFailCount` | 110 | **110** (unchanged) |
| `validatePinsFailHash` | `c87ecdd6…a45560` | `958bcf24…4ae17` |

From failing run
[24632821166](https://github.com/CopilotKit/CopilotKit/actions/runs/24632821166):

```
validate-pins FAIL: actual=110 baseline=110
validate-pins HASH: actual=958bcf24c27cef69d7856e12deafe92073af7ad716289b2f6e4418827264ae17 baseline=c87ecdd6cc0829f8ef93c6e3cc4bb30aa3a577f99c5c8e9349b7c2dc78a45560
```

## Why

PR CopilotKit#4095 (`fix(showcase/agno): upgrade agno SDK to 2.5.17`) ratcheted
the hash against its own branch state, but other PRs merged in between
(CopilotKit#4094 google-adk, CopilotKit#4092 chown, etc.) shifted the baseline further. End
result: one `[FAIL]` healed while another regressed — net zero on the
counter but the failing tuples changed, so the hash no longer matches.

## What this PR does

Re-ratchets `showcase/scripts/fail-baseline.json` to the hash currently
produced by main. Count stays at 110.

## Risk

Minimal. Single field change in a JSON baseline file. No workflow edits.
No source changes. Does not hide new regressions — if any NEW failure
appears after this merges, the count (not just the hash) will bump and
CI will catch it.

## Test plan

- [x] Extracted actual hash from failing run output, not guessed
- [ ] CI green after merge (unblocks main)

This branch was successfully deployed

3 active and 2 inactive deployments
Preview – research-canvas — e3b9defb Deployed Apr 19, 2026 by vercel[bot]
Preview – travel — e3b9defb Deployed Apr 19, 2026 by vercel[bot]
Preview – docs — e3b9defb Deployed Apr 19, 2026 by vercel[bot]
Preview – chat-with-your-data — e3b9defb Deployed Apr 19, 2026 by vercel[bot]
Preview – form-filling — e3b9defb Deployed Apr 19, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant