Skip to content

Commit e4a2969

Browse files
committed
First version
1 parent 6b5b751 commit e4a2969

File tree

16 files changed

+2326
-365
lines changed

16 files changed

+2326
-365
lines changed

README.md

Lines changed: 1 addition & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -16,76 +16,4 @@
1616

1717
    
1818

19-
# Generated agent
20-
21-
Java agent repository generated by the Embabel project creator.
22-
23-
Starting point for your own agent development using the [Embabel framework](https://github.com/embabel/embabel-agent).
24-
25-
Add your magic here!
26-
27-
Illustrates:
28-
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.
31-
- A simple agent
32-
- Unit tests for an agent verifying prompts and hyperparameters
33-
34-
# To run
35-
36-
Run the shell script to start Embabel under Spring Shell:
37-
38-
```bash
39-
./scripts/shell.sh
40-
```
41-
42-
There is a single example agent, `WriteAndReviewAgent`.
43-
It uses one LLM with a high temperature and creative persona to write a story based on your input,
44-
then another LLM with a low temperature and different persona to review the story.
45-
46-
When the Embabel shell comes up, use the story agent like this:
47-
48-
```
49-
x "Tell me a story about...[your topic]"
50-
```
51-
52-
Try the `InjectedDemo` command to see simple, non-agent use:
53-
54-
```java
55-
animal
56-
```
57-
58-
## A2A Support
59-
60-
Embabel integrates with the [A2A](https://github.com/google-a2a/A2A) protocol, allowing you to connect to other
61-
A2A-enabled agents and
62-
services.
63-
64-
> Embabel agents can be exposed to A2A with zero developer effort.
65-
66-
Check out the `a2a` branch of this repository to try A2A support.
67-
68-
You'll need the following environment variable:
69-
70-
- `GOOGLE_STUDIO_API_KEY`: Your Google Studio API key, which is used for Gemini.
71-
72-
Start the Google A2A web interface using Docker compose:
73-
74-
```bash
75-
docker compose up
76-
```
77-
78-
Go to the web interface running within the container at `http://localhost:12000/`.
79-
80-
Connect to your agent at `host.docker.internal:8080/a2a`. Note that `localhost:8080/a2a` won't work as the server
81-
cannot access it when running in a Docker container.
82-
83-
Your agent will have automatically been exported to A2A. Add it in the UI, and start a chat.
84-
You should see something like this:
85-
86-
<img src="images/a2a_ui.jpg" alt="A2A UI" width="600">
87-
88-
## Contributors
89-
90-
[![Embabel contributors](https://contrib.rocks/image?repo=embabel/java-agent-template)](https://github.com/embabel/java-agent-template/graphs/contributors)
91-
19+
# Talk to the Docs

pom.xml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
<version>3.5.3</version>
1010
<relativePath/> <!-- Lookup parent from repository -->
1111
</parent>
12-
<groupId>com.embabel.template</groupId>
13-
<artifactId>ProjectName</artifactId>
12+
<groupId>com.embabel.agent</groupId>
13+
<artifactId>guide</artifactId>
1414
<version>0.1.0-SNAPSHOT</version>
1515
<packaging>jar</packaging>
16-
<name>My first agent</name>
17-
<description>Generated agent project</description>
16+
<name>Talk to the docs</name>
17+
<description>Embabel talk to the docs</description>
1818

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

2424
<dependencies>
@@ -30,6 +30,18 @@
3030
<version>${embabel-agent.version}</version>
3131
</dependency>
3232

33+
<dependency>
34+
<groupId>com.embabel.agent</groupId>
35+
<artifactId>embabel-agent-starter-shell</artifactId>
36+
<version>${embabel-agent.version}</version>
37+
</dependency>
38+
39+
<dependency>
40+
<groupId>com.embabel.agent</groupId>
41+
<artifactId>embabel-agent-rag-lucene</artifactId>
42+
<version>${embabel-agent.version}</version>
43+
</dependency>
44+
3345
<dependency>
3446
<groupId>com.embabel.agent</groupId>
3547
<artifactId>embabel-agent-test</artifactId>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424

2525
@SpringBootApplication
2626
@EnableAgentShell
27-
@EnableAgents(loggingTheme = LoggingThemes.STAR_WARS)
28-
class ProjectNameApplication {
27+
@EnableAgents(loggingTheme = LoggingThemes.SEVERANCE)
28+
class GuideApplication {
2929
public static void main(String[] args) {
30-
SpringApplication.run(ProjectNameApplication.class, args);
30+
SpringApplication.run(GuideApplication.class, args);
3131
}
3232
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.embabel.guide;
2+
3+
import com.embabel.agent.api.common.Ai;
4+
import com.embabel.agent.rag.Ingester;
5+
import com.embabel.chat.ChatSession;
6+
import org.slf4j.Logger;
7+
import org.slf4j.LoggerFactory;
8+
import org.springframework.stereotype.Service;
9+
10+
@Service
11+
public class ConversationManager {
12+
13+
private final Ai ai;
14+
private final Ingester ingester;
15+
16+
private final Logger logger = LoggerFactory.getLogger(ConversationManager.class);
17+
18+
public ConversationManager(
19+
Ai ai,
20+
Ingester ingester) {
21+
this.ingester = ingester;
22+
this.ai = ai;
23+
var ingestionResult = ingester.ingest("data/index.md");
24+
logger.info("Ingestion result: {}", ingestionResult);
25+
}
26+
27+
public ChatSession guide() {
28+
return new Guide(ai);
29+
}
30+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.embabel.guide;
2+
3+
import com.embabel.agent.api.common.Ai;
4+
import com.embabel.agent.rag.tools.RagOptions;
5+
import com.embabel.chat.*;
6+
import org.jetbrains.annotations.NotNull;
7+
8+
/**
9+
* GuideLoader will have loaded content
10+
*/
11+
public class Guide implements ChatSession {
12+
13+
private final Ai ai;
14+
15+
private Conversation conversation = new InMemoryConversation();
16+
17+
public Guide(Ai ai) {
18+
this.ai = ai;
19+
}
20+
21+
@NotNull
22+
@Override
23+
public Conversation getConversation() {
24+
return conversation;
25+
}
26+
27+
@Override
28+
public void respond(@NotNull UserMessage userMessage, @NotNull MessageListener messageListener) {
29+
conversation = conversation.withMessage(userMessage);
30+
final var assistantMessage = ai
31+
.withLlmByRole("docs")
32+
.withRagTools(new RagOptions().withSimilarityThreshold(.0).withTopK(8))
33+
.withTemplate("guide_system")
34+
.respondWithSystemPrompt(conversation);
35+
conversation = conversation.withMessage(assistantMessage);
36+
messageListener.onMessage(assistantMessage);
37+
}
38+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.embabel.guide;
2+
3+
import com.embabel.agent.event.logging.personality.severance.LumonColorPalette;
4+
import com.embabel.agent.shell.TerminalServices;
5+
import org.springframework.shell.standard.ShellComponent;
6+
import org.springframework.shell.standard.ShellMethod;
7+
8+
@ShellComponent
9+
public class GuideShell {
10+
11+
private final TerminalServices terminalServices;
12+
private final ConversationManager conversationManager;
13+
14+
public GuideShell(
15+
ConversationManager conversationManager,
16+
TerminalServices terminalServices) {
17+
this.conversationManager = conversationManager;
18+
this.terminalServices = terminalServices;
19+
}
20+
21+
@ShellMethod("talk to docs")
22+
public String talk() {
23+
var guide = conversationManager.guide();
24+
return terminalServices.chat(
25+
guide,
26+
"Welcome to the Guide! How can I assist you today?",
27+
LumonColorPalette.INSTANCE);
28+
}
29+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.embabel.guide;
2+
3+
import com.embabel.agent.rag.RagService;
4+
import com.embabel.agent.rag.lucene.LuceneRagService;
5+
import org.springframework.context.annotation.Bean;
6+
import org.springframework.context.annotation.Configuration;
7+
8+
@Configuration
9+
class RagConfig {
10+
11+
@Bean
12+
RagService ragService() {
13+
return new LuceneRagService(
14+
"docs",
15+
"data/index.md"
16+
);
17+
}
18+
}

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

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

0 commit comments

Comments
 (0)