Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
4f4df9e
Add temporal-spring-ai module for Spring AI integration
donald-pinckney Apr 6, 2026
31bc77e
Document callback registry lifecycle risk and add stream() override
donald-pinckney Apr 6, 2026
079089a
Add tests for temporal-spring-ai (T1-T4)
donald-pinckney Apr 6, 2026
b62adfa
Update TASK_QUEUE.json: T1-T4, T9, T11 completed
donald-pinckney Apr 6, 2026
e538674
Add T14 (NPE bug) to TASK_QUEUE.json
donald-pinckney Apr 6, 2026
c98af78
Fix UUID non-determinism, null metadata NPE, and unbounded tool loop
donald-pinckney Apr 7, 2026
54a5d40
Split SpringAiPlugin into conditional auto-configuration (T6)
donald-pinckney Apr 7, 2026
58804ad
Update TASK_QUEUE.json: T5, T6, T7, T10, T14 completed
donald-pinckney Apr 7, 2026
f4b1028
Update TASK_QUEUE.json: T12 completed
donald-pinckney Apr 7, 2026
e509673
Replace fragile string matching with instanceof in TemporalStubUtil (T8)
donald-pinckney Apr 7, 2026
0cc143e
Update TASK_QUEUE.json: T8 completed
donald-pinckney Apr 7, 2026
b09d2ff
Use WorkflowReplayer for proper replay determinism tests
donald-pinckney Apr 7, 2026
8ba4eb0
Simplify stream() exception message
donald-pinckney Apr 7, 2026
4b7aa19
Revert tool call iteration limit, match Spring AI's recursive pattern
donald-pinckney Apr 7, 2026
969aabd
Fix javadoc reference for publishToMavenLocal
donald-pinckney Apr 8, 2026
615ff92
Use SimplePlugin builder for VectorStore and EmbeddingModel plugins
donald-pinckney Apr 9, 2026
f6d781c
Clean up TASK_QUEUE.json: remove completed tasks, add T15
donald-pinckney Apr 9, 2026
336cc7b
Add link to proposed design for T15
donald-pinckney Apr 9, 2026
6d4d166
Triage Copilot and DABH review comments into TASK_QUEUE
donald-pinckney Apr 9, 2026
32e6f99
T16: Guard assistantMessage.getMedia() against null
donald-pinckney Apr 9, 2026
d9b5002
T17: Include Nexus stubs in unrecognized tool type error message
donald-pinckney Apr 9, 2026
bec50f8
T18: Use ObjectProvider to fix NoUniqueBeanDefinitionException
donald-pinckney Apr 10, 2026
9ebc25b
T19: Make replay test exercise tool calls
donald-pinckney Apr 10, 2026
6c3a107
T20: Handle duplicate MCP client names with clear error
donald-pinckney Apr 10, 2026
4e6003d
T21: Use float[] instead of List<Double> in EmbeddingModelTypes
donald-pinckney Apr 10, 2026
5d19df9
T18 fix: Use getIfUnique() instead of getIfAvailable()
donald-pinckney Apr 10, 2026
52c6d4b
Add T28: Restore plugin classes as public API per tconley review
donald-pinckney Apr 10, 2026
01fec57
Clean up TASK_QUEUE: remove completed, mark superseded
donald-pinckney Apr 10, 2026
1b5c56e
T28: Restore VectorStorePlugin and EmbeddingModelPlugin as public cla…
donald-pinckney Apr 10, 2026
bc6275f
T23: Resolved — MCP capability caching is correct
donald-pinckney Apr 10, 2026
60f2941
T24: Change from discussion to fix — rawContent should be String
donald-pinckney Apr 10, 2026
528e538
T22: Defer starter artifact to after PR merge
donald-pinckney Apr 10, 2026
d58700f
T25: Replied to DABH about docs. Added T29 for README follow-up.
donald-pinckney Apr 10, 2026
4e600da
T29: Bump to high priority, do in this PR
donald-pinckney Apr 10, 2026
e19463b
T15: Also remove LocalActivityToolCallbackWrapper and ExecuteToolLoca…
donald-pinckney Apr 10, 2026
2c97806
T24: Change ChatModelTypes.Message rawContent from Object to String
donald-pinckney Apr 10, 2026
70c8594
T29: Add README with compatibility matrix and quick start
donald-pinckney Apr 10, 2026
b11249a
T30: Fix edge CI Java version mismatch
donald-pinckney Apr 10, 2026
42f46d6
T31: Skip temporal-spring-ai on JDK < 17
donald-pinckney Apr 10, 2026
7cb1dbc
T15: Plain tools execute in workflow context by default
donald-pinckney Apr 10, 2026
f0d0f9a
Clean up TASK_QUEUE: remove completed and superseded
donald-pinckney Apr 13, 2026
7e7e5ad
Update README with tool execution model
donald-pinckney Apr 13, 2026
8e505f7
README: mention programmatic plugin setup for optional integrations
donald-pinckney Apr 13, 2026
bc7f5b1
Merge branch 'master' into d/20260406-164203
donald-pinckney Apr 13, 2026
024126d
Merge branch 'master' into d/20260406-164203
donald-pinckney Apr 16, 2026
bbcb85e
Remove TASK_QUEUE.json
donald-pinckney Apr 16, 2026
88910d6
Publish temporal-spring-ai from the JDK 11 release job via toolchains
donald-pinckney Apr 16, 2026
0fbfec4
Merge remote-tracking branch 'origin/master' into d/20260406-164203
donald-pinckney Apr 17, 2026
b6de0a7
Align markdown tables
donald-pinckney Apr 17, 2026
48780de
Skip temporal-spring-ai tests when testJavaVersion < 17
donald-pinckney Apr 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add temporal-spring-ai module for Spring AI integration
Adds a new module that integrates Spring AI with Temporal workflows,
enabling durable AI model calls, vector store operations, embeddings,
and MCP tool execution as Temporal activities.

Key components:
- ActivityChatModel: ChatModel implementation backed by activities
- TemporalChatClient: Temporal-aware ChatClient with tool detection
- SpringAiPlugin: Auto-registers Spring AI activities with workers
- Tool system: @DeterministicTool, @SideEffectTool, activity-backed tools
- MCP integration: ActivityMcpClient for durable MCP tool calls

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
  • Loading branch information
donald-pinckney and claude committed Apr 8, 2026
commit 4f4df9e5e6230e0d00121f898fdbb98208dc0a69
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ include 'temporal-testing'
include 'temporal-test-server'
include 'temporal-opentracing'
include 'temporal-kotlin'
include 'temporal-spring-ai'
include 'temporal-spring-boot-autoconfigure'
include 'temporal-spring-boot-starter'
include 'temporal-remote-data-encoder'
Expand Down
1 change: 1 addition & 0 deletions temporal-bom/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies {
api project(':temporal-sdk')
api project(':temporal-serviceclient')
api project(':temporal-shaded')
api project(':temporal-spring-ai')
api project(':temporal-spring-boot-autoconfigure')
api project(':temporal-spring-boot-starter')
api project(':temporal-test-server')
Expand Down
54 changes: 54 additions & 0 deletions temporal-spring-ai/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
description = '''Temporal Java SDK Spring AI Plugin'''

ext {
springAiVersion = '1.1.0'
Comment thread
donald-pinckney marked this conversation as resolved.
// Spring AI requires Spring Boot 3.x / Java 17+
springBootVersionForSpringAi = "$springBoot3Version"
}

// Spring AI requires Java 17+, override the default Java 8 target from java.gradle
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

compileJava {
options.compilerArgs.removeAll(['--release', '8'])
options.compilerArgs.addAll(['--release', '17'])
}

compileTestJava {
options.compilerArgs.removeAll(['--release', '8'])
options.compilerArgs.addAll(['--release', '17'])
}

dependencies {
api(platform("org.springframework.boot:spring-boot-dependencies:$springBootVersionForSpringAi"))
api(platform("org.springframework.ai:spring-ai-bom:$springAiVersion"))

// this module shouldn't carry temporal-sdk with it, especially for situations when users may be using a shaded artifact
compileOnly project(':temporal-sdk')
Comment thread
donald-pinckney marked this conversation as resolved.
compileOnly project(':temporal-spring-boot-autoconfigure')

api 'org.springframework.boot:spring-boot-autoconfigure'
api 'org.springframework.ai:spring-ai-client-chat'
Comment thread
brianstrauch marked this conversation as resolved.

implementation 'org.springframework.boot:spring-boot-starter'

// Optional: Vector store support
compileOnly 'org.springframework.ai:spring-ai-rag'

// Optional: MCP (Model Context Protocol) support
compileOnly 'org.springframework.ai:spring-ai-mcp'

testImplementation project(':temporal-sdk')
testImplementation project(':temporal-testing')
testImplementation "org.mockito:mockito-core:${mockitoVersion}"
testImplementation 'org.springframework.boot:spring-boot-starter-test'

testRuntimeOnly group: 'ch.qos.logback', name: 'logback-classic', version: "${logbackVersion}"
}

tasks.test {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.temporal.springai.activity;

import io.temporal.activity.ActivityInterface;
import io.temporal.activity.ActivityMethod;
import io.temporal.springai.model.ChatModelTypes;

/**
* Temporal activity interface for calling Spring AI chat models.
*
* <p>This activity wraps a Spring AI {@link org.springframework.ai.chat.model.ChatModel} and makes
* it callable from within Temporal workflows. The activity handles serialization of prompts and
* responses, enabling durable AI conversations with automatic retries and timeout handling.
*/
@ActivityInterface
public interface ChatModelActivity {

/**
* Calls the chat model with the given input.
*
* @param input the chat model input containing messages, options, and tool definitions
* @return the chat model output containing generated responses and metadata
*/
@ActivityMethod
ChatModelTypes.ChatModelActivityOutput callChatModel(ChatModelTypes.ChatModelActivityInput input);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,276 @@
package io.temporal.springai.activity;

import io.temporal.springai.model.ChatModelTypes;
import io.temporal.springai.model.ChatModelTypes.Message;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.springframework.ai.chat.messages.*;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.content.Media;
import org.springframework.ai.model.tool.ToolCallingChatOptions;
import org.springframework.ai.tool.ToolCallback;
import org.springframework.ai.tool.definition.ToolDefinition;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.util.CollectionUtils;
import org.springframework.util.MimeType;

/**
* Implementation of {@link ChatModelActivity} that delegates to a Spring AI {@link ChatModel}.
*
* <p>This implementation handles the conversion between Temporal-serializable types ({@link
* ChatModelTypes}) and Spring AI types.
*
* <p>Supports multiple chat models. The model to use is determined by the {@code modelName} field
* in the input. If no model name is specified, the default model is used.
*/
public class ChatModelActivityImpl implements ChatModelActivity {

private final Map<String, ChatModel> chatModels;
private final String defaultModelName;

/**
* Creates an activity implementation with a single chat model.
*
* @param chatModel the chat model to use
*/
public ChatModelActivityImpl(ChatModel chatModel) {
this.chatModels = Map.of("default", chatModel);
this.defaultModelName = "default";
}

/**
* Creates an activity implementation with multiple chat models.
*
* @param chatModels map of model names to chat models
* @param defaultModelName the name of the default model to use when none is specified
*/
public ChatModelActivityImpl(Map<String, ChatModel> chatModels, String defaultModelName) {
this.chatModels = chatModels;
this.defaultModelName = defaultModelName;
}

@Override
public ChatModelTypes.ChatModelActivityOutput callChatModel(
ChatModelTypes.ChatModelActivityInput input) {
ChatModel chatModel = resolveChatModel(input.modelName());
Prompt prompt = createPrompt(input);
ChatResponse response = chatModel.call(prompt);
return toOutput(response);
}

private ChatModel resolveChatModel(String modelName) {
String name = (modelName != null && !modelName.isEmpty()) ? modelName : defaultModelName;
ChatModel model = chatModels.get(name);
if (model == null) {
throw new IllegalArgumentException(
"No chat model with name '" + name + "'. Available models: " + chatModels.keySet());
}
return model;
}

private Prompt createPrompt(ChatModelTypes.ChatModelActivityInput input) {
List<org.springframework.ai.chat.messages.Message> messages =
input.messages().stream().map(this::toSpringMessage).collect(Collectors.toList());

ToolCallingChatOptions.Builder optionsBuilder =
ToolCallingChatOptions.builder()
.internalToolExecutionEnabled(false); // Let workflow handle tool execution

if (input.modelOptions() != null) {
ChatModelTypes.ModelOptions opts = input.modelOptions();
if (opts.model() != null) optionsBuilder.model(opts.model());
if (opts.temperature() != null) optionsBuilder.temperature(opts.temperature());
if (opts.maxTokens() != null) optionsBuilder.maxTokens(opts.maxTokens());
if (opts.topP() != null) optionsBuilder.topP(opts.topP());
if (opts.topK() != null) optionsBuilder.topK(opts.topK());
if (opts.frequencyPenalty() != null) optionsBuilder.frequencyPenalty(opts.frequencyPenalty());
if (opts.presencePenalty() != null) optionsBuilder.presencePenalty(opts.presencePenalty());
if (opts.stopSequences() != null) optionsBuilder.stopSequences(opts.stopSequences());
}

// Add tool callbacks (stubs that provide definitions but won't be executed
// since internalToolExecutionEnabled is false)
if (!CollectionUtils.isEmpty(input.tools())) {
List<ToolCallback> toolCallbacks =
input.tools().stream()
.map(
tool ->
createStubToolCallback(
tool.function().name(),
tool.function().description(),
tool.function().jsonSchema()))
.collect(Collectors.toList());
optionsBuilder.toolCallbacks(toolCallbacks);
}

ToolCallingChatOptions chatOptions = optionsBuilder.build();

return Prompt.builder().messages(messages).chatOptions(chatOptions).build();
}

private org.springframework.ai.chat.messages.Message toSpringMessage(Message message) {
return switch (message.role()) {
case SYSTEM -> new SystemMessage((String) message.rawContent());
case USER -> {
UserMessage.Builder builder = UserMessage.builder().text((String) message.rawContent());
if (!CollectionUtils.isEmpty(message.mediaContents())) {
builder.media(
message.mediaContents().stream().map(this::toMedia).collect(Collectors.toList()));
}
yield builder.build();
}
case ASSISTANT ->
AssistantMessage.builder()
.content((String) message.rawContent())
.properties(Map.of())
.toolCalls(
message.toolCalls() != null
? message.toolCalls().stream()
.map(
tc ->
new AssistantMessage.ToolCall(
tc.id(),
tc.type(),
tc.function().name(),
tc.function().arguments()))
.collect(Collectors.toList())
: List.of())
.media(
message.mediaContents() != null
? message.mediaContents().stream()
.map(this::toMedia)
.collect(Collectors.toList())
: List.of())
.build();
case TOOL ->
ToolResponseMessage.builder()
.responses(
List.of(
new ToolResponseMessage.ToolResponse(
message.toolCallId(), message.name(), (String) message.rawContent())))
.build();
};
}

private Media toMedia(ChatModelTypes.MediaContent mediaContent) {
MimeType mimeType = MimeType.valueOf(mediaContent.mimeType());
if (mediaContent.uri() != null) {
try {
return new Media(mimeType, new URI(mediaContent.uri()));
} catch (URISyntaxException e) {
throw new RuntimeException("Invalid media URI: " + mediaContent.uri(), e);
}
} else if (mediaContent.data() != null) {
return new Media(mimeType, new ByteArrayResource(mediaContent.data()));
}
throw new IllegalArgumentException("Media content must have either uri or data");
}

private ChatModelTypes.ChatModelActivityOutput toOutput(ChatResponse response) {
List<ChatModelTypes.ChatModelActivityOutput.Generation> generations =
response.getResults().stream()
.map(
gen ->
new ChatModelTypes.ChatModelActivityOutput.Generation(
fromAssistantMessage(gen.getOutput())))
.collect(Collectors.toList());

ChatModelTypes.ChatModelActivityOutput.ChatResponseMetadata metadata = null;
if (response.getMetadata() != null) {
var rateLimit = response.getMetadata().getRateLimit();
var usage = response.getMetadata().getUsage();

metadata =
new ChatModelTypes.ChatModelActivityOutput.ChatResponseMetadata(
response.getMetadata().getModel(),
rateLimit != null
? new ChatModelTypes.ChatModelActivityOutput.ChatResponseMetadata.RateLimit(
rateLimit.getRequestsLimit(),
rateLimit.getRequestsRemaining(),
rateLimit.getRequestsReset(),
rateLimit.getTokensLimit(),
rateLimit.getTokensRemaining(),
rateLimit.getTokensReset())
: null,
usage != null
? new ChatModelTypes.ChatModelActivityOutput.ChatResponseMetadata.Usage(
usage.getPromptTokens() != null ? usage.getPromptTokens().intValue() : null,
usage.getCompletionTokens() != null
? usage.getCompletionTokens().intValue()
: null,
usage.getTotalTokens() != null ? usage.getTotalTokens().intValue() : null)
: null);
}

return new ChatModelTypes.ChatModelActivityOutput(generations, metadata);
}

private Message fromAssistantMessage(AssistantMessage assistantMessage) {
List<Message.ToolCall> toolCalls = null;
if (!CollectionUtils.isEmpty(assistantMessage.getToolCalls())) {
toolCalls =
assistantMessage.getToolCalls().stream()
.map(
tc ->
new Message.ToolCall(
tc.id(),
tc.type(),
new Message.ChatCompletionFunction(tc.name(), tc.arguments())))
.collect(Collectors.toList());
}

List<ChatModelTypes.MediaContent> mediaContents = null;
if (!CollectionUtils.isEmpty(assistantMessage.getMedia())) {
mediaContents =
assistantMessage.getMedia().stream().map(this::fromMedia).collect(Collectors.toList());
}

return new Message(
assistantMessage.getText(), Message.Role.ASSISTANT, null, null, toolCalls, mediaContents);
}

private ChatModelTypes.MediaContent fromMedia(Media media) {
String mimeType = media.getMimeType().toString();
if (media.getData() instanceof String uri) {
return new ChatModelTypes.MediaContent(mimeType, uri);
} else if (media.getData() instanceof byte[] data) {
return new ChatModelTypes.MediaContent(mimeType, data);
}
throw new IllegalArgumentException(
"Unsupported media data type: " + media.getData().getClass());
}

/**
* Creates a stub ToolCallback that provides a tool definition but throws if called. This is used
* because Spring AI's ChatModel API requires ToolCallbacks, but we only need to inform the model
* about available tools - actual execution happens in the workflow (since
* internalToolExecutionEnabled is false).
*/
private ToolCallback createStubToolCallback(String name, String description, String inputSchema) {
ToolDefinition toolDefinition =
ToolDefinition.builder()
.name(name)
.description(description)
.inputSchema(inputSchema)
.build();

return new ToolCallback() {
@Override
public ToolDefinition getToolDefinition() {
return toolDefinition;
}

@Override
public String call(String toolInput) {
throw new UnsupportedOperationException(
"Tool execution should be handled by the workflow, not the activity. "
+ "Ensure internalToolExecutionEnabled is set to false.");
}
};
}
}
Loading