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

[Bug]: copilotkit_emit_message / copilotkit_emit_state / copilotkit_emit_tool_call events never reach the frontend (event name prefix mismatch with ag-ui-langgraph)

Aperta
#1,364 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub
bug
Lingua principale
Python
Stelle
15.9k
Fork
1.4k
Merge medio
1g 17h
PR unite (30g)
163

Descrizione

### 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

None of the manually emitted events (`copilotkit_emit_message`, `copilotkit_emit_state`, `copilotkit_emit_tool_call`) reach the frontend. They are silently dropped by `ag-ui-langgraph` because of an event name mismatch.

### Steps to Reproduce

1. Install copilotkit v0.1.83 (Python SDK) — which depends on ag-ui-langgraph v0.0.28.
2. In a LangGraph node, call `await copilotkit_emit_message(config, "Loading...")`.
3. Observe that the message never appears in the frontend CopilotChat UI.
4. The same issue affects `copilotkit_emit_state` and `copilotkit_emit_tool_call`.

### Expected Behavior

Messages emitted via `copilotkit_emit_message` should stream to the frontend as `TextMessageStart/Content/End` events and appear in the `CopilotChat` UI as assistant messages in real-time.

Similarly, `copilotkit_emit_state` should trigger `StateSnapshotEvent` and `copilotkit_emit_tool_call` should trigger `ToolCallStart/Args/End` events on the frontend.

### Environment

```text
Packages:
copilotkit==0.1.83
ag-ui-langgraph==0.0.28
ag-ui-protocol==0.0.18

Runtime:
Python 3.12
```

### Screenshots

Image

Image

### Logs & Errors

```shell
No errors in the terminal — events are dispatched successfully but silently ignored by `ag-ui-langgraph` because the `if event["name"] == CustomEventNames.ManuallyEmitMessage` comparison never matches (the actual event name has the `"copilotkit_"` prefix).
```

### Additional Context

**Root cause:** The `copilotkit` Python SDK (v0.1.83) dispatches custom events with a `"copilotkit_"` prefix, but `ag-ui-langgraph` (v0.0.28) expects the event names **without** that prefix:

| `copilotkit` SDK dispatches (langgraph.py) | `ag-ui-langgraph` expects (types.py `CustomEventNames`) |
|---|---|
| `"copilotkit_manually_emit_message"` | `"manually_emit_message"` |
| `"copilotkit_manually_emit_intermediate_state"` | `"manually_emit_state"` |
| `"copilotkit_manually_emit_tool_call"` | `"manually_emit_tool_call"` |
| `"copilotkit_exit"` | `"exit"` |

In `copilotkit/langgraph.py` (lines ~338, ~415, ~440, ~460):

```python
await adispatch_custom_event("copilotkit_manually_emit_message", ...)
await adispatch_custom_event("copilotkit_manually_emit_intermediate_state", ...)
await adispatch_custom_event("copilotkit_manually_emit_tool_call", ...)
await adispatch_custom_event("copilotkit_exit", ...)
```

In `ag_ui_langgraph/types.py`:

```python
class CustomEventNames(str, Enum):
ManuallyEmitMessage = "manually_emit_message"
ManuallyEmitToolCall = "manually_emit_tool_call"
ManuallyEmitState = "manually_emit_state"
Exit = "exit"
```

In `ag_ui_langgraph/agent.py` (line ~835):

```python
if event["name"] == CustomEventNames.ManuallyEmitMessage: # "manually_emit_message"
# This never matches because the actual event name is "copilotkit_manually_emit_message"
```

**Workaround:** Call `adispatch_custom_event` directly with the unprefixed names:

```python
from langchain_core.callbacks.manager import adispatch_custom_event

await adispatch_custom_event(
"manually_emit_message", # without "copilotkit_" prefix
{"message": message, "message_id": str(uuid.uuid4()), "role": "assistant"},
config=config,
)
```
## Suggested Fix

Either:
- Remove the `"copilotkit_"` prefix from the SDK's `adispatch_custom_event` calls in `copilotkit/langgraph.py`, **or**
- Add prefix-stripping logic in `ag-ui-langgraph`'s event handler in `agent.py`

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.