Package com.tnsai.agents.streaming
Class AgentStreamingSupport
java.lang.Object
com.tnsai.agents.streaming.AgentStreamingSupport
Handles streaming and event-based chat operations for an Agent.
This class extracts streaming/event concerns from the Agent class:
- Stream-based chat (streamChat)
- Event-based chat with callbacks (chatWithEvents)
- LLM invocation with progress events
- Tool call execution with events
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceContext interface for accessing Agent internals needed for streaming. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionchatWithEvents(String message, String sessionId) Chat with events using session-based publisher.chatWithEvents(String message, Consumer<TnsAIEvent> eventConsumer) Chat with event callbacks for AG-UI integration.chatWithEvents(String message, Consumer<TnsAIEvent> eventConsumer, ChatRetrievalContext retrievalContext) streamChat(String message) Streams the LLM response token by token.streamChatWithTools(String message, String requestSystemPrompt, Consumer<ChatChunk> handler) streamChatWithTools(String message, String requestSystemPrompt, Consumer<ChatChunk> handler, ChatRetrievalContext retrievalContext) streamChatWithTools(String message, Consumer<ChatChunk> handler) Streams a response with full tool calling support via ChatChunk callbacks.
-
Constructor Details
-
AgentStreamingSupport
-
-
Method Details
-
streamChat
Streams the LLM response token by token. -
chatWithEvents
Chat with event callbacks for AG-UI integration. -
chatWithEvents
public String chatWithEvents(String message, Consumer<TnsAIEvent> eventConsumer, ChatRetrievalContext retrievalContext) -
chatWithEvents
Chat with events using session-based publisher. -
streamChatWithTools
Streams a response with full tool calling support via ChatChunk callbacks.Combines streaming text output with tool execution in a multi-turn loop:
- Stream LLM response via
LLMClient.streamChatWithHandler(com.tnsai.llm.ChatRequest, java.util.function.Consumer<com.tnsai.llm.ChatChunk>) - If tool calls are received, execute them and emit TOOL_CALL chunks
- Send tool results back to LLM and repeat until final text response
- Parameters:
message- the user messagehandler- callback receiving ChatChunk events- Returns:
- the complete response string
- Stream LLM response via
-
streamChatWithTools
-
streamChatWithTools
-