Skip to content

Commit 392693c

Browse files
committed
Add HITL Use Cases; Fix DSL Event Consumption
Signed-off-by: Ricardo Zanini <[email protected]>
1 parent a14cc21 commit 392693c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1285
-399
lines changed

experimental/lambda/src/test/java/io/serverless/workflow/impl/FluentDSLCallTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ void testSwitch() throws InterruptedException, ExecutionException {
8282
tasks
8383
.switchCase(
8484
switchOdd ->
85-
switchOdd.functions(
85+
switchOdd.onPredicate(
8686
item ->
8787
item.when(CallTest::isOdd).then(FlowDirectiveEnum.END)))
8888
.callFn(callJava -> callJava.function(CallTest::zero)))
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.api.types.func;
17+
18+
import io.serverlessworkflow.api.types.EventData;
19+
import java.util.Objects;
20+
import java.util.function.Function;
21+
22+
public class EventDataFunction extends EventData {
23+
24+
public <T, R> EventData withFunction(Function<T, R> value) {
25+
setObject(value);
26+
return this;
27+
}
28+
29+
public <T, R> EventData withFunction(Function<T, R> value, Class<T> argClass) {
30+
Objects.requireNonNull(argClass);
31+
setObject(new TypedFunction<>(value, argClass));
32+
return this;
33+
}
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.api.types.func;
17+
18+
import io.serverlessworkflow.api.types.EventData;
19+
import java.util.Objects;
20+
import java.util.function.Predicate;
21+
22+
public class EventDataPredicate extends EventData {
23+
24+
public <T> EventDataPredicate withPredicate(Predicate<T> predicate) {
25+
setObject(predicate);
26+
return this;
27+
}
28+
29+
public <T> EventDataPredicate withPredicate(Predicate<T> predicate, Class<T> clazz) {
30+
Objects.requireNonNull(clazz);
31+
setObject(new TypedPredicate<>(predicate, clazz));
32+
return this;
33+
}
34+
}

fluent/agentic/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@
5757
<artifactId>serverlessworkflow-experimental-agentic</artifactId>
5858
<scope>test</scope>
5959
</dependency>
60+
<dependency>
61+
<groupId>io.cloudevents</groupId>
62+
<artifactId>cloudevents-json-jackson</artifactId>
63+
<scope>test</scope>
64+
</dependency>
65+
<dependency>
66+
<groupId>io.serverlessworkflow</groupId>
67+
<artifactId>serverlessworkflow-impl-jackson</artifactId>
68+
<version>${project.version}</version>
69+
</dependency>
6070
</dependencies>
6171

6272
<build>

fluent/agentic/src/main/java/io/serverlessworkflow/fluent/agentic/AgentListenTaskBuilder.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,31 @@
1818
import io.serverlessworkflow.api.types.AnyEventConsumptionStrategy;
1919
import io.serverlessworkflow.api.types.ListenTask;
2020
import io.serverlessworkflow.api.types.func.UntilPredicate;
21-
import io.serverlessworkflow.fluent.spec.ListenTaskBuilder;
21+
import io.serverlessworkflow.fluent.func.FuncListenToBuilder;
22+
import io.serverlessworkflow.fluent.func.spi.ConditionalTaskBuilder;
23+
import io.serverlessworkflow.fluent.spec.AbstractListenTaskBuilder;
2224
import java.util.function.Predicate;
2325

24-
public class AgentListenTaskBuilder extends ListenTaskBuilder<AgentTaskItemListBuilder> {
26+
public class AgentListenTaskBuilder
27+
extends AbstractListenTaskBuilder<AgentTaskItemListBuilder, FuncListenToBuilder>
28+
implements ConditionalTaskBuilder<AgentListenTaskBuilder> {
2529

2630
private UntilPredicate untilPredicate;
2731

2832
public AgentListenTaskBuilder() {
2933
super(new AgentTaskItemListBuilder());
3034
}
3135

36+
@Override
37+
protected AgentListenTaskBuilder self() {
38+
return this;
39+
}
40+
41+
@Override
42+
protected FuncListenToBuilder newEventConsumptionStrategyBuilder() {
43+
return new FuncListenToBuilder();
44+
}
45+
3246
public <T> AgentListenTaskBuilder until(Predicate<T> predicate, Class<T> predClass) {
3347
untilPredicate = new UntilPredicate().withPredicate(predicate, predClass);
3448
return this;

fluent/agentic/src/test/java/io/serverlessworkflow/fluent/agentic/Agents.java

Lines changed: 103 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ public interface Agents {
2626
interface ChatBot {
2727
@UserMessage(
2828
"""
29-
You are a happy chat bot, reply to my message:
30-
{{userInput}}.
31-
""")
29+
You are a happy chat bot, reply to my message:
30+
{{userInput}}.
31+
""")
3232
@Agent
3333
String chat(@V("userInput") String userInput);
3434
}
@@ -37,11 +37,11 @@ interface MovieExpert {
3737

3838
@UserMessage(
3939
"""
40-
You are a great evening planner.
41-
Propose a list of 3 movies matching the given mood.
42-
The mood is {{mood}}.
43-
Provide a list with the 3 items and nothing else.
44-
""")
40+
You are a great evening planner.
41+
Propose a list of 3 movies matching the given mood.
42+
The mood is {{mood}}.
43+
Provide a list with the 3 items and nothing else.
44+
""")
4545
@Agent
4646
List<String> findMovie(@V("mood") String mood);
4747
}
@@ -50,10 +50,10 @@ interface SettingAgent extends AgentSpecification {
5050

5151
@UserMessage(
5252
"""
53-
Create a vivid {{style}} setting. It should include the time period, the state of technology,
54-
key locations, and a brief description of the world’s political or social situation.
55-
Make it imaginative, atmospheric, and suitable for a {{style}} novel.
56-
""")
53+
Create a vivid {{style}} setting. It should include the time period, the state of technology,
54+
key locations, and a brief description of the world’s political or social situation.
55+
Make it imaginative, atmospheric, and suitable for a {{style}} novel.
56+
""")
5757
@Agent(
5858
"Generates an imaginative setting including timeline, technology level, and world structure")
5959
String invoke(@V("style") String style);
@@ -63,9 +63,9 @@ interface HeroAgent extends AgentSpecification {
6363

6464
@UserMessage(
6565
"""
66-
Invent a compelling protagonist for a {{style}} story. Describe their background, personality,
67-
motivations, and any unique skills or traits.
68-
""")
66+
Invent a compelling protagonist for a {{style}} story. Describe their background, personality,
67+
motivations, and any unique skills or traits.
68+
""")
6969
@Agent("Creates a unique and relatable protagonist with rich backstory and motivations.")
7070
String invoke(@V("style") String style);
7171
}
@@ -74,10 +74,10 @@ interface ConflictAgent extends AgentSpecification {
7474

7575
@UserMessage(
7676
"""
77-
Generate a central conflict or threat for a {{style}} plot. It can be external or
78-
internal (e.g. moral dilemma, personal transformation).
79-
Make it high-stakes and thematically rich.
80-
""")
77+
Generate a central conflict or threat for a {{style}} plot. It can be external or
78+
internal (e.g. moral dilemma, personal transformation).
79+
Make it high-stakes and thematically rich.
80+
""")
8181
@Agent("Proposes a central conflict or dramatic tension to drive a compelling narrative.")
8282
String invoke(@V("style") String style);
8383
}
@@ -86,8 +86,8 @@ interface FactAgent extends AgentSpecification {
8686

8787
@UserMessage(
8888
"""
89-
Generate a unique sci-fi fact about an alien civilization's {{goal}} environment or evolutionary history. Make it imaginative and specific.
90-
""")
89+
Generate a unique sci-fi fact about an alien civilization's {{goal}} environment or evolutionary history. Make it imaginative and specific.
90+
""")
9191
@Agent("Generates a core fact that defines the foundation of an civilization.")
9292
String invoke(@V("fact") String fact);
9393
}
@@ -96,10 +96,10 @@ interface CultureAgent extends AgentSpecification {
9696

9797
@UserMessage(
9898
"""
99-
Given the following sci-fi fact about an civilization, describe 3–5 unique cultural traits, traditions, or societal structures that naturally emerge from this environment.
100-
Fact:
101-
{{fact}}
102-
""")
99+
Given the following sci-fi fact about an civilization, describe 3–5 unique cultural traits, traditions, or societal structures that naturally emerge from this environment.
100+
Fact:
101+
{{fact}}
102+
""")
103103
@Agent("Derives cultural traits from the environmental/evolutionary fact.")
104104
List<String> invoke(@V("fact") String fact);
105105
}
@@ -108,10 +108,10 @@ interface TechnologyAgent extends AgentSpecification {
108108

109109
@UserMessage(
110110
"""
111-
Given the following sci-fi fact about an alien civilization, describe 3–5 technologies or engineering solutions they might have developed. Focus on tools, transportation, communication, and survival systems.
112-
Fact:
113-
{{fact}}
114-
""")
111+
Given the following sci-fi fact about an alien civilization, describe 3–5 technologies or engineering solutions they might have developed. Focus on tools, transportation, communication, and survival systems.
112+
Fact:
113+
{{fact}}
114+
""")
115115
@Agent("Derives plausible technological inventions from the fact.")
116116
List<String> invoke(@V("fact") String fact);
117117
}
@@ -120,9 +120,9 @@ interface StorySeedAgent extends AgentSpecification {
120120

121121
@UserMessage(
122122
"""
123-
You are a science fiction writer. Given the following title, come up with a short story premise. Describe the world, the central concept, and the thematic direction (e.g., dystopia, exploration, AI ethics).
124-
Title: {{title}}
125-
""")
123+
You are a science fiction writer. Given the following title, come up with a short story premise. Describe the world, the central concept, and the thematic direction (e.g., dystopia, exploration, AI ethics).
124+
Title: {{title}}
125+
""")
126126
@Agent("Generates a high-level sci-fi premise based on a title.")
127127
String invoke(@V("title") String title);
128128
}
@@ -131,10 +131,10 @@ interface PlotAgent extends AgentSpecification {
131131

132132
@UserMessage(
133133
"""
134-
Using the following premise, outline a three-act structure for a science fiction short story. Include a brief description of the main character, the inciting incident, the rising conflict, and the resolution.
135-
Premise:
136-
{{premise}}
137-
""")
134+
Using the following premise, outline a three-act structure for a science fiction short story. Include a brief description of the main character, the inciting incident, the rising conflict, and the resolution.
135+
Premise:
136+
{{premise}}
137+
""")
138138
@Agent("Transforms a premise into a structured sci-fi plot.")
139139
String invoke(@V("premise") String premise);
140140
}
@@ -143,10 +143,10 @@ interface SceneAgent extends AgentSpecification {
143143

144144
@UserMessage(
145145
"""
146-
Write the opening scene of a science fiction short story based on the following plot outline. Introduce the main character and immerse the reader in the setting. Use vivid, cinematic language.
147-
Plot:
148-
{{plot}}
149-
""")
146+
Write the opening scene of a science fiction short story based on the following plot outline. Introduce the main character and immerse the reader in the setting. Use vivid, cinematic language.
147+
Plot:
148+
{{plot}}
149+
""")
150150
@Agent("Generates the opening scene of the story from a plot outline.")
151151
String invoke(@V("plot") String plot);
152152
}
@@ -155,13 +155,13 @@ interface MeetingInvitationDraft extends AgentSpecification {
155155

156156
@UserMessage(
157157
"""
158-
You are a professional meeting invitation writer. Draft a concise and clear meeting invitation email based on the following details:
159-
Subject: {{subject}}
160-
Date: {{date}}
161-
Time: {{time}}
162-
Location: {{location}}
163-
Agenda: {{agenda}}
164-
""")
158+
You are a professional meeting invitation writer. Draft a concise and clear meeting invitation email based on the following details:
159+
Subject: {{subject}}
160+
Date: {{date}}
161+
Time: {{time}}
162+
Location: {{location}}
163+
Agenda: {{agenda}}
164+
""")
165165
@Agent("Drafts a professional meeting invitation email.")
166166
String invoke(
167167
@V("subject") String subject,
@@ -175,10 +175,63 @@ interface MeetingInvitationStyle extends AgentSpecification {
175175

176176
@UserMessage(
177177
"""
178-
You are a professional meeting invitation writer. Rewrite the following meeting invitation email to better fit the {{style}} style:
179-
Original Invitation: {{invitation}}
180-
""")
178+
You are a professional meeting invitation writer. Rewrite the following meeting invitation email to better fit the {{style}} style:
179+
Original Invitation: {{invitation}}
180+
""")
181181
@Agent("Edits a meeting invitation email to better fit a given style.")
182182
String invoke(@V("invitation") String invitation, @V("style") String style);
183183
}
184+
185+
interface EmailDrafter {
186+
187+
@UserMessage(
188+
"""
189+
You are a precise email drafting assistant.
190+
191+
GOAL
192+
- Draft a professional email that achieves the stated purpose.
193+
- Keep it concise and skimmable.
194+
195+
INPUT
196+
recipient_name: {{recipientName}}
197+
sender_name: {{senderName}}
198+
purpose: {{purpose}} // e.g., follow-up, scheduling, proposal, apology, onboarding
199+
key_points: {{keyPoints}} // bullet list or comma-separated facts
200+
tone: {{tone}} // e.g., friendly, neutral, formal
201+
length: {{length}} // short|medium
202+
call_to_action: {{cta}} // e.g., "reply with a time", "confirm receipt", or empty
203+
signature: {{signature}} // prebuilt block; do NOT invent
204+
allowed_domains: {{allowedDomains}} // e.g., ["acme.com","example.com"]
205+
known_links: {{links}} // URLs you may use; if not in allowed_domains, do not include
206+
207+
HARD RULES
208+
- Never fabricate facts, prices, or promises.
209+
- Only include links from allowed_domains and only those listed in known_links.
210+
- Do not include internal/confidential URLs.
211+
- If you lack a detail, write a neutral placeholder (e.g., "[DATE]").
212+
- Keep subject <= 60 characters if possible.
213+
- One clear CTA max.
214+
215+
OUTPUT
216+
Return ONLY a compact JSON object with keys:
217+
{
218+
"subject": "...",
219+
"body_plain": "...",
220+
"links": ["..."] // subset of known_links, or empty
221+
}
222+
No markdown, no explanations, no extra text.
223+
""")
224+
@Agent("Drafts a new outbound email from structured inputs; returns JSON.")
225+
String draftNew(
226+
@V("recipientName") String recipientName,
227+
@V("senderName") String senderName,
228+
@V("purpose") String purpose,
229+
@V("keyPoints") List<String> keyPoints,
230+
@V("tone") String tone,
231+
@V("length") String length,
232+
@V("cta") String cta,
233+
@V("signature") String signature,
234+
@V("allowedDomains") List<String> allowedDomains,
235+
@V("links") List<String> links);
236+
}
184237
}

0 commit comments

Comments
 (0)