Skip to content

feat(agents): add chat_stream for streaming agent chat events - #2885

Draft
ks93 wants to merge 1 commit into
masterfrom
feat/agents-chat-stream
Draft

ks93 wants to merge 1 commit into
masterfrom
feat/agents-chat-stream

Conversation

@ks93

@ks93 ks93 commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add agents.chat_stream(...), which takes the same arguments as chat() but streams Server-Sent Events while the agent works. It sends stream: true with Accept: text/event-stream.
  • It yields typed events:
    • AgentChatProgress: status updates, e.g. "Searching knowledge graph...".
    • AgentChatResponseChunk: fragments of the reply, to be concatenated as they arrive.
    • AgentChatResponse: the final, complete response (cursor, messages, action calls). Always the last event.
    • UnknownAgentChatStreamEvent: for event types the SDK doesn't know yet.
  • The union is exported as AgentChatStreamEvent. The sync client gets a regular iterator through the codegen.
  • chat() and chat_stream() now share a small helper that builds the request body.

A separate method is used instead of a stream flag on chat(), since a function that returns a response or an iterator depending on a flag is awkward to type, especially for the generated sync client.

The codegen adds a # type: ignore [misc] to generated iterator methods. It isn't needed here (mypy flags it as unused), so it is removed by hand, the same as for geospatial.stream_features. The codegen's verify step ignores comments, so this stays in sync.

Testing

  • Unit tests for the request (stream flag, accept header), typed events in order, unknown event types, the [DONE] sentinel, multi-line data: fields, comment lines, and a stream without a trailing blank line.
  • Smoke-tested against a live CDF project: 71 response chunks followed by the final AgentChatResponse with a cursor, and the joined chunks matched the final text.

This branch has not been deployed

No deployments
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