Skip to content

Commit 697d2e7

Browse files
committed
Handoff example
1 parent 62880df commit 697d2e7

File tree

4 files changed

+53
-8
lines changed

4 files changed

+53
-8
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.embabel.example.handoff;
2+
3+
import com.embabel.agent.api.annotation.*;
4+
import com.embabel.agent.api.common.OperationContext;
5+
import com.embabel.agent.domain.io.UserInput;
6+
import com.embabel.common.ai.model.LlmOptions;
7+
import com.embabel.example.horoscope.StarPerson;
8+
import com.embabel.example.wikipedia.ResearchSubject;
9+
10+
record Choice(String choice) {
11+
12+
}
13+
14+
record AdventureLog(String log) {
15+
}
16+
17+
@Agent(description = "Choose your own adventure handoff agent")
18+
public class Handoff {
19+
20+
/**
21+
* This action is get user input out of the way in selecting the adventure by handoff
22+
* @param userInput
23+
* @param operationContext
24+
* @return
25+
*/
26+
@Action
27+
Choice makeChoice(UserInput userInput, OperationContext operationContext) {
28+
return WaitFor.formSubmission("Please choose your own adventure", Choice.class);
29+
}
30+
31+
@Action
32+
@AchievesGoal(description = "Choose your own adventure",
33+
export = @Export(remote = true))
34+
AdventureLog chooseAdventure(Choice choice, OperationContext operationContext) {
35+
return operationContext.promptRunner()
36+
.withLlm(LlmOptions.fromModel("gpt-4.1-nano"))
37+
.withHandoffs(StarPerson.class, ResearchSubject.class)
38+
.createObject("""
39+
Based on the user's input, decide what to do. You might do something related to a horoscope or some fact checking.
40+
What they said: %s
41+
""".formatted(choice.choice()), AdventureLog.class);
42+
}
43+
}

examples-java/src/main/java/com/embabel/example/horoscope/StarNewsFinder.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515
*/
1616
package com.embabel.example.horoscope;
1717

18-
import com.embabel.agent.api.annotation.AchievesGoal;
19-
import com.embabel.agent.api.annotation.Action;
20-
import com.embabel.agent.api.annotation.Agent;
21-
import com.embabel.agent.api.annotation.WaitFor;
18+
import com.embabel.agent.api.annotation.*;
2219
import com.embabel.agent.api.common.PromptRunner;
2320
import com.embabel.agent.config.models.OpenAiModels;
2421
import com.embabel.agent.core.CoreToolGroups;
@@ -118,7 +115,11 @@ public RelevantNewsStories findNewsStories(StarPerson person, Horoscope horoscop
118115
// The @AchievesGoal annotation indicates that completing this action
119116
// achieves the given goal, so the agent can be complete
120117
@AchievesGoal(
121-
description = "Write an amusing writeup for the target person based on their horoscope and current news stories"
118+
description = "Write an amusing writeup for the target person based on their horoscope and current news stories",
119+
export = @Export(
120+
remote = true,
121+
name = "starNewsWriteup",
122+
startingInputTypes = {StarPerson.class, UserInput.class})
122123
)
123124
@Action
124125
public Writeup writeup(
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.embabel.example.wikipedia;
2+
3+
public record ResearchSubject(String name) {
4+
}

examples-java/src/main/java/com/embabel/example/wikipedia/WikiAgent.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@
2525
import java.util.List;
2626
import java.util.stream.Collectors;
2727

28-
record ResearchSubject(String name) {
29-
}
30-
3128
record FocusAreas(List<FocusArea> focusAreas) {}
3229

3330
record FocusArea(String topic) {

0 commit comments

Comments
 (0)