|
1 | 1 | <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"> |
2 | 2 |
|
3 | | - |
| 3 | +# Generated Agent Project |
4 | 4 |
|
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
| 5 | + |
14 | 6 |
|
15 | | - |
| 7 | +    |
16 | 8 |
|
17 | | - |
18 | | - |
19 | | -# Generated Agent Project |
| 9 | +<br clear="left"/> |
20 | 10 |
|
21 | 11 | Starting point for your own agent development using the [Embabel framework](https://github.com/embabel/embabel-agent). |
22 | 12 |
|
| 13 | +Uses Spring Boot 3.5.9 and Embabel 0.3.1. |
| 14 | + |
23 | 15 | Add your magic here! |
24 | 16 |
|
25 | 17 | Illustrates: |
@@ -79,9 +71,64 @@ See [LLM integration guide](docs/llm-docs.md) (work in progress). |
79 | 71 |
|
80 | 72 | Also see [Spring AI models](https://docs.spring.io/spring-ai/reference/api/index.html). |
81 | 73 |
|
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. |
83 | 88 |
|
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 | +``` |
85 | 132 |
|
86 | 133 | ## Contributors |
87 | 134 |
|
|
0 commit comments