Skip to content

Streaming works in backend, but Agent Chat UI does not display messages during stream #143

Open
@he-or-h

Description

@he-or-h

Description

I’m using a Python LangGraph backend with the Agent Chat UI (Next.js).
The backend correctly streams messages via text/event-stream, and I can see event: message and event: done in the browser Network tab.

However, messages never appear in the chat UI.

What works:

  • Streaming backend is returning:
Transfer-Encoding: chunked
x-accel-buffering: no
Access-Control-Allow-Origin: *
  • Events look correct:
event: message
data: {"id": "0", "role": "ai", "content": [{"type": "text", "text": "Hello"}]}
id: 0
  • /threads/{id}/history contains the correct snapshots

What’s broken:

  • The chat UI does not show any streamed messages
  • No errors in console

Minimal backend example

from sse_starlette.sse import EventSourceResponse
from uuid import uuid4

@app.post("/threads/{thread_id}/runs/stream")
def run_stream(thread_id: str, payload: dict, request: Request):
    agent_id = payload.get("assistant_id")
    messages = payload.get("input")
    stream_mode = payload.get("stream_mode")

    if not agent_id or agent_id not in AVAILABLE_GRAPHS:
        raise HTTPException(status_code=400, detail="Invalid agent_id")

    graph = AVAILABLE_GRAPHS[agent_id]

    def event_stream():
        for i, (message, _) in enumerate(graph.stream(messages, config=RunnableConfig(configurable={"thread_id": thread_id}), stream_mode="messages")):
            yield {
                "id": str(i),
                "event": "message",
                "data": json.dumps({
                    "id": message.id or str(uuid4()),
                    "role": "ai",
                    "content": [{"type": "text", "text": message.content}]
                })
            }
        yield {"event": "done", "data": "{}"}

    return EventSourceResponse(event_stream())

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions