Skip to content

feat(cpp): SSE streaming response support for C++ agent framework#518

Open
itomek wants to merge 6 commits intomainfrom
360-c-framework-streaming-response-support
Open

feat(cpp): SSE streaming response support for C++ agent framework#518
itomek wants to merge 6 commits intomainfrom
360-c-framework-streaming-response-support

Conversation

@itomek
Copy link
Collaborator

@itomek itomek commented Mar 16, 2026

Closes #360

Summary

  • SseParser (sse_parser.h/cpp): stateful SSE line parser that handles chunked delivery, CRLF, [DONE] sentinel, malformed JSON, and role-only chunks without crashing
  • LemonadeClient streaming (lemonade_client.cpp): httpPostStreaming uses httplib's cli.send() API with ContentReceiverWithProgress; chatCompletionsStreaming wires SSE parser to caller callback, falls back to non-streaming JSON parse if server ignores stream:true, validates HTTP status even on Error::Canceled early exit
  • Console streaming (console.h/cpp, clean_console.h/cpp): printStreamToken flushes each token immediately; printStreamEnd emits trailing newline; SilentConsole inherits default no-ops
  • Agent integration (agent.cpp): callLlm branches on config_.streaming; processQuery suppresses progress spinners and duplicate print calls (thought/goal/finalAnswer) that were already streamed live
  • GAIA_STREAMING=1 env var: enables streaming without recompiling, following the same pattern as LEMONADE_BASE_URL
  • 245 unit tests: 18 new SseParser tests covering all edge cases; streaming tests added to console and types suites

Test plan

  • cmake -B build -DGAIA_BUILD_TESTS=ON && cmake --build build && ctest --test-dir build — all tests pass (245 total; 1 pre-existing failure due to LEMONADE_BASE_URL env var in CI)
  • Manual: GAIA_STREAMING=1 ./build/my_agent — tokens stream to terminal word-by-word
  • Manual: config_.streaming = false (default) — behavior identical to pre-PR baseline
  • Manual: agent against server that ignores stream:true — fallback returns correct response

🤖 Generated with Claude Code

Add token-by-token streaming through the full stack:

- SseParser: stateful parser for OpenAI SSE responses (data: lines,
  [DONE] sentinel, chunked delivery, CRLF handling, malformed JSON safety)
- LemonadeClient::chatCompletionsStreaming: streaming POST via httplib
  cli.send() with ContentReceiverWithProgress; falls back gracefully
  when server ignores stream:true; validates HTTP status on early
  Canceled exit to catch reverse-proxy errors
- LemonadeClient::httpPostStreaming: low-level streaming HTTP helper
- OutputHandler::printStreamToken / printStreamEnd: virtual no-op
  defaults; TerminalConsole and CleanConsole flush tokens immediately
- Agent::callLlm: branches on config_.streaming; accumulates tokens
  via callback, falls back to non-streaming JSON parse if no tokens received
- Agent::processQuery: skips progress spinners and duplicate
  printThought/printGoal/printFinalAnswer output when streaming
- AgentConfig::streaming: defaults to GAIA_STREAMING env var (=1 to
  enable without recompiling)
- 245 unit tests; 18 new SseParser tests covering all edge cases

Closes #360
@itomek itomek linked an issue Mar 16, 2026 that may be closed by this pull request
@github-actions github-actions bot added the cpp label Mar 16, 2026
@itomek itomek self-assigned this Mar 16, 2026
@itomek itomek marked this pull request as ready for review March 18, 2026 17:14
@itomek itomek requested a review from kovtcharov-amd as a code owner March 18, 2026 17:14
@github-actions github-actions bot added the tests Test changes label Mar 18, 2026
@itomek itomek force-pushed the 360-c-framework-streaming-response-support branch from 6aa48cd to 73387f9 Compare March 18, 2026 19:11
itomek added 4 commits March 18, 2026 15:14
- Add /EHsc to CMake for MSVC builds (C++ tests crashed without exception unwinding)
- Add USERPROFILE env var to MCP config tests (Path.home() uses USERPROFILE on Windows)
- Skip signal name tests on Windows (SIGKILL/SIGSEGV not available)
@itomek itomek force-pushed the 360-c-framework-streaming-response-support branch from d245f82 to 15c24df Compare March 18, 2026 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cpp tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

C++ Framework: Streaming response support

2 participants