Skip to content

Commit 119bc4e

Browse files
committed
Update to 0.3.1
1 parent 088a3c5 commit 119bc4e

File tree

7 files changed

+80
-33
lines changed

7 files changed

+80
-33
lines changed

README.md

Lines changed: 63 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
11
<img align="left" src="https://github.com/embabel/embabel-agent/blob/main/embabel-agent-api/images/315px-Meister_der_Weltenchronik_001.jpg?raw=true" width="180">
22

3-
![Build](https://github.com/embabel/java-agent-template/actions/workflows/maven.yml/badge.svg)
3+
# Generated Agent Project
44

5-
![Java](https://img.shields.io/badge/java-%23ED8B00.svg?style=for-the-badge&logo=openjdk&logoColor=white)
6-
![Spring](https://img.shields.io/badge/spring-%236DB33F.svg?style=for-the-badge&logo=spring&logoColor=white)
7-
![Apache Tomcat](https://img.shields.io/badge/apache%20tomcat-%23F8DC75.svg?style=for-the-badge&logo=apache-tomcat&logoColor=black)
8-
![Apache Maven](https://img.shields.io/badge/Apache%20Maven-C71A36?style=for-the-badge&logo=Apache%20Maven&logoColor=white)
9-
![ChatGPT](https://img.shields.io/badge/chatGPT-74aa9c?style=for-the-badge&logo=openai&logoColor=white)
10-
![JSON](https://img.shields.io/badge/JSON-000?logo=json&logoColor=fff)
11-
![GitHub Actions](https://img.shields.io/badge/github%20actions-%232671E5.svg?style=for-the-badge&logo=githubactions&logoColor=white)
12-
![Docker](https://img.shields.io/badge/docker-%230db7ed.svg?style=for-the-badge&logo=docker&logoColor=white)
13-
![IntelliJ IDEA](https://img.shields.io/badge/IntelliJIDEA-000000.svg?style=for-the-badge&logo=intellij-idea&logoColor=white)
5+
![Build](https://github.com/embabel/java-agent-template/actions/workflows/maven.yml/badge.svg)
146

15-
&nbsp;&nbsp;&nbsp;&nbsp;
7+
![Java](https://img.shields.io/badge/java-%23ED8B00.svg?style=for-the-badge&logo=openjdk&logoColor=white) ![Spring](https://img.shields.io/badge/spring-%236DB33F.svg?style=for-the-badge&logo=spring&logoColor=white) ![Apache Maven](https://img.shields.io/badge/Apache%20Maven-C71A36?style=for-the-badge&logo=Apache%20Maven&logoColor=white) ![ChatGPT](https://img.shields.io/badge/chatGPT-74aa9c?style=for-the-badge&logo=openai&logoColor=white)
168

17-
&nbsp;&nbsp;&nbsp;&nbsp;
18-
19-
# Generated Agent Project
9+
<br clear="left"/>
2010

2111
Starting point for your own agent development using the [Embabel framework](https://github.com/embabel/embabel-agent).
2212

13+
Uses Spring Boot 3.5.9 and Embabel 0.3.1.
14+
2315
Add your magic here!
2416

2517
Illustrates:
@@ -79,9 +71,64 @@ See [LLM integration guide](docs/llm-docs.md) (work in progress).
7971

8072
Also see [Spring AI models](https://docs.spring.io/spring-ai/reference/api/index.html).
8173

82-
## A2A support
74+
## Testing
75+
76+
This repository includes unit tests and integration tests demonstrating how to test Embabel agents.
77+
78+
### Running Tests
79+
80+
```bash
81+
mvn test
82+
```
83+
84+
### Unit Tests
85+
86+
Unit tests use Embabel's `FakeOperationContext` and `FakePromptRunner` to test agent actions in isolation without
87+
calling actual LLMs.
8388

84-
Embabel integrates with Google A2a. See [A2A integration](docs/a2a.md).
89+
See [WriteAndReviewAgentTest.java](./src/test/java/com/embabel/template/agent/WriteAndReviewAgentTest.java) for examples
90+
of:
91+
92+
- Creating a fake context with `FakeOperationContext.create()`
93+
- Setting up expected responses with `context.expectResponse()`
94+
- Verifying prompt content contains expected values
95+
- Inspecting LLM invocations via `promptRunner.getLlmInvocations()`
96+
97+
```java
98+
var context = FakeOperationContext.create();
99+
context.expectResponse(new Story("Once upon a time..."));
100+
101+
var story = agent.craftStory(userInput, context.ai());
102+
103+
var prompt = context.getLlmInvocations().getFirst().getMessages().getFirst().getContent();
104+
assertTrue(prompt.contains("knight"));
105+
```
106+
107+
### Integration Tests
108+
109+
Integration tests extend `EmbabelMockitoIntegrationTest` to test complete agent workflows under Spring Boot with a fully
110+
configured `AgentPlatform`.
111+
112+
See [WriteAndReviewAgentIntegrationTest.java](./src/test/java/com/embabel/template/agent/WriteAndReviewAgentIntegrationTest.java)
113+
for examples of:
114+
115+
- Mocking LLM responses with `whenCreateObject()` and `whenGenerateText()`
116+
- Running complete agent workflows via `AgentInvocation`
117+
- Verifying LLM calls and hyperparameters with `verifyCreateObjectMatching()` and `verifyGenerateTextMatching()`
118+
119+
```java
120+
whenCreateObject(prompt -> prompt.contains("Craft a short story"), Story.class)
121+
.thenReturn(new Story("AI will transform our world..."));
122+
123+
var invocation = AgentInvocation.create(agentPlatform, ReviewedStory.class);
124+
var result = invocation.invoke(input);
125+
126+
verifyCreateObjectMatching(
127+
prompt -> prompt.contains("Craft a short story"),
128+
Story.class,
129+
llm -> llm.getLlm().getTemperature() == 0.7
130+
);
131+
```
85132

86133
## Contributors
87134

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>org.springframework.boot</groupId>
88
<artifactId>spring-boot-starter-parent</artifactId>
9-
<version>3.5.7</version>
9+
<version>3.5.9</version>
1010
<relativePath/> <!-- Lookup parent from repository -->
1111
</parent>
1212
<groupId>com.embabel.template</groupId>
@@ -18,7 +18,7 @@
1818

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

2424
<dependencies>
@@ -89,7 +89,7 @@
8989
<dependency>
9090
<groupId>com.embabel.agent</groupId>
9191
<artifactId>embabel-agent-starter-anthropic</artifactId>
92-
<version>${embabel-agent.version}</version>
92+
<version>${embabel-agent.version}</version>
9393
</dependency>
9494
</dependencies>
9595
</profile>

src/main/java/com/embabel/template/DemoShell.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.embabel.template;
22

3-
import com.embabel.agent.api.common.autonomy.AgentInvocation;
3+
import com.embabel.agent.api.invocation.AgentInvocation;
44
import com.embabel.agent.core.AgentPlatform;
55
import com.embabel.agent.domain.io.UserInput;
66
import com.embabel.template.agent.WriteAndReviewAgent;

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import com.embabel.common.ai.model.LlmOptions;
2828
import com.embabel.common.core.types.Timestamped;
2929
import org.springframework.beans.factory.annotation.Value;
30-
import org.springframework.context.annotation.Profile;
3130
import org.springframework.lang.NonNull;
3231

3332
import java.time.Instant;
@@ -40,7 +39,7 @@ abstract class Personas {
4039
.andGoal("Write engaging and imaginative stories")
4140
.andBackstory("Has a PhD in French literature; used to work in a circus");
4241

43-
static final Persona REVIEWER = new Persona(
42+
static final Persona REVIEWER = Persona.create(
4443
"Media Book Review",
4544
"New York Times Book Reviewer",
4645
"Professional and insightful",
@@ -50,7 +49,6 @@ abstract class Personas {
5049

5150

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

5654
public record Story(String text) {

src/main/java/com/embabel/template/injected/InjectedDemo.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ public Animal inventAnimal() {
2626
return ai
2727
.withDefaultLlm()
2828
.withId("invent-animal")
29-
.createObject("""
30-
You just woke up in a magical forest.
31-
Invent a fictional animal.
32-
The animal should have a name and a species.
33-
""",
34-
Animal.class);
29+
.creating(Animal.class)
30+
.withExample("good example", new Animal("Fluffox", "Magicox"))
31+
.withExample("bad example: does not pass validation", new Animal("Sparky", "Dragon"))
32+
.fromPrompt("""
33+
You just woke up in a magical forest.
34+
Invent a fictional animal.
35+
The animal should have a name and a species.
36+
""");
3537
}
3638
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.embabel.template.agent;
22

3-
import com.embabel.agent.api.common.autonomy.AgentInvocation;
3+
import com.embabel.agent.api.invocation.AgentInvocation;
44
import com.embabel.agent.domain.io.UserInput;
5-
import com.embabel.agent.testing.integration.EmbabelMockitoIntegrationTest;
5+
import com.embabel.agent.test.integration.EmbabelMockitoIntegrationTest;
66
import org.junit.jupiter.api.BeforeAll;
77
import org.junit.jupiter.api.Test;
88

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.embabel.template.agent;
22

33
import com.embabel.agent.domain.io.UserInput;
4-
import com.embabel.agent.testing.unit.FakeOperationContext;
5-
import com.embabel.agent.testing.unit.FakePromptRunner;
4+
import com.embabel.agent.test.unit.FakeOperationContext;
5+
import com.embabel.agent.test.unit.FakePromptRunner;
66
import org.junit.jupiter.api.Test;
77

88
import java.time.Instant;

0 commit comments

Comments
 (0)