Class ChatStreamerImpl

java.lang.Object
com.axelor.ai.chat.stream.ChatStreamerImpl
All Implemented Interfaces:
ChatStreamer

public class ChatStreamerImpl extends Object implements ChatStreamer
Multi-step agentic loop that streams LLM responses and executes tool calls.

Each invocation of stream(com.axelor.ai.chat.ChatRequest, com.axelor.ai.chat.stream.StreamWriter) runs an asynchronous loop: call the ChatProvider, relay text/reasoning deltas as StreamEvents, and when the provider finishes with FinishReason.TOOL_CALLS, execute the requested tools via ToolExecutor and feed results back for the next iteration. The loop is capped at 10 steps.

Sub-agent consultation is handled via ToolResult.Consult: the outer loop builds a nested pipeline for the target agent and runs runConsultLoop(com.axelor.ai.chat.stream.ChatStreamerImpl.AgentFrame, com.axelor.ai.chat.stream.StreamWriter, java.util.concurrent.atomic.AtomicBoolean, com.axelor.ai.chat.stream.ToolOutputDeduplicator) which streams to the same SSE connection, wrapped in a ConsultWriter so the sub-agent's prose does not surface in the conversation. The sub-agent finishes naturally — its last assistant text becomes the consult_agent tool output for the parent.

  • Method Details

    • stream

      public ChatHandle stream(ChatRequest req, StreamWriter w)
      Description copied from interface: ChatStreamer
      Starts an asynchronous streaming chat loop.

      The implementation calls the LLM, relays streaming deltas as StreamEvents to the writer, and when the LLM requests tool calls, executes them and feeds results back for subsequent iterations.

      Specified by:
      stream in interface ChatStreamer
      Parameters:
      req - the chat request containing message history and options
      w - the SSE stream writer for the HTTP response
      Returns:
      a handle to cancel the loop or await its completion