ag-ui-protocol / ag-ui-protocol/ag-ui
setMessages from useCopilotChatInternal has no effect on CopilotSidebar when using AG-UI external agents
- Linguagem predominante
- Python
- Estrelas
- 15.9k
- Forks
- 1.4k
- Merge médio
- 1d 17h
- PRs com merge (30d)
- 163
Descrição
## Environment
- **CopilotKit**: 1.51.4
- **Backend**: `ag-ui-strands` (Python FastAPI + Strands Agent, deployed to AWS AgentCore)
- **Frontend**: Next.js 15, `CopilotSidebar`, `useCopilotChatInternal`
## Problem
We're implementing **session persistence** — saving conversation history to a backend store and restoring it on page load. The restore step calls `setMessages()` from `useCopilotChatInternal`, but the sidebar remains empty. The call succeeds (no error), `messages` from the hook briefly reflects the injected messages, but `CopilotSidebar` displays nothing.
## Minimal reproduction
```tsx
const { messages, setMessages } = useCopilotChatInternal();
// On mount, after fetching saved messages from our backend:
useEffect(() => {
if (restoredMessages?.length) {
setMessages(restoredMessages); // called successfully
console.log("messages after set:", messages); // shows the injected messages
// BUT: CopilotSidebar is still empty
}
}, [restoredMessages]);
```
## What we've confirmed
1. **`setMessages` is a no-op for CopilotSidebar display** — `useCopilotMessagesContext().messages` always returns `[]` in AG-UI mode, regardless of what `setMessages` writes.
2. **`initialMessages` prop is declared but unimplemented** — The prop exists on `CopilotSidebar` / `CopilotChat` but has no effect in practice. Searching the source, it's passed down but never used to seed the AG-UI message stream.
3. **Works for page refresh only with GraphQL-backed agents** — With a standard CopilotKit cloud/self-hosted backend, `setMessages` writes to the GQL store and `CopilotSidebar` reads from there. With an AG-UI external agent, `CopilotSidebar` reads from the AG-UI SSE stream context — a separate store. The two are not synchronized.
4. **`useCopilotChatInternal` vs `useCopilotChat`** — We found `useCopilotChatInternal` because the standard `useCopilotChat` only exposes the deprecated `visibleMessages`/`appendMessage`. The non-deprecated `messages`/`sendMessage` are internal. That discovery alone suggests the public API for AG-UI message access is unclear.
## What we actually need
A supported way to **pre-populate** the AG-UI sidebar with saved messages on mount, so users see their conversation history after a page reload without re-running the agent.
## Questions
1. Is there **any supported pattern** for restoring AG-UI message history on the client side?
2. Is the `initialMessages` prop intentionally unimplemented for AG-UI, or is this a gap?
3. Would a **PR implementing `initialMessages` for AG-UI** (injecting saved messages into the AG-UI stream context on mount) be accepted? We'd be happy to contribute.
## Workaround we're considering
Since `CopilotSidebar` reads from the AG-UI SSE stream, one approach would be to replay saved messages as synthetic SSE events through a local stream on mount. This feels fragile — we'd rather know the intended design.
Thanks for the great work on ag-ui-strands. The framework is excellent for production deployments — this is the only gap we've hit.
Guia de contribuição
Avaliação
Esta issue ainda não foi avaliada.