Skip to content

Commit 92380f6

Browse files
authored
Upgrade to 0.1.1
Upgrade to 0.1.1
2 parents 150a47f + 43b2927 commit 92380f6

10 files changed

Lines changed: 77 additions & 172 deletions

File tree

.idea/jarRepositories.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Add your magic here!
2626

2727
Illustrates:
2828

29+
- An injected demo showing how any Spring component can be injected with an Embabel `Ai` instance to enable it to
30+
perform LLM operations.
2931
- A simple agent
3032
- Unit tests for an agent verifying prompts and hyperparameters
3133

@@ -47,6 +49,12 @@ When the Embabel shell comes up, use the story agent like this:
4749
x "Tell me a story about...[your topic]"
4850
```
4951

52+
Try the `InjectedDemo` command to see simple, non-agent use:
53+
54+
```java
55+
animal
56+
```
57+
5058
## A2A Support
5159

5260
Embabel integrates with the [A2A](https://github.com/google-a2a/A2A) protocol, allowing you to connect to other

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
<properties>
2020
<java.version>21</java.version>
21-
<embabel-agent.version>0.1.0</embabel-agent.version>
21+
<embabel-agent.version>0.1.1</embabel-agent.version>
2222
</properties>
2323

2424
<dependencies>
@@ -63,7 +63,7 @@
6363
<snapshots>
6464
<enabled>false</enabled>
6565
</snapshots>
66-
</repository>
66+
</repository>
6767
<repository>
6868
<id>embabel-snapshots</id>
6969
<url>https://repo.embabel.com/artifactory/libs-snapshot</url>

src/main/java/com/embabel/template/ProjectNameApplication.java renamed to src/main/java/com/embabel/ProjectNameApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.embabel.template;
16+
package com.embabel;
1717

1818
import com.embabel.agent.config.annotation.EnableAgentShell;
1919
import com.embabel.agent.config.annotation.EnableAgents;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.embabel.template;
2+
3+
import com.embabel.template.injected.InjectedDemo;
4+
import org.springframework.shell.standard.ShellComponent;
5+
import org.springframework.shell.standard.ShellMethod;
6+
7+
@ShellComponent
8+
record DemoShell(InjectedDemo injectedDemo) {
9+
10+
@ShellMethod("Invent an animal")
11+
String animal() {
12+
return injectedDemo.inventAnimal().toString();
13+
}
14+
}

src/main/java/com/embabel/template/agent/WriteAndReviewAgent.java

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@
2020
import com.embabel.agent.api.annotation.Agent;
2121
import com.embabel.agent.api.annotation.Export;
2222
import com.embabel.agent.api.common.OperationContext;
23-
import com.embabel.agent.api.common.PromptRunner;
2423
import com.embabel.agent.domain.io.UserInput;
2524
import com.embabel.agent.domain.library.HasContent;
2625
import com.embabel.agent.prompt.persona.Persona;
27-
import com.embabel.common.ai.model.AutoModelSelectionCriteria;
26+
import com.embabel.agent.prompt.persona.RoleGoalBackstory;
2827
import com.embabel.common.ai.model.LlmOptions;
29-
import com.embabel.common.ai.prompt.PromptContributionLocation;
3028
import com.embabel.common.core.types.Timestamped;
3129
import org.springframework.beans.factory.annotation.Value;
3230
import org.springframework.context.annotation.Profile;
@@ -37,21 +35,16 @@
3735
import java.time.format.DateTimeFormatter;
3836

3937
abstract class Personas {
40-
static final Persona WRITER = Persona.create(
41-
"Roald Dahl",
42-
"A creative storyteller who loves to weave imaginative tales that are a bit unconventional",
43-
"Quirky",
44-
"Create memorable stories that captivate the reader's imagination.",
45-
"",
46-
PromptContributionLocation.BEGINNING
47-
);
38+
static final RoleGoalBackstory WRITER = RoleGoalBackstory
39+
.withRole("Creative Storyteller")
40+
.andGoal("Write engaging and imaginative stories")
41+
.andBackstory("Has a PhD in French literature; used to work in a circus");
42+
4843
static final Persona REVIEWER = Persona.create(
4944
"Media Book Review",
5045
"New York Times Book Reviewer",
5146
"Professional and insightful",
52-
"Help guide readers toward good stories",
53-
"",
54-
PromptContributionLocation.BEGINNING
47+
"Help guide readers toward good stories"
5548
);
5649
}
5750

@@ -112,8 +105,9 @@ class WriteAndReviewAgent {
112105
export = @Export(remote = true, name = "writeAndReviewStory"))
113106
@Action
114107
ReviewedStory reviewStory(UserInput userInput, Story story, OperationContext context) {
115-
String review = context.promptRunner()
116-
.withLlm(LlmOptions.fromCriteria(AutoModelSelectionCriteria.INSTANCE))
108+
var review = context
109+
.ai()
110+
.withAutoLlm()
117111
.withPromptContributor(Personas.REVIEWER)
118112
.generateText(String.format("""
119113
You will be given a short story to review.
@@ -141,12 +135,11 @@ ReviewedStory reviewStory(UserInput userInput, Story story, OperationContext con
141135

142136
@Action
143137
Story craftStory(UserInput userInput, OperationContext context) {
144-
PromptRunner runner = context.promptRunner()
145-
// Higher temperature for more creative output
146-
.withLlm(LlmOptions.fromCriteria(AutoModelSelectionCriteria.INSTANCE, 0.9))
147-
.withPromptContributor(Personas.WRITER);
148-
149-
return runner.createObject(String.format("""
138+
return context.ai()
139+
// Higher temperature for more creative output
140+
.withLlm(LlmOptions.withAutoLlm().withTemperature(.7))
141+
.withPromptContributor(Personas.WRITER)
142+
.createObject(String.format("""
150143
Craft a short story in %d words or less.
151144
The story should be engaging and imaginative.
152145
Use the user's input as inspiration if possible.
@@ -155,8 +148,8 @@ Story craftStory(UserInput userInput, OperationContext context) {
155148
# User input
156149
%s
157150
""",
158-
storyWordCount,
159-
userInput.getContent()
160-
).trim(), Story.class);
151+
storyWordCount,
152+
userInput.getContent()
153+
).trim(), Story.class);
161154
}
162155
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.embabel.template.injected;
2+
3+
import com.embabel.agent.api.common.Ai;
4+
import org.springframework.stereotype.Component;
5+
6+
/**
7+
* Demonstrate injection of Embabel's OperationContext into a Spring component.
8+
*
9+
* @param ai Embabel AI helper, injected by Spring
10+
*/
11+
@Component
12+
public record InjectedDemo(Ai ai) {
13+
14+
public record Animal(String name, String species) {
15+
}
16+
17+
public Animal inventAnimal() {
18+
return ai
19+
.withDefaultLlm()
20+
.createObject("""
21+
You just woke up in a magical forest.
22+
Invent a fictional animal.
23+
The animal should have a name and a species.
24+
""",
25+
Animal.class);
26+
}
27+
}

src/test/java/com/embabel/agent/testing/integration/EmbabelMockitoIntegrationTest.java

Lines changed: 0 additions & 139 deletions
This file was deleted.

src/test/java/com/embabel/template/agent/WriteAndReviewAgentIntegrationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* This will run under Spring Boot against an AgentPlatform instance
1414
* that has loaded all our agents.
1515
*/
16-
class StoryWriterIntegrationTest extends EmbabelMockitoIntegrationTest {
16+
class WriteAndReviewAgentIntegrationTest extends EmbabelMockitoIntegrationTest {
1717

1818
@Test
1919
void shouldExecuteCompleteWorkflow() {
@@ -39,7 +39,7 @@ void shouldExecuteCompleteWorkflow() {
3939
"Expected review to match: " + reviewedStoryResult);
4040

4141
verifyCreateObjectMatching(prompt -> prompt.contains("Craft a short story"), Story.class,
42-
llm -> llm.getLlm().getTemperature() == 0.9 && llm.getToolGroups().isEmpty());
42+
llm -> llm.getLlm().getTemperature() == 0.7 && llm.getToolGroups().isEmpty());
4343
verifyGenerateTextMatching(prompt -> prompt.contains("You will be given a short story to review"));
4444
verifyNoMoreInteractions();
4545
}

src/test/java/com/embabel/template/agent/WriteAndReviewAgentTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ void testWriteAndReviewAgent() {
2525
String prompt = promptRunner.getLlmInvocations().getFirst().getPrompt();
2626
assertTrue(prompt.contains("knight"), "Expected prompt to contain 'knight'");
2727

28-
var temp = promptRunner.getLlmInvocations().getFirst().getInteraction().getLlm().getTemperature();
29-
assertEquals(0.9, temp, 0.01,
30-
"Expected temperature to be 0.9: Higher for more creative output");
3128
}
3229

3330
@Test

0 commit comments

Comments
 (0)