-
Notifications
You must be signed in to change notification settings - Fork 314
Add Spring AI integration documentation for Java SDK #4454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
40a5146
Add Spring AI integration documentation for Java SDK
donald-pinckney 2dc8343
Update Temporal Java SDK version to 1.35.0
donald-pinckney b0a6398
clarify public preview
donald-pinckney 49df59c
Edit streaming
donald-pinckney 8e5f4ea
edit plain tools
donald-pinckney b9edcf2
spring-ai docs: cover activity options, provider passthrough, media cap
donald-pinckney 45fe400
spring-ai docs: lead with agents, honor workflow-side tools
donald-pinckney 658eb2f
spring-ai docs: replace inline code with snipsync placeholders
donald-pinckney 6b743b2
Merge branch 'main' into docs/spring-ai-integration
donald-pinckney a27d432
edits
donald-pinckney 9811114
Merge branch 'main' into docs/spring-ai-integration
donald-pinckney e3d96c3
Update docs/develop/java/integrations/spring-ai.mdx
donald-pinckney 6467e2d
Update docs/develop/java/integrations/spring-ai.mdx
donald-pinckney a0360ea
Update docs/develop/java/integrations/spring-ai.mdx
donald-pinckney be1dad4
Rename Compatibility section to Prerequisites and clarify requirements
donald-pinckney e1e86ae
Explain tool registration and link to Spring AI tools docs
donald-pinckney 789c629
Cross-link heartbeats and priority docs in ActivityOptions guidance
donald-pinckney d20392a
Merge branch 'main' into docs/spring-ai-integration
donald-pinckney File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| --- | ||
| id: spring-ai | ||
| title: Spring AI integration - Java SDK | ||
| sidebar_label: Spring AI | ||
| slug: /develop/java/integrations/spring-ai | ||
| toc_max_heading_level: 2 | ||
| keywords: | ||
| - ai | ||
| - agents | ||
| - spring ai | ||
| - java | ||
| - integrations | ||
| tags: | ||
| - Spring AI | ||
| - Java SDK | ||
| - Temporal SDKs | ||
| - Integrations | ||
| - AI Frameworks | ||
| description: Build durable AI Workflows in Java with the Temporal Spring AI integration. | ||
| --- | ||
|
|
||
| The [Temporal Spring AI integration](https://central.sonatype.com/artifact/io.temporal/temporal-spring-ai) lets you call [Spring AI](https://docs.spring.io/spring-ai/reference/) models, tools, vector stores, embeddings, and MCP servers from Temporal Workflows as durable Activities. Model calls and tool invocations are recorded in Workflow history, so they retry on failure and replay deterministically — without you having to change how you write Spring AI code. | ||
|
donald-pinckney marked this conversation as resolved.
Outdated
|
||
|
|
||
| The integration is built on the Temporal Java SDK's [Plugin system](/develop/plugins-guide) and is distributed as the `io.temporal:temporal-spring-ai` module alongside the existing [Spring Boot integration](/develop/java/integrations/spring-boot-integration). | ||
|
|
||
| ## Compatibility | ||
|
donald-pinckney marked this conversation as resolved.
Outdated
|
||
|
|
||
| | Dependency | Minimum version | | ||
| | ----------------- | --------------- | | ||
| | Java | 17 | | ||
| | Spring Boot | 3.x | | ||
| | Spring AI | 1.1.0 | | ||
| | Temporal Java SDK | 1.35.0 | | ||
|
donald-pinckney marked this conversation as resolved.
|
||
|
|
||
| ## Add the dependency | ||
|
|
||
| Add `temporal-spring-ai` alongside `temporal-spring-boot-starter` and a Spring AI model starter (for example, `spring-ai-starter-model-openai`). | ||
|
|
||
| **[Apache Maven](https://maven.apache.org/):** | ||
|
|
||
| ```xml | ||
| <dependency> | ||
| <groupId>io.temporal</groupId> | ||
| <artifactId>temporal-spring-ai</artifactId> | ||
| <version>${temporal-sdk.version}</version> | ||
| </dependency> | ||
| ``` | ||
|
|
||
| **[Gradle Groovy DSL](https://gradle.org/):** | ||
|
|
||
| ```groovy | ||
| implementation "io.temporal:temporal-spring-ai:${temporalSdkVersion}" | ||
| ``` | ||
|
|
||
| When `temporal-spring-ai` is on the classpath, the `SpringAiPlugin` auto-registers `ChatModelActivity` with all Temporal Workers created by the Spring Boot integration. Optional Activities are auto-configured when their dependencies are present: | ||
|
|
||
| | Feature | Dependency | Registered Activity | | ||
| | ------------ | --------------- | ------------------------ | | ||
| | Vector store | `spring-ai-rag` | `VectorStoreActivity` | | ||
| | Embeddings | `spring-ai-rag` | `EmbeddingModelActivity` | | ||
| | MCP | `spring-ai-mcp` | `McpClientActivity` | | ||
|
|
||
| ## Call a chat model from a Workflow | ||
|
|
||
| Use `ActivityChatModel` as a Spring AI `ChatModel` inside a Workflow. Every call goes through a Temporal Activity, so model responses are durable and retried per your Activity options. | ||
|
|
||
| Wrap `ActivityChatModel` in a `TemporalChatClient` to build prompts and register tools: | ||
|
|
||
| ```java | ||
|
donald-pinckney marked this conversation as resolved.
|
||
| @WorkflowInit | ||
| public MyWorkflowImpl(String goal) { | ||
| ActivityChatModel chatModel = ActivityChatModel.forDefault(); | ||
|
|
||
| WeatherActivity weather = Workflow.newActivityStub( | ||
| WeatherActivity.class, activityOptions); | ||
|
|
||
| this.chatClient = TemporalChatClient.builder(chatModel) | ||
| .defaultSystem("You are a helpful assistant.") | ||
| .defaultTools(weather, new TimestampTools()) | ||
| .build(); | ||
| } | ||
|
|
||
| @Override | ||
| public String run(String goal) { | ||
| return chatClient.prompt().user(goal).call().content(); | ||
| } | ||
| ``` | ||
|
|
||
| `ActivityChatModel.forDefault()` resolves to the default Spring AI `ChatModel` bean. To target a specific model in a multi-model application, pass its bean name to `ActivityChatModel.forModel("openai")`. | ||
|
|
||
| :::note | ||
|
donald-pinckney marked this conversation as resolved.
|
||
| Streaming responses are not supported. `ActivityChatModel.stream()` throws `UnsupportedOperationException` because streaming through Temporal Activities isn't a durable operation. | ||
| ::: | ||
|
|
||
| ## Register tools | ||
|
donald-pinckney marked this conversation as resolved.
|
||
|
|
||
| Tools passed to `defaultTools()` are dispatched based on their type. The integration handles Temporal determinism for you when the tool is durable, and gives you control when it isn't. | ||
|
|
||
| ### Activity stubs | ||
|
|
||
| An interface annotated with both `@ActivityInterface` and Spring AI `@Tool` methods is auto-detected and executed as a Temporal Activity. Use this for external calls that need retries and timeouts. | ||
|
|
||
| ```java | ||
| @ActivityInterface | ||
| public interface WeatherActivity { | ||
| @Tool(description = "Get weather for a city") | ||
| @ActivityMethod | ||
| String getWeather(String city); | ||
| } | ||
| ``` | ||
|
|
||
| ### Nexus service stubs | ||
|
|
||
| Nexus service stubs with `@Tool` methods are auto-detected and invoked as [Nexus operations](/develop/java/nexus), enabling cross-Namespace tool calls. | ||
|
|
||
| ### `@SideEffectTool` | ||
|
|
||
| Classes annotated with `@SideEffectTool` have each `@Tool` method wrapped in `Workflow.sideEffect()`. The result is recorded in history on first execution and replayed from history afterward. Use this for cheap, non-deterministic operations such as timestamps or UUIDs. | ||
|
|
||
| ```java | ||
| @SideEffectTool | ||
| public class TimestampTools { | ||
| @Tool(description = "Get current time") | ||
| public String now() { | ||
| return Instant.now().toString(); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### Plain tools | ||
|
|
||
| Any class with `@Tool` methods that isn't an Activity stub, Nexus stub, or `@SideEffectTool` runs directly on the Workflow thread. You're responsible for determinism — call Activities, `Workflow.sideEffect()`, child Workflows, or other durable primitives as needed. | ||
|
|
||
| ```java | ||
| public class MyTools { | ||
| @Tool(description = "Process data") | ||
| public String process(String input) { | ||
| SomeActivity act = Workflow.newActivityStub(SomeActivity.class, opts); | ||
| return act.doWork(input); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Use vector stores, embeddings, and MCP | ||
|
|
||
| When the corresponding Spring AI modules are on the classpath, the integration registers Activities for vector stores, embeddings, and MCP tool calls. Inject the matching Spring AI types into your Activities or Workflows and use them as you would in any Spring AI application — each operation is executed through a Temporal Activity. | ||
|
|
||
| You can also register these plugins explicitly, without relying on auto-configuration: | ||
|
|
||
| ```java | ||
| new VectorStorePlugin(vectorStore); | ||
| new EmbeddingModelPlugin(embeddingModel); | ||
| new McpPlugin(); | ||
| ``` | ||
|
|
||
| `ActivityMcpClient` wraps a Spring AI MCP client so that remote MCP tool calls become durable Activity executions. | ||
|
|
||
| ## Learn more | ||
|
donald-pinckney marked this conversation as resolved.
Outdated
|
||
|
|
||
| - [`temporal-spring-ai` README](https://github.com/temporalio/sdk-java/blob/master/temporal-spring-ai/README.md) — full reference for the module | ||
| - [Spring Boot integration](/develop/java/integrations/spring-boot-integration) — required companion module | ||
| - [Plugin system](/develop/plugins-guide) — how integrations are registered with Workers and Clients | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.