Skip to content

Commit 94f41da

Browse files
authored
Agentic workflow examples (#808)
* Add loop with maxIterations to the AgenticDSL Signed-off-by: Dmitrii Tikhomirov <[email protected]> * Agentic workflow examples Signed-off-by: Dmitrii Tikhomirov <[email protected]> * more examples Signed-off-by: Dmitrii Tikhomirov <[email protected]> * more examples Signed-off-by: Dmitrii Tikhomirov <[email protected]> * added README.md Signed-off-by: Dmitrii Tikhomirov <[email protected]> * post review Signed-off-by: Dmitrii Tikhomirov <[email protected]> * updated sequence demo Signed-off-by: Dmitrii Tikhomirov <[email protected]> --------- Signed-off-by: Dmitrii Tikhomirov <[email protected]>
1 parent 2580ea8 commit 94f41da

File tree

4 files changed

+828
-0
lines changed

4 files changed

+828
-0
lines changed

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

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
*/
1616
package io.serverlessworkflow.fluent.agentic;
1717

18+
import dev.langchain4j.agent.tool.Tool;
1819
import dev.langchain4j.agentic.Agent;
1920
import dev.langchain4j.agentic.internal.AgentSpecification;
21+
import dev.langchain4j.service.SystemMessage;
2022
import dev.langchain4j.service.UserMessage;
2123
import dev.langchain4j.service.V;
2224
import java.util.List;
@@ -234,4 +236,143 @@ String draftNew(
234236
@V("allowedDomains") List<String> allowedDomains,
235237
@V("links") List<String> links);
236238
}
239+
240+
interface CreativeWriter {
241+
242+
@UserMessage(
243+
"""
244+
You are a creative writer.
245+
Generate a draft of a story no more than
246+
3 sentences long around the given topic.
247+
Return only the story and nothing else.
248+
The topic is {{topic}}.
249+
""")
250+
@Agent("Generates a story based on the given topic")
251+
String generateStory(@V("topic") String topic);
252+
}
253+
254+
interface AudienceEditor {
255+
256+
@UserMessage(
257+
"""
258+
You are a professional editor.
259+
Analyze and rewrite the following story to better align
260+
with the target audience of {{audience}}.
261+
Return only the story and nothing else.
262+
The story is "{{story}}".
263+
""")
264+
@Agent("Edits a story to better fit a given audience")
265+
String editStory(@V("story") String story, @V("audience") String audience);
266+
}
267+
268+
interface StyleEditor {
269+
270+
@UserMessage(
271+
"""
272+
You are a professional editor.
273+
Analyze and rewrite the following story to better fit and be more coherent with the {{style}} style.
274+
Return only the story and nothing else.
275+
The story is "{{story}}".
276+
""")
277+
@Agent("Edits a story to better fit a given style")
278+
String editStory(@V("story") String story, @V("style") String style);
279+
}
280+
281+
interface StyleScorer {
282+
283+
@UserMessage(
284+
"""
285+
You are a critical reviewer.
286+
Give a review score between 0.0 and 1.0 for the following
287+
story based on how well it aligns with the style '{{style}}'.
288+
Return only the score and nothing else.
289+
290+
The story is: "{{story}}"
291+
""")
292+
@Agent("Scores a story based on how well it aligns with a given style")
293+
double scoreStyle(@V("story") String story, @V("style") String style);
294+
}
295+
296+
interface FoodExpert {
297+
298+
@UserMessage(
299+
"""
300+
You are a great evening planner.
301+
Propose a list of 3 meals matching the given mood.
302+
The mood is {{mood}}.
303+
For each meal, just give the name of the meal.
304+
Provide a list with the 3 items and nothing else.
305+
""")
306+
@Agent
307+
List<String> findMeal(@V("mood") String mood);
308+
}
309+
310+
interface AstrologyAgent {
311+
@SystemMessage(
312+
"""
313+
You are an astrologist that generates horoscopes based on the user's name and zodiac sign.
314+
""")
315+
@UserMessage(
316+
"""
317+
Generate the horoscope for {{name}} who is a {{sign}}.
318+
""")
319+
@Agent("An astrologist that generates horoscopes based on the user's name and zodiac sign.")
320+
String horoscope(@V("name") String name, @V("sign") String sign);
321+
}
322+
323+
enum RequestCategory {
324+
LEGAL,
325+
MEDICAL,
326+
TECHNICAL,
327+
UNKNOWN
328+
}
329+
330+
interface CategoryRouter {
331+
332+
@UserMessage(
333+
"""
334+
Analyze the following user request and categorize it as 'legal', 'medical' or 'technical'.
335+
In case the request doesn't belong to any of those categories categorize it as 'unknown'.
336+
Reply with only one of those words and nothing else.
337+
The user request is: '{{request}}'.
338+
""")
339+
@Agent("Categorizes a user request")
340+
RequestCategory classify(@V("request") String request);
341+
}
342+
343+
interface MedicalExpert {
344+
345+
@dev.langchain4j.service.UserMessage(
346+
"""
347+
You are a medical expert.
348+
Analyze the following user request under a medical point of view and provide the best possible answer.
349+
The user request is {{it}}.
350+
""")
351+
@Tool("A medical expert")
352+
String medicalRequest(String request);
353+
}
354+
355+
interface LegalExpert {
356+
357+
@dev.langchain4j.service.UserMessage(
358+
"""
359+
You are a legal expert.
360+
Analyze the following user request under a legal point of view and provide the best possible answer.
361+
The user request is {{it}}.
362+
""")
363+
@Tool("A legal expert")
364+
String legalRequest(String request);
365+
}
366+
367+
interface TechnicalExpert {
368+
369+
@dev.langchain4j.service.UserMessage(
370+
"""
371+
You are a technical expert.
372+
Analyze the following user request under a technical point of view and provide the best possible answer.
373+
The user request is {{it}}.
374+
""")
375+
@Tool("A technical expert")
376+
String technicalRequest(String request);
377+
}
237378
}

