|
| 1 | +package com.embabel.template.agent; |
| 2 | + |
| 3 | +import com.embabel.agent.api.common.autonomy.AgentInvocation; |
| 4 | +import com.embabel.agent.domain.io.UserInput; |
| 5 | +import com.embabel.agent.testing.integration.EmbabelMockitoIntegrationTest; |
| 6 | +import org.junit.jupiter.api.Test; |
| 7 | + |
| 8 | +import static org.junit.jupiter.api.Assertions.*; |
| 9 | + |
| 10 | +/** |
| 11 | + * Use framework superclass to test the complete workflow of writing and reviewing a story. |
| 12 | + * This will run under Spring Boot against an AgentPlatform instance |
| 13 | + * that has loaded all our agents. |
| 14 | + */ |
| 15 | +class WriteAndReviewAgentIntegrationTest extends EmbabelMockitoIntegrationTest { |
| 16 | + |
| 17 | + @Test |
| 18 | + void shouldExecuteCompleteWorkflow() { |
| 19 | + var input = new UserInput("Write about artificial intelligence"); |
| 20 | + |
| 21 | + var story = new Story("AI will transform our world..."); |
| 22 | + var reviewedStory = new ReviewedStory(story, "Excellent exploration of AI themes.", Personas.REVIEWER); |
| 23 | + |
| 24 | + whenCreateObject(prompt -> prompt.contains("Craft a short story"), Story.class) |
| 25 | + .thenReturn(story); |
| 26 | + |
| 27 | + // The second call uses generateText |
| 28 | + whenGenerateText(prompt -> prompt.contains("You will be given a short story to review")) |
| 29 | + .thenReturn(reviewedStory.review()); |
| 30 | + |
| 31 | + var invocation = AgentInvocation.create(agentPlatform, ReviewedStory.class); |
| 32 | + var reviewedStoryResult = invocation.invoke(input); |
| 33 | + |
| 34 | + assertNotNull(reviewedStoryResult); |
| 35 | + assertTrue(reviewedStoryResult.getContent().contains(story.text()), |
| 36 | + "Expected story content to be present: " + reviewedStoryResult.getContent()); |
| 37 | + assertEquals(reviewedStory, reviewedStoryResult, |
| 38 | + "Expected review to match: " + reviewedStoryResult); |
| 39 | + |
| 40 | + verifyCreateObjectMatching(prompt -> prompt.contains("Craft a short story"), Story.class, |
| 41 | + llm -> llm.getLlm().getTemperature() == 0.7 && llm.getToolGroups().isEmpty()); |
| 42 | + verifyGenerateTextMatching(prompt -> prompt.contains("You will be given a short story to review")); |
| 43 | + verifyNoMoreInteractions(); |
| 44 | + } |
| 45 | +} |
0 commit comments