Allow chat history to be sent to AI engine (#6128)

# Description of Changes
Add an extra parameter to every agent to receive the conversation
history in addition to the current message. This will make it possible
to answer followup questions from the AI without needing to give full
context in your message.
This commit is contained in:
James Brunton
2026-04-21 15:03:10 +00:00
committed by GitHub
parent f779085d75
commit 2a856fbc19
14 changed files with 116 additions and 19 deletions
@@ -0,0 +1,22 @@
package stirling.software.proprietary.model.api.ai;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
@Data
@Schema(description = "A prior message in the chat conversation")
public class AiConversationMessage {
@NotNull
@NotBlank
@Schema(description = "The role of the message sender", example = "user")
private String role;
@NotNull
@Schema(description = "The content of the message")
private String content;
}
@@ -1,5 +1,6 @@
package stirling.software.proprietary.model.api.ai;
import java.util.ArrayList;
import java.util.List;
import io.swagger.v3.oas.annotations.media.Schema;
@@ -20,4 +21,10 @@ public class AiWorkflowRequest {
@NotBlank
@Schema(description = "The user message to orchestrate", example = "Summarise these documents")
private String userMessage;
@Schema(
description =
"Prior chat messages exchanged between the user and the assistant, ordered"
+ " oldest-first. Excludes the current userMessage.")
private List<AiConversationMessage> conversationHistory = new ArrayList<>();
}
@@ -34,6 +34,7 @@ import stirling.software.common.util.ExceptionUtils;
import stirling.software.common.util.TempFile;
import stirling.software.common.util.TempFileManager;
import stirling.software.common.util.ZipExtractionUtils;
import stirling.software.proprietary.model.api.ai.AiConversationMessage;
import stirling.software.proprietary.model.api.ai.AiWorkflowFileInput;
import stirling.software.proprietary.model.api.ai.AiWorkflowFileRequest;
import stirling.software.proprietary.model.api.ai.AiWorkflowOutcome;
@@ -92,6 +93,10 @@ public class AiWorkflowService {
WorkflowTurnRequest initialRequest = new WorkflowTurnRequest();
initialRequest.setUserMessage(request.getUserMessage().trim());
initialRequest.setFileNames(new ArrayList<>(filesByName.keySet()));
initialRequest.setConversationHistory(
request.getConversationHistory() == null
? new ArrayList<>()
: new ArrayList<>(request.getConversationHistory()));
listener.onProgress(AiWorkflowProgressEvent.of(AiWorkflowPhase.ANALYZING));
@@ -183,6 +188,7 @@ public class AiWorkflowService {
WorkflowTurnRequest nextRequest = new WorkflowTurnRequest();
nextRequest.setUserMessage(request.getUserMessage());
nextRequest.setFileNames(request.getFileNames());
nextRequest.setConversationHistory(request.getConversationHistory());
nextRequest.setArtifacts(pdfContentExtractor.buildArtifacts(contentResults));
nextRequest.setResumeWith(response.getResumeWith());
return new WorkflowState.Pending(nextRequest);
@@ -415,6 +421,7 @@ public class AiWorkflowService {
private static class WorkflowTurnRequest {
private String userMessage;
private List<String> fileNames = new ArrayList<>();
private List<AiConversationMessage> conversationHistory = new ArrayList<>();
private List<WorkflowArtifact> artifacts = new ArrayList<>();
private String resumeWith;
}