1717
1818import com .embabel .agent .api .annotation .*;
1919import com .embabel .agent .api .common .OperationContext ;
20+ import com .embabel .agent .config .models .AnthropicModels ;
2021import com .embabel .agent .config .models .OpenAiModels ;
2122import com .embabel .agent .core .CoreToolGroups ;
2223import com .embabel .agent .domain .io .UserInput ;
2324import com .embabel .agent .domain .library .Person ;
2425import com .embabel .agent .domain .library .PersonImpl ;
2526import com .embabel .agent .domain .library .RelevantNewsStories ;
2627import com .embabel .common .ai .model .LlmOptions ;
27- import com .embabel .common .ai .model .ModelSelectionCriteria ;
2828import org .springframework .beans .factory .annotation .Value ;
2929
3030import java .util .stream .Collectors ;
@@ -51,12 +51,14 @@ public StarNewsFinder(
5151
5252 @ Action
5353 public Person extractPerson (UserInput userInput , OperationContext context ) {
54- return context .ai ().withLlm (OpenAiModels .GPT_41 ).createObjectIfPossible (
55- """
56- Create a person from this user input, extracting their name:
57- %s""" .formatted (userInput .getContent ()),
58- PersonImpl .class
59- );
54+ return context .ai ()
55+ .withLlm (OpenAiModels .GPT_41 )
56+ .createObjectIfPossible (
57+ """
58+ Create a person from this user input, extracting their name:
59+ %s""" .formatted (userInput .getContent ()),
60+ PersonImpl .class
61+ );
6062 }
6163
6264 @ Action (cost = 100.0 ) // Make it costly so it won't be used in a plan unless there's no other path
@@ -75,12 +77,14 @@ public StarPerson assembleStarPerson(Person person, Starry starry) {
7577
7678 @ Action
7779 public StarPerson extractStarPerson (UserInput userInput , OperationContext context ) {
78- return context .ai ().withLlm (OpenAiModels .GPT_41 ).createObjectIfPossible (
79- """
80- Create a person from this user input, extracting their name and star sign:
81- %s""" .formatted (userInput .getContent ()),
82- StarPerson .class
83- );
80+ return context .ai ()
81+ .withLlmByRole ("best" )
82+ .createObjectIfPossible (
83+ """
84+ Create a person from this user input, extracting their name and star sign:
85+ %s""" .formatted (userInput .getContent ()),
86+ StarPerson .class
87+ );
8488 }
8589
8690 @ Action
@@ -109,7 +113,9 @@ public RelevantNewsStories findNewsStories(StarPerson person, Horoscope horoscop
109113 find news stories about training courses.""" .formatted (
110114 person .name (), person .sign (), horoscope .summary (), storyCount );
111115
112- return context .ai ().withDefaultLlm ().createObject (prompt , RelevantNewsStories .class );
116+ return context .ai ()
117+ .withDefaultLlm ().
118+ createObject (prompt , RelevantNewsStories .class );
113119 }
114120
115121 // The @AchievesGoal annotation indicates that completing this action
@@ -127,10 +133,6 @@ public Writeup writeup(
127133 RelevantNewsStories relevantNewsStories ,
128134 Horoscope horoscope ,
129135 OperationContext context ) {
130- var llm = LlmOptions .fromCriteria (
131- ModelSelectionCriteria .firstOf (OpenAiModels .GPT_41_MINI )
132- ).withTemperature (0.9 );
133-
134136 var newsItems = relevantNewsStories .getItems ().stream ()
135137 .map (item -> "- " + item .getUrl () + ": " + item .getSummary ())
136138 .collect (Collectors .joining ("\n " ));
@@ -150,6 +152,10 @@ public Writeup writeup(
150152
151153 Format it as Markdown with links.""" .formatted (
152154 person .name (), person .sign (), horoscope .summary (), newsItems );
153- return context .ai ().withLlm (llm ).createObject (prompt , Writeup .class );
155+ return context .ai ()
156+ .withLlm (LlmOptions
157+ .withFirstAvailableLlmOf (AnthropicModels .CLAUDE_37_SONNET , OpenAiModels .GPT_41_MINI )
158+ .withTemperature (0.9 ))
159+ .createObject (prompt , Writeup .class );
154160 }
155161}
0 commit comments