Skip to content

Commit 7e7e5ad

Browse files
Update README with tool execution model
Document the three tool types: activity stubs (auto-detected), @SideEffectTool (wrapped in sideEffect), and plain tools (execute in workflow context, user responsible for determinism). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f0d0f9a commit 7e7e5ad

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

temporal-spring-ai/README.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@ The plugin auto-registers `ChatModelActivity` with all Temporal workers. In your
3131
@WorkflowInit
3232
public MyWorkflowImpl(String goal) {
3333
ActivityChatModel chatModel = ActivityChatModel.forDefault();
34+
35+
WeatherActivity weather = Workflow.newActivityStub(WeatherActivity.class, opts);
36+
3437
this.chatClient = TemporalChatClient.builder(chatModel)
3538
.defaultSystem("You are a helpful assistant.")
36-
.defaultTools(myActivityStub)
39+
.defaultTools(weather, new MyTools())
3740
.build();
3841
}
3942

@@ -43,6 +46,52 @@ public String run(String goal) {
4346
}
4447
```
4548

49+
## Tool Types
50+
51+
Tools passed to `defaultTools()` are handled based on their type:
52+
53+
### Activity stubs
54+
55+
Interfaces annotated with both `@ActivityInterface` and `@Tool` methods. Auto-detected and executed as durable Temporal activities with retries and timeouts.
56+
57+
```java
58+
@ActivityInterface
59+
public interface WeatherActivity {
60+
@Tool(description = "Get weather for a city") @ActivityMethod
61+
String getWeather(String city);
62+
}
63+
```
64+
65+
### `@SideEffectTool`
66+
67+
Classes annotated with `@SideEffectTool`. Each `@Tool` method is wrapped in `Workflow.sideEffect()` — the result is recorded in history on first execution and replayed from history on subsequent replays. Use for cheap non-deterministic operations (timestamps, UUIDs).
68+
69+
```java
70+
@SideEffectTool
71+
public class TimestampTools {
72+
@Tool(description = "Get current time")
73+
public String now() { return Instant.now().toString(); }
74+
}
75+
```
76+
77+
### Plain tools
78+
79+
Any class with `@Tool` methods that isn't a stub or `@SideEffectTool`. Executes directly in the workflow thread. The user is responsible for determinism — call activities, `Workflow.sideEffect()`, child workflows, etc. as needed.
80+
81+
```java
82+
public class MyTools {
83+
@Tool(description = "Process data")
84+
public String process(String input) {
85+
SomeActivity act = Workflow.newActivityStub(SomeActivity.class, opts);
86+
return act.doWork(input);
87+
}
88+
}
89+
```
90+
91+
### Nexus service stubs
92+
93+
Auto-detected and executed as Nexus operations, similar to activity stubs.
94+
4695
## Optional Integrations
4796

4897
These are auto-configured when their dependencies are on the classpath:

0 commit comments

Comments
 (0)