Package com.axelor.ai.chat.stream
Class CollectingStreamWriter
java.lang.Object
com.axelor.ai.chat.stream.StreamWriter
com.axelor.ai.chat.stream.CollectingStreamWriter
- All Implemented Interfaces:
AutoCloseable
A
StreamWriter that collects text deltas in memory instead of writing SSE. Used by AiServiceImpl for synchronous agent invocations.
It also records how the turn ended, not just what it said. A turn that suspends waiting for a
human — a tool needing approval, a client-side tool — finishes cleanly with no Error
event, and a caller that only reads the text cannot tell that apart from a real answer. See
getSuspendedTools() and isMaxStepsExhausted().
-
Field Summary
Fields inherited from class com.axelor.ai.chat.stream.StreamWriter
HEADER_NAME, HEADER_VALUE, NOTIFY_MAX_STEPS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voiddone()Writes thedata: [DONE]\n\nterminator and flushes.getError()Returns the error message if the stream failed, or null.The tools the turn is still waiting on, empty when it ended on its own terms.getText()Returns the accumulated text from all text deltas.booleanisDone()booleanWhether the agentic loop stopped because it ran out of steps rather than finishing.voidwrite(StreamEvent event) Serializes the event asdata: {json}\n\nand flushes.Methods inherited from class com.axelor.ai.chat.stream.StreamWriter
clearNotify, notify, notify
-
Constructor Details
-
CollectingStreamWriter
public CollectingStreamWriter()
-
-
Method Details
-
write
Description copied from class:StreamWriterSerializes the event asdata: {json}\n\nand flushes.- Overrides:
writein classStreamWriter- Throws:
IOException
-
done
public void done()Description copied from class:StreamWriterWrites thedata: [DONE]\n\nterminator and flushes. Must be the last write.- Overrides:
donein classStreamWriter
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Overrides:
closein classStreamWriter
-
getText
Returns the accumulated text from all text deltas. -
isDone
public boolean isDone() -
getError
Returns the error message if the stream failed, or null. -
getSuspendedTools
The tools the turn is still waiting on, empty when it ended on its own terms. Non-empty means the agentic loop stopped mid-reasoning for a human — the text collected so far is a fragment, not an answer. -
isMaxStepsExhausted
public boolean isMaxStepsExhausted()Whether the agentic loop stopped because it ran out of steps rather than finishing.
-