experimental/fluent/agentic/src/test/java/io/serverlessworkflow/fluent/agentic/AgentsUtils.java

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,84 @@ public static Agents.MovieExpert newMovieExpert() {
3131
.chatModel(BASE_MODEL)
3232
.build());
3333
}
34+
35+
public static Agents.CreativeWriter newCreativeWriter() {
36+
return spy(
37+
AgenticServices.agentBuilder(Agents.CreativeWriter.class)
38+
.outputName("story")
39+
.chatModel(BASE_MODEL)
40+
.build());
41+
}
42+
43+
public static Agents.AudienceEditor newAudienceEditor() {
44+
return spy(
45+
AgenticServices.agentBuilder(Agents.AudienceEditor.class)
46+
.outputName("story")
47+
.chatModel(BASE_MODEL)
48+
.build());
49+
}
50+
51+
public static Agents.StyleEditor newStyleEditor() {
52+
return spy(
53+
AgenticServices.agentBuilder(Agents.StyleEditor.class)
54+
.outputName("story")
55+
.chatModel(BASE_MODEL)
56+
.build());
57+
}
58+
59+
public static Agents.StyleScorer newStyleScorer() {
60+
return spy(
61+
AgenticServices.agentBuilder(Agents.StyleScorer.class)
62+
.outputName("score")
63+
.chatModel(BASE_MODEL)
64+
.build());
65+
}
66+
67+
public static Agents.FoodExpert newFoodExpert() {
68+
return spy(
69+
AgenticServices.agentBuilder(Agents.FoodExpert.class)
70+
.chatModel(BASE_MODEL)
71+
.outputName("meals")
72+
.build());
73+
}
74+
75+
public static Agents.AstrologyAgent newAstrologyAgent() {
76+
return spy(
77+
AgenticServices.agentBuilder(Agents.AstrologyAgent.class)
78+
.chatModel(BASE_MODEL)
79+
.outputName("horoscope")
80+
.build());
81+
}
82+
83+
public static Agents.CategoryRouter newCategoryRouter() {
84+
return spy(
85+
AgenticServices.agentBuilder(Agents.CategoryRouter.class)
86+
.chatModel(BASE_MODEL)
87+
.outputName("category")
88+
.build());
89+
}
90+
91+
public static Agents.MedicalExpert newMedicalExpert() {
92+
return spy(
93+
AgenticServices.agentBuilder(Agents.MedicalExpert.class)
94+
.chatModel(BASE_MODEL)
95+
.outputName("response")
96+
.build());
97+
}
98+
99+
public static Agents.TechnicalExpert newTechnicalExpert() {
100+
return spy(
101+
AgenticServices.agentBuilder(Agents.TechnicalExpert.class)
102+
.chatModel(BASE_MODEL)
103+
.outputName("response")
104+
.build());
105+
}
106+
107+
public static Agents.LegalExpert newLegalExpert() {
108+
return spy(
109+
AgenticServices.agentBuilder(Agents.LegalExpert.class)
110+
.chatModel(BASE_MODEL)
111+
.outputName("response")
112+
.build());
113+
}
34114
}

0 commit comments

Comments
 (0)