11package io .quarkiverse .langchain4j .agentic .deployment ;
22
3- import java .util .List ;
4-
53import jakarta .enterprise .context .ApplicationScoped ;
64import jakarta .inject .Inject ;
75
1311import dev .langchain4j .agentic .declarative .ExitCondition ;
1412import dev .langchain4j .agentic .declarative .LoopAgent ;
1513import dev .langchain4j .agentic .declarative .SequenceAgent ;
16- import dev .langchain4j .agentic .declarative .SubAgent ;
1714import dev .langchain4j .agentic .declarative .SupervisorAgent ;
1815import dev .langchain4j .agentic .declarative .SupervisorRequest ;
1916import dev .langchain4j .agentic .scope .AgenticScopeAccess ;
@@ -63,7 +60,7 @@ public interface CategoryRouter {
6360 Reply with only one of those words and nothing else.
6461 The user request is: '{{request}}'.
6562 """ )
66- @ Agent ("Categorize a user request" )
63+ @ Agent (description = "Categorize a user request" , outputKey = "category " )
6764 RequestCategory classify (@ V ("request" ) String request );
6865
6966 @ ChatModelSupplier
@@ -100,7 +97,7 @@ public interface MedicalExpert {
10097 The user request is {{request}}.
10198 """ )
10299 @ Tool ("A medical expert" )
103- @ Agent ("A medical expert" )
100+ @ Agent (description = "A medical expert" , outputKey = "response " )
104101 String medical (@ V ("request" ) String request );
105102
106103 @ ChatModelSupplier
@@ -118,7 +115,7 @@ public interface MedicalExpertWithMemory {
118115 The user request is {{request}}.
119116 """ )
120117 @ Tool ("A medical expert" )
121- @ Agent ("A medical expert" )
118+ @ Agent (description = "A medical expert" , outputKey = "response " )
122119 String medical (@ MemoryId String memoryId , @ V ("request" ) String request );
123120 }
124121
@@ -130,7 +127,7 @@ public interface LegalExpert {
130127 The user request is {{request}}.
131128 """ )
132129 @ Tool ("A legal expert" )
133- @ Agent ("A legal expert" )
130+ @ Agent (description = "A legal expert" , outputKey = "response " )
134131 String legal (@ V ("request" ) String request );
135132 }
136133
@@ -142,7 +139,7 @@ public interface LegalExpertWithMemory {
142139 The user request is {{request}}.
143140 """ )
144141 @ Tool ("A legal expert" )
145- @ Agent ("A legal expert" )
142+ @ Agent (description = "A legal expert" , outputKey = "response " )
146143 String legal (@ MemoryId String memoryId , @ V ("request" ) String request );
147144 }
148145
@@ -154,7 +151,7 @@ public interface TechnicalExpert {
154151 The user request is {{request}}.
155152 """ )
156153 @ Tool ("A technical expert" )
157- @ Agent ("A technical expert" )
154+ @ Agent (description = "A technical expert" , outputKey = "response " )
158155 String technical (@ V ("request" ) String request );
159156 }
160157
@@ -166,7 +163,7 @@ public interface TechnicalExpertWithMemory {
166163 The user request is {{request}}.
167164 """ )
168165 @ Tool ("A technical expert" )
169- @ Agent ("A technical expert" )
166+ @ Agent (description = "A technical expert" , outputKey = "response " )
170167 String technical (@ MemoryId String memoryId , @ V ("request" ) String request );
171168 }
172169
@@ -178,7 +175,7 @@ public interface CreativeWriter {
178175 Return only the story and nothing else.
179176 The topic is {{topic}}.
180177 """ )
181- @ Agent ("Generate a story based on the given topic" )
178+ @ Agent (description = "Generate a story based on the given topic" , outputKey = "story " )
182179 String generateStory (@ V ("topic" ) String topic );
183180
184181 @ ChatModelSupplier
@@ -200,7 +197,7 @@ public interface AudienceEditor {
200197 Return only the story and nothing else.
201198 The story is "{{story}}".
202199 """ )
203- @ Agent ("Edit a story to better fit a given audience" )
200+ @ Agent (description = "Edit a story to better fit a given audience" , outputKey = "story " )
204201 String editStory (@ V ("story" ) String story , @ V ("audience" ) String audience );
205202
206203 @ ChatModelSupplier
@@ -224,7 +221,7 @@ public interface StyleEditor {
224221 Return only the story and nothing else.
225222 The story is "{{story}}".
226223 """ )
227- @ Agent ("Edit a story to better fit a given style" )
224+ @ Agent (description = "Edit a story to better fit a given style" , outputKey = "story " )
228225 String editStory (@ V ("story" ) String story , @ V ("style" ) String style );
229226
230227 @ ChatModelSupplier
@@ -256,7 +253,7 @@ public interface StyleScorer {
256253
257254 The story is: "{{story}}"
258255 """ )
259- @ Agent ("Score a story based on how well it aligns with a given style" )
256+ @ Agent (description = "Score a story based on how well it aligns with a given style" , outputKey = "score " )
260257 double scoreStyle (@ V ("story" ) String story , @ V ("style" ) String style );
261258
262259 @ ChatModelSupplier
@@ -277,40 +274,6 @@ public interface StyledWriter extends AgenticScopeAccess {
277274 ResultWithAgenticScope <String > writeStoryWithStyle (@ V ("topic" ) String topic , @ V ("style" ) String style );
278275 }
279276
280- public interface FoodExpert {
281-
282- @ UserMessage ("""
283- You are a great evening planner.
284- Propose a list of 3 meals matching the given mood.
285- The mood is {{mood}}.
286- For each meal, just give the name of the meal.
287- Provide a list with the 3 items and nothing else.
288- """ )
289- @ Agent
290- List <String > findMeal (@ V ("mood" ) String mood );
291- }
292-
293- public interface MovieExpert {
294-
295- @ UserMessage ("""
296- You are a great evening planner.
297- Propose a list of 3 movies matching the given mood.
298- The mood is {{mood}}.
299- Provide a list with the 3 items and nothing else.
300- """ )
301- @ Agent
302- List <String > findMovie (@ V ("mood" ) String mood );
303- }
304-
305- public record EveningPlan (String movie , String meal ) {
306- }
307-
308- public interface EveningPlannerAgent {
309-
310- @ Agent
311- List <EveningPlan > plan (@ V ("mood" ) String mood );
312- }
313-
314277 @ ApplicationScoped
315278 public static class NoneAiAgent {
316279
@@ -328,20 +291,14 @@ public String goodBye() {
328291
329292 public interface StoryCreator {
330293
331- @ SequenceAgent (outputKey = "story" , subAgents = {
332- @ SubAgent (type = CreativeWriter .class , outputKey = "story" ),
333- @ SubAgent (type = AudienceEditor .class , outputKey = "story" ),
334- @ SubAgent (type = StyleEditor .class , outputKey = "story" )
335- })
294+ @ SequenceAgent (outputKey = "story" , subAgents = { CreativeWriter .class , AudienceEditor .class , StyleEditor .class })
336295 String write (@ V ("topic" ) String topic , @ V ("style" ) String style , @ V ("audience" ) String audience );
337296 }
338297
339298 public interface StyleReviewLoopAgent {
340299
341300 @ LoopAgent (description = "Review the given story to ensure it aligns with the specified style" , outputKey = "story" , maxIterations = 5 , subAgents = {
342- @ SubAgent (type = StyleScorer .class , outputKey = "score" ),
343- @ SubAgent (type = StyleEditor .class , outputKey = "story" )
344- })
301+ StyleScorer .class , StyleEditor .class })
345302 String write (@ V ("story" ) String story );
346303
347304 @ ExitCondition
@@ -353,9 +310,7 @@ static boolean exit(@V("score") double score) {
353310 public interface SupervisorStoryCreator {
354311
355312 @ SupervisorAgent (outputKey = "story" , responseStrategy = SupervisorResponseStrategy .LAST , subAgents = {
356- @ SubAgent (type = CreativeWriter .class , outputKey = "story" ),
357- @ SubAgent (type = StyleReviewLoopAgent .class , outputKey = "story" )
358- })
313+ CreativeWriter .class , StyleReviewLoopAgent .class })
359314 ResultWithAgenticScope <String > write (@ V ("topic" ) String topic , @ V ("style" ) String style );
360315
361316 @ SupervisorRequest
0 commit comments