Class AiToolStatusPublisher
The callback is placed into the ToolContext by AiConversationChatService
under STATUS_UPDATE_CALLBACK. If no callback was provided by the caller (typical for non-UI scenarios),
all methods on this publisher are silent no-ops.
Typical tool usage — two-phase publish so the UI can render an in-flight indicator and a result snippet:
String msg = "Searching customers by name"; statusPublisher.update(toolContext, msg); String result = customerRepo.searchByName(...); // long-running work statusPublisher.complete(toolContext, msg, "found " + result.size());
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcomplete(String message, @Nullable String snippet, @Nullable org.springframework.ai.chat.model.ToolContext toolContext) Publishes the completion of a previously-started step.voidpublish(AiToolStatusUpdate update, @Nullable org.springframework.ai.chat.model.ToolContext toolContext) Forwards an arbitraryAiToolStatusUpdatethrough the status callback.voidPublishes an in-flight status update — "this step has started, no result yet".
-
Field Details
-
STATUS_UPDATE_CALLBACK
- See Also:
-
DEFAULT_TOOL_CONTEXT_MARKER
Key of the marker entry that the add-on places into the defaultToolContextof its chat clients, so it is visible to every tool invocation, including application-defined ones.Only the presence of the key is part of the contract — its value is unspecified and may change. An application whose tool iterates, logs or forwards the tool context should reference this constant to recognise and skip the entry rather than hard-coding the string.
- See Also:
-
-
Constructor Details
-
AiToolStatusPublisher
public AiToolStatusPublisher()
-
-
Method Details
-
update
public void update(String message, @Nullable org.springframework.ai.chat.model.ToolContext toolContext) Publishes an in-flight status update — "this step has started, no result yet". Sends anAiToolStatusUpdatewith a blankresultSnippet.- Parameters:
message- status text describing the step that has startedtoolContext- current tool context carrying the UI callback;null(no callback) makes this a no-op
-
complete
public void complete(String message, @Nullable String snippet, @Nullable org.springframework.ai.chat.model.ToolContext toolContext) Publishes the completion of a previously-started step.The
messagemust match the one passed toupdate(String, ToolContext)so the UI can fold the two into a single completed entry. A blanksnippetis treated as "nothing to report" and the call is a silent no-op.- Parameters:
message- same status text that was passed toupdate(String, ToolContext)snippet- short result of the finished step; blank ornullmakes this a no-optoolContext- current tool context carrying the UI callback;null(no callback) makes this a no-op
-
publish
public void publish(AiToolStatusUpdate update, @Nullable org.springframework.ai.chat.model.ToolContext toolContext) Forwards an arbitraryAiToolStatusUpdatethrough the status callback.Note, prefer:
which encode the two-phase contract correctly.- Parameters:
update- status update to deliver; ignored if its message is blanktoolContext- current tool context carrying the UI callback;null(no callback) makes this a no-op
-