Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

./scripts/support/check_env.sh

export SPRING_PROFILES_ACTIVE=shell,starwars
mvn -P agent-examples-kotlin -Dmaven.test.skip=true spring-boot:run
export SPRING_PROFILES_ACTIVE=shell,severance
mvn -Dmaven.test.skip=true spring-boot:run
30 changes: 30 additions & 0 deletions src/main/java/com/embabel/template/agent/HomeController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.embabel.template.agent;

import com.embabel.agent.core.*;
import com.embabel.agent.domain.io.UserInput;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.Instant;
import java.util.Map;

@RestController
public class HomeController {
@Autowired
private AgentPlatform agentPlatform;

@RequestMapping("/")
public String home() {
Agent agent = agentPlatform.agents().getFirst();
AgentProcess agentProcess = agentPlatform.runAgentFrom(
agent,
ProcessOptions.getDEFAULT(),
Map.of(
"user_input", new UserInput("hello world", Instant.now())
)
);
ReviewedStory reviewedStory = ((ReviewedStory) agentProcess.lastResult());
return reviewedStory.getContent();
}
}
15 changes: 12 additions & 3 deletions src/main/java/com/embabel/template/agent/WriteAndReviewAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.embabel.agent.api.annotation.AchievesGoal;
import com.embabel.agent.api.annotation.Action;
import com.embabel.agent.api.annotation.Agent;
import com.embabel.agent.api.annotation.Condition;
import com.embabel.agent.api.common.OperationContext;
import com.embabel.agent.api.common.PromptRunner;
import com.embabel.agent.domain.io.UserInput;
Expand Down Expand Up @@ -88,7 +89,7 @@ public String getContent() {

@Agent(description = "Generate a story based on user input and review it")
@Profile("!test")
class WriteAndReviewAgent {
public class WriteAndReviewAgent {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have to have public in order for Reflection to call the condition method.


private final int storyWordCount;
private final int reviewWordCount;
Expand All @@ -101,8 +102,11 @@ class WriteAndReviewAgent {
this.reviewWordCount = reviewWordCount;
}

@Action
Story craftStory(UserInput userInput) {
@Action(
post = {"isStoryShortEnough"},
canRerun = true
)
public Story craftStory(UserInput userInput) {
return PromptRunner.usingLlm(
LlmOptions.fromCriteria(AutoModelSelectionCriteria.INSTANCE)
.withTemperature(0.9) // Higher temperature for more creative output
Expand Down Expand Up @@ -150,4 +154,9 @@ ReviewedStory reviewStory(UserInput userInput, Story story, OperationContext con
Personas.REVIEWER
);
}

@Condition(name = "isStoryShortEnough")
public boolean isStoryLongEnough(Story story, OperationContext operationContext) {
return story.text().length() < 200;
}
}
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
spring.profiles.active=shell
spring.profiles.active=web, severance