ag-ui-protocol / ag-ui-protocol/ag-ui

[Bug]: Frontend tools registered via useFrontendTool are not invokable when using CopilotKit ↔ A2A (A2AAgent + A2AClient), but work via HttpAgent + ag_ui_adk endpoint

Abierto
#1,143 2 comentarios 0 reacciones 0 asignados Ver en GitHub
bug
Lenguaje dominante
Python
Estrellas
15.9k
Forks
1.4k
Merge medio
1 d 17 h
PR fusionados (30 d)
163

Descripción

### Pre-flight Checklist

- [x] I have searched [existing issues](https://github.com/ag-ui-protocol/ag-ui/issues) and this hasn't been reported yet.
- [x] I am using the **latest** version AG-UI.

### Describe the Bug

When I register a client-side tool in CopilotKit using `useFrontendTool` (example tool: `sayHello`) and expose tools on the backend via `AGUIToolset()` in a Google ADK A2A agent, the agent is **unable to invoke** the frontend tool when communicating through:

* CopilotKit runtime (`@copilotkit/runtime/v2`)
* `A2AAgent` (`@ag-ui/a2a`)
* `A2AClient` TypeScript client (`@a2a-js/sdk/client`)

However, if I expose the backend ADK agent using `ag_ui_adk` (`add_adk_fastapi_endpoint`) and connect from CopilotKit using `HttpAgent` (`@ag-ui/client`), the same frontend tool **is invoked successfully**.

This suggests tool invocation routing/handshake is broken specifically in the **A2AAgent + A2AClient path**, not in CopilotKit frontend tool registration itself.

---

### Affected Components

* CopilotKit frontend tool registration: `useFrontendTool`
* CopilotKit runtime endpoint: `createCopilotEndpoint` + `CopilotRuntime`
* A2A integration: `A2AAgent` + `A2AClient`
* Backend: Google ADK A2A agent with `AGUIToolset()`

### Actual behavior

When using **A2AAgent + A2AClient** as the runtime agent backend, the agent does **not** invoke the frontend tool (tool call does not reach the browser handler).

When using **HttpAgent + add_adk_fastapi_endpoint**, the tool invocation works and the browser tool handler executes.

## Why this seems like a bug

* The frontend tool is registered correctly (works in the HttpAgent path).
* The backend exposes tool support (`AGUIToolset()`).
* The only difference is transport/protocol path:

* ✅ Works: CopilotKit ↔ HttpAgent ↔ `ag_ui_adk` endpoint
* ❌ Fails: CopilotKit ↔ `A2AAgent` ↔ `A2AClient` ↔ A2A server

This suggests the A2A integration is not forwarding/negotiating client tool definitions or not routing tool-call messages back to the CopilotKit frontend tool executor.

---

### Steps to Reproduce

---

### 1) Register a frontend tool (Next.js client component)

`page.tsx`:

```tsx
"use client";

import { CopilotChat, CopilotKitProvider } from "@copilotkit/react-core/v2";
import { useFrontendTool } from "@copilotkit/react-core";
import { createA2UIMessageRenderer } from "@copilotkit/a2ui-renderer";
import { theme } from "./theme";

export const dynamic = "force-dynamic";

function MCPTool() {
useFrontendTool({
name: "sayHello",
description: "Say hello to someone.",
parameters: [
{
name: "name",
type: "string",
description: "name of the person to greet",
required: true,
},
],
handler: async ({ name }) => {
alert(`Hello, ${name}!`);
},
});

return null;
}

export default function Home() {
const A2UIMessageRenderer = createA2UIMessageRenderer({ theme });
const activityRenderers = [A2UIMessageRenderer];

return (




);
}
```

### 2) Create a CopilotKit runtime endpoint using A2AAgent + A2AClient

`api/copilotkit/route.ts`:

```ts
import {
CopilotRuntime,
createCopilotEndpoint,
InMemoryAgentRunner,
} from "@copilotkit/runtime/v2";
import { handle } from "hono/vercel";
import { A2AAgent } from "@ag-ui/a2a";
import { A2AClient } from "@a2a-js/sdk/client";

export const GET = (req: Request) => handler(req);
export const POST = (req: Request) => handler(req);

async function handler(req: Request) {
const a2aClient = new A2AClient("http://localhost:10007");
const agent = new A2AAgent({ a2aClient });

const runtime = new CopilotRuntime({
agents: { my_agent: agent },
runner: new InMemoryAgentRunner(),
});

const app = createCopilotEndpoint({
runtime,
basePath: "/api/copilotkit",
});

return handle(app)(req);
}
```

### 3) Backend ADK A2A agent includes `AGUIToolset()`

```py
def _build_agent(self) -> LlmAgent:
root_agent = LlmAgent(
name="basic_a2a_agent",
description="Helpful assistant",
model=LiteLlm(
model=f"openai/{os.getenv('OPENAI_MODEL_NAME')}",
api_key=os.getenv("OPENAI_API_KEY")
),
instruction="You are helpful agent, answer to user query in polite and friendly manner",
tools=[AGUIToolset()],
)
adk_agent = ADKAgent(
adk_agent=root_agent,
app_name="agents",
user_id="demo_user",
)
return adk_agent
```

### 4) Test: ask the agent to call `sayHello`

Example prompt:

> “Call the sayHello tool with name=Suraj”

**Result:** No alert appears, tool handler not invoked.

---

## Control test (works)

If I expose the backend agent with:

```py
add_adk_fastapi_endpoint(app, adk_agent, path="/")
```

…and connect CopilotKit using `HttpAgent` (AG-UI protocol), then the frontend tool invocation works as expected.

---

### Expected Behavior

---

When the user asks the agent to call a frontend tool (e.g., “Say hello to Suraj”), the backend agent should be able to invoke the CopilotKit client tool registered via `useFrontendTool`, and the handler should run in the browser:

```ts
handler: async ({ name }) => alert(`Hello, ${name}!`)
```

---

### Environment

```text
---

* Backend: "a2a-sdk",
"google-adk",
"google-genai",
"python-dotenv",
"litellm",
"ag-ui-adk>=0.4.2",

* Package versions:

"@a2a-js/sdk": "0.2.5",
"@a2ui/lit": "^0.8.1",
"@ag-ui/a2a": "0.00.6",
"@copilotkit/a2ui-renderer": "^1.51.3",
"@copilotkit/react-core": "^1.51.3",
"@copilotkit/react-ui": "^1.51.3",
"@copilotkit/runtime": "^1.51.3",
"hono": "^4.6.18",
"next": "^16.0.10",
"react": "^19.2.3",
"react-dom": "^19.2.3",
"zod": "^3.25.75"

---
```

### Screenshots

_No response_

### Logs & Errors

```shell
For A2A ADK agent

-2026-02-18 13:06:44,972 - INFO - ag_ui_adk.client_proxy_toolset - Initialized ClientProxyToolset with 0 tools (all long-running)
- 2026-02-18 13:06:44,972 - DEBUG - ag_ui_adk.adk_agent - Replaced AGUIToolset with ClientProxyToolset for agent basic_a2a_agent

for ag_ui_adk agent

- 2026-02-18 13:09:31,239 - INFO - ag_ui_adk.client_proxy_toolset - Initialized ClientProxyToolset with 1 tools (all long-running)
- 2026-02-18 13:09:31,239 - DEBUG - ag_ui_adk.adk_agent - Replaced AGUIToolset with ClientProxyToolset for agent basic_a2a_agent
```

### Additional Context

_No response_

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.