|
15 | 15 | */ |
16 | 16 | package io.serverlessworkflow.fluent.agentic.langchain4j; |
17 | 17 |
|
18 | | -import dev.langchain4j.agent.tool.Tool; |
19 | 18 | import dev.langchain4j.agentic.Agent; |
20 | | -import dev.langchain4j.agentic.scope.AgenticScopeAccess; |
21 | | -import dev.langchain4j.service.MemoryId; |
22 | 19 | import dev.langchain4j.service.UserMessage; |
23 | 20 | import dev.langchain4j.service.V; |
24 | | -import java.util.List; |
25 | 21 |
|
26 | 22 | public class Agents { |
27 | 23 |
|
28 | | - public interface ExpertRouterAgent { |
29 | | - |
30 | | - @Agent |
31 | | - String ask(@V("request") String request); |
32 | | - } |
33 | | - |
34 | | - public interface ExpertRouterAgentWithMemory extends AgenticScopeAccess { |
35 | | - |
36 | | - @Agent |
37 | | - String ask(@MemoryId String memoryId, @V("request") String request); |
38 | | - } |
39 | | - |
40 | | - public interface CategoryRouter { |
41 | | - |
42 | | - @UserMessage( |
43 | | - """ |
44 | | - Analyze the following user request and categorize it as 'legal', 'medical' or 'technical'. |
45 | | - In case the request doesn't belong to any of those categories categorize it as 'unknown'. |
46 | | - Reply with only one of those words and nothing else. |
47 | | - The user request is: '{{request}}'. |
48 | | - """) |
49 | | - @Agent("Categorize a user request") |
50 | | - RequestCategory classify(@V("request") String request); |
51 | | - } |
52 | | - |
53 | | - public enum RequestCategory { |
54 | | - LEGAL, |
55 | | - MEDICAL, |
56 | | - TECHNICAL, |
57 | | - UNKNOWN |
58 | | - } |
59 | | - |
60 | | - public interface RouterAgent { |
61 | | - |
62 | | - @UserMessage( |
63 | | - """ |
64 | | - Analyze the following user request and categorize it as 'legal', 'medical' or 'technical', |
65 | | - then forward the request as it is to the corresponding expert provided as a tool. |
66 | | - Finally return the answer that you received from the expert without any modification. |
67 | | -
|
68 | | - The user request is: '{{it}}'. |
69 | | - """) |
70 | | - @Agent |
71 | | - String askToExpert(String request); |
72 | | - } |
73 | | - |
74 | | - public interface MedicalExpert { |
75 | | - |
76 | | - @UserMessage( |
77 | | - """ |
78 | | - You are a medical expert. |
79 | | - Analyze the following user request under a medical point of view and provide the best possible answer. |
80 | | - The user request is {{request}}. |
81 | | - """) |
82 | | - @Tool("A medical expert") |
83 | | - @Agent("A medical expert") |
84 | | - String medical(@V("request") String request); |
85 | | - } |
86 | | - |
87 | | - public interface MedicalExpertWithMemory { |
88 | | - |
89 | | - @UserMessage( |
90 | | - """ |
91 | | - You are a medical expert. |
92 | | - Analyze the following user request under a medical point of view and provide the best possible answer. |
93 | | - The user request is {{request}}. |
94 | | - """) |
95 | | - @Tool("A medical expert") |
96 | | - @Agent("A medical expert") |
97 | | - String medical(@MemoryId String memoryId, @V("request") String request); |
98 | | - } |
99 | | - |
100 | | - public interface LegalExpert { |
101 | | - |
102 | | - @UserMessage( |
103 | | - """ |
104 | | - You are a legal expert. |
105 | | - Analyze the following user request under a legal point of view and provide the best possible answer. |
106 | | - The user request is {{request}}. |
107 | | - """) |
108 | | - @Tool("A legal expert") |
109 | | - @Agent("A legal expert") |
110 | | - String legal(@V("request") String request); |
111 | | - } |
112 | | - |
113 | | - public interface LegalExpertWithMemory { |
114 | | - |
115 | | - @UserMessage( |
116 | | - """ |
117 | | - You are a legal expert. |
118 | | - Analyze the following user request under a legal point of view and provide the best possible answer. |
119 | | - The user request is {{request}}. |
120 | | - """) |
121 | | - @Tool("A legal expert") |
122 | | - @Agent("A legal expert") |
123 | | - String legal(@MemoryId String memoryId, @V("request") String request); |
124 | | - } |
125 | | - |
126 | | - public interface TechnicalExpert { |
127 | | - |
128 | | - @UserMessage( |
129 | | - """ |
130 | | - You are a technical expert. |
131 | | - Analyze the following user request under a technical point of view and provide the best possible answer. |
132 | | - The user request is {{request}}. |
133 | | - """) |
134 | | - @Tool("A technical expert") |
135 | | - @Agent("A technical expert") |
136 | | - String technical(@V("request") String request); |
137 | | - } |
138 | | - |
139 | | - public interface TechnicalExpertWithMemory { |
140 | | - |
141 | | - @UserMessage( |
142 | | - """ |
143 | | - You are a technical expert. |
144 | | - Analyze the following user request under a technical point of view and provide the best possible answer. |
145 | | - The user request is {{request}}. |
146 | | - """) |
147 | | - @Tool("A technical expert") |
148 | | - @Agent("A technical expert") |
149 | | - String technical(@MemoryId String memoryId, @V("request") String request); |
150 | | - } |
151 | | - |
152 | 24 | public interface CreativeWriter { |
153 | 25 |
|
154 | 26 | @UserMessage( |
@@ -187,71 +59,4 @@ public interface StyleEditor { |
187 | 59 | @Agent("Edit a story to better fit a given style") |
188 | 60 | String editStory(@V("story") String story, @V("style") String style); |
189 | 61 | } |
190 | | - |
191 | | - public interface StyleScorer { |
192 | | - |
193 | | - @UserMessage( |
194 | | - """ |
195 | | - You are a critical reviewer. |
196 | | - Give a review score between 0.0 and 1.0 for the following story based on how well it aligns with the style '{{style}}'. |
197 | | - Return only the score and nothing else. |
198 | | -
|
199 | | - The story is: "{{story}}" |
200 | | - """) |
201 | | - @Agent("Score a story based on how well it aligns with a given style") |
202 | | - double scoreStyle(@V("story") String story, @V("style") String style); |
203 | | - } |
204 | | - |
205 | | - public interface StyleReviewLoop { |
206 | | - |
207 | | - @Agent("Review the given story to ensure it aligns with the specified style") |
208 | | - String scoreAndReview(@V("story") String story, @V("style") String style); |
209 | | - } |
210 | | - |
211 | | - public interface StyledWriter extends AgenticScopeAccess { |
212 | | - |
213 | | - @Agent |
214 | | - String writeStoryWithStyle(@V("topic") String topic, @V("style") String style); |
215 | | - } |
216 | | - |
217 | | - public interface FoodExpert { |
218 | | - |
219 | | - @UserMessage( |
220 | | - """ |
221 | | - You are a great evening planner. |
222 | | - Propose a list of 3 meals matching the given mood. |
223 | | - The mood is {{mood}}. |
224 | | - For each meal, just give the name of the meal. |
225 | | - Provide a list with the 3 items and nothing else. |
226 | | - """) |
227 | | - @Agent |
228 | | - List<String> findMeal(@V("mood") String mood); |
229 | | - } |
230 | | - |
231 | | - public interface MovieExpert { |
232 | | - |
233 | | - @UserMessage( |
234 | | - """ |
235 | | - You are a great evening planner. |
236 | | - Propose a list of 3 movies matching the given mood. |
237 | | - The mood is {mood}. |
238 | | - Provide a list with the 3 items and nothing else. |
239 | | - """) |
240 | | - @Agent |
241 | | - List<String> findMovie(@V("mood") String mood); |
242 | | - } |
243 | | - |
244 | | - public record EveningPlan(String movie, String meal) {} |
245 | | - |
246 | | - public interface EveningPlannerAgent { |
247 | | - |
248 | | - @Agent |
249 | | - List<EveningPlan> plan(@V("mood") String mood); |
250 | | - } |
251 | | - |
252 | | - public interface HoroscopeAgent { |
253 | | - |
254 | | - @Agent |
255 | | - String invoke(@V("name") String name); |
256 | | - } |
257 | 62 | } |
0 commit comments