Skip to content

Commit 2efebab

Browse files
committed
Disambiguate classes
1 parent 586746a commit 2efebab

File tree

9 files changed

+86
-61
lines changed

9 files changed

+86
-61
lines changed

examples-java/README.md

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# Java Examples
22

3-
This module contains Java implementations of Embabel Agent examples, demonstrating enterprise Java patterns and Spring Boot best practices.
3+
This module contains Java implementations of Embabel Agent examples, demonstrating enterprise Java patterns and Spring
4+
Boot best practices.
45

56
## 🚀 Quick Start
67

78
### Prerequisites
9+
810
- Java 21+
911
- Maven 3.9+
1012
- API Keys: `OPENAI_API_KEY` or `ANTHROPIC_API_KEY`
@@ -23,7 +25,7 @@ cd ../scripts/java
2325
shell.cmd --docker-tools # Windows
2426

2527
# Or run directly with Maven
26-
mvn spring-boot:run -Dspring-boot.run.main-class=com.embabel.example.AgentShellApplication
28+
mvn spring-boot:run -Dspring-boot.run.main-class=com.embabel.example.JavaAgentShellApplication
2729
```
2830

2931
## 📂 Project Structure
@@ -45,16 +47,19 @@ examples-java/
4547
## 🎯 Available Example
4648

4749
### **Horoscope News Finder** (Beginner-Friendly)
50+
4851
Find personalized news based on someone's zodiac sign, combining horoscope readings with current events.
4952

5053
**Key Concepts:**
54+
5155
- `@Agent` and `@Action` annotations
5256
- Spring dependency injection
5357
- LLM integration for data extraction
5458
- Web tool usage for news searches
5559
- Goal-oriented workflows
5660

5761
**Implementation Highlights:**
62+
5863
```java
5964
@Agent(description = "Finds personalized news based on zodiac signs")
6065
@Component
@@ -81,6 +86,7 @@ public class StarNewsFinder {
8186
```
8287

8388
**Try it:**
89+
8490
```
8591
shell:> execute "Find horoscope news for Bob who is a Scorpio"
8692
shell:> execute "What's in the stars for Alice today? She's a Gemini"
@@ -89,13 +95,15 @@ shell:> execute "What's in the stars for Alice today? She's a Gemini"
8995
## 🛠️ Configuration
9096

9197
### API Keys
98+
9299
```bash
93100
export OPENAI_API_KEY="your-openai-key"
94101
# or
95102
export ANTHROPIC_API_KEY="your-anthropic-key"
96103
```
97104

98105
### Application Configuration
106+
99107
```yaml
100108
# application.yml
101109
embabel:
@@ -113,6 +121,7 @@ spring:
113121
### Interactive Shell (Development)
114122
115123
**Basic Shell Mode:**
124+
116125
```java
117126
import com.embabel.agent.config.annotation.LoggingThemes;
118127

@@ -127,18 +136,21 @@ public class AgentShellApplication {
127136
```
128137

129138
Features:
139+
130140
- Command-line interface for testing
131141
- Star Wars themed logging messages
132142
- Real-time execution feedback
133143
- Debug options with `-p` and `-r` flags
134144

135145
**Shell with Docker Integration:**
146+
136147
```java
148+
137149
@SpringBootApplication
138150
@EnableAgentShell
139151
@EnableAgents(
140-
loggingTheme = LoggingThemes.STAR_WARS,
141-
mcpServers = {McpServers.DOCKER_DESKTOP}
152+
loggingTheme = LoggingThemes.STAR_WARS,
153+
mcpServers = {McpServers.DOCKER_DESKTOP}
142154
)
143155
public class AgentShellMcpClientApplication {
144156
public static void main(String[] args) {
@@ -148,12 +160,14 @@ public class AgentShellMcpClientApplication {
148160
```
149161

150162
Features:
163+
151164
- All basic shell features
152165
- Docker Desktop MCP integration
153166
- Container execution capabilities
154167
- Enhanced tool access
155168

156169
### MCP Server (Integration)
170+
157171
```java
158172
@SpringBootApplication
159173
@EnableAgentMcpServer
@@ -166,6 +180,7 @@ public class AgentMcpApplication {
166180
```
167181

168182
Features:
183+
169184
- JSON-RPC server implementation
170185
- Claude Desktop compatibility
171186
- Docker integration support
@@ -174,6 +189,7 @@ Features:
174189
## 💡 Java Implementation Patterns
175190

176191
### Spring Dependency Injection
192+
177193
```java
178194
@Component
179195
public class StarNewsFinder {
@@ -187,6 +203,7 @@ public class StarNewsFinder {
187203
```
188204

189205
### Domain Models with Validation
206+
190207
```java
191208
public class StarPerson extends Person {
192209
@NotNull
@@ -200,6 +217,7 @@ public class StarPerson extends Person {
200217
```
201218

202219
### Builder Pattern for Complex Objects
220+
203221
```java
204222
public class Writeup {
205223
private final String title;
@@ -214,6 +232,7 @@ public class Writeup {
214232
```
215233

216234
### Service Layer Abstraction
235+
217236
```java
218237
@Service
219238
public class HoroscopeService {
@@ -236,6 +255,7 @@ mvn test -Dtest=StarNewsFinderTest
236255
```
237256

238257
### Test Structure
258+
239259
```java
240260
@SpringBootTest
241261
@AutoConfigureMockMvc
@@ -253,23 +273,23 @@ class StarNewsFinderTest {
253273

254274
## 🐛 Troubleshooting
255275

256-
| Issue | Solution |
257-
|-------|----------|
258-
| `No API key found` | Set `OPENAI_API_KEY` or `ANTHROPIC_API_KEY` environment variable |
259-
| `ClassNotFoundException` | Run `mvn clean install` from project root |
260-
| `Port already in use` | Change port with `--server.port=8081` |
261-
| `Bean creation error` | Check Spring profile configuration |
262-
| `WARNING: Only Basic Agent features` | Use `--docker-tools` parameter to enable Docker integration |
276+
| Issue | Solution |
277+
|--------------------------------------|------------------------------------------------------------------|
278+
| `No API key found` | Set `OPENAI_API_KEY` or `ANTHROPIC_API_KEY` environment variable |
279+
| `ClassNotFoundException` | Run `mvn clean install` from project root |
280+
| `Port already in use` | Change port with `--server.port=8081` |
281+
| `Bean creation error` | Check Spring profile configuration |
282+
| `WARNING: Only Basic Agent features` | Use `--docker-tools` parameter to enable Docker integration |
263283

264284
## 📊 Comparison with Kotlin Examples
265285

266-
| Feature | Java | Kotlin |
267-
|---------|------|--------|
268-
| **Code Style** | Verbose, explicit | Concise, expressive |
269-
| **Null Safety** | Manual checks | Built-in null safety |
270-
| **Async Support** | CompletableFuture | Coroutines |
271-
| **Data Classes** | Lombok/Records | Native data classes |
272-
| **DSL Support** | Builder pattern | Native DSL support |
286+
| Feature | Java | Kotlin |
287+
|-------------------|-------------------|----------------------|
288+
| **Code Style** | Verbose, explicit | Concise, expressive |
289+
| **Null Safety** | Manual checks | Built-in null safety |
290+
| **Async Support** | CompletableFuture | Coroutines |
291+
| **Data Classes** | Lombok/Records | Native data classes |
292+
| **DSL Support** | Builder pattern | Native DSL support |
273293

274294
## 🎓 Learning Resources
275295

@@ -281,6 +301,7 @@ class StarNewsFinderTest {
281301
## 🤝 Contributing
282302

283303
When adding new Java examples:
304+
284305
1. Follow Java naming conventions
285306
2. Use meaningful variable and method names
286307
3. Add comprehensive JavaDoc

examples-java/pom.xml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
<artifactId>example-agent-java</artifactId>
1212
<name>Embabel Agent Java Examples</name>
1313
<description>Java Examples for Embabel Agentic Flows</description>
14+
<properties>
15+
<spring-shell-standard.version>3.4.0</spring-shell-standard.version>
16+
</properties>
17+
1418

1519
<dependencies>
1620

@@ -20,6 +24,12 @@
2024
<version>${project.version}</version>
2125
</dependency>
2226

27+
<dependency>
28+
<groupId>org.springframework.shell</groupId>
29+
<artifactId>spring-shell-standard</artifactId>
30+
<version>${spring-shell-standard.version}</version>
31+
</dependency>
32+
2333
<!-- Test Dependencies -->
2434
<dependency>
2535
<groupId>com.embabel.agent</groupId>
@@ -57,7 +67,7 @@
5767
<groupId>org.springframework.boot</groupId>
5868
<artifactId>spring-boot-maven-plugin</artifactId>
5969
<configuration>
60-
<mainClass>com.embabel.example.AgentShellApplication</mainClass>
70+
<mainClass>com.embabel.example.JavaAgentShellApplication</mainClass>
6171
</configuration>
6272
<version>${spring-boot.version}</version>
6373
</plugin>
@@ -81,7 +91,7 @@
8191
<groupId>org.springframework.boot</groupId>
8292
<artifactId>spring-boot-maven-plugin</artifactId>
8393
<configuration>
84-
<mainClass>com.embabel.example.AgentShellMcpClientApplication</mainClass>
94+
<mainClass>com.embabel.example.JavaAgentShellMcpClientApplication</mainClass>
8595
</configuration>
8696
<version>${spring-boot.version}</version>
8797
</plugin>
@@ -105,7 +115,7 @@
105115
<groupId>org.springframework.boot</groupId>
106116
<artifactId>spring-boot-maven-plugin</artifactId>
107117
<configuration>
108-
<mainClass>com.embabel.example.AgentMcpServerApplication</mainClass>
118+
<mainClass>com.embabel.example.JavaMcpServerApplication</mainClass>
109119
</configuration>
110120
<version>${spring-boot.version}</version>
111121
</plugin>

examples-java/src/main/java/com/embabel/example/AgentShellApplication.java renamed to examples-java/src/main/java/com/embabel/example/JavaAgentShellApplication.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
loggingTheme = LoggingThemes.SEVERANCE,
4242
mcpServers = {McpServers.DOCKER_DESKTOP}
4343
)
44-
public class AgentShellApplication {
44+
public class JavaAgentShellApplication {
4545

4646
/**
4747
* Application entry point.
@@ -52,6 +52,6 @@ public class AgentShellApplication {
5252
* @param args command line arguments passed to the application
5353
*/
5454
public static void main(String[] args) {
55-
SpringApplication.run(AgentShellApplication.class, args);
55+
SpringApplication.run(JavaAgentShellApplication.class, args);
5656
}
5757
}

examples-java/src/main/java/com/embabel/example/AgentShellMcpClientApplication.java renamed to examples-java/src/main/java/com/embabel/example/JavaAgentShellMcpClientApplication.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
loggingTheme = LoggingThemes.STAR_WARS,
4141
mcpServers = {McpServers.DOCKER_DESKTOP}
4242
)
43-
public class AgentShellMcpClientApplication {
43+
public class JavaAgentShellMcpClientApplication {
4444

4545
/**
4646
* Application entry point.
@@ -51,6 +51,6 @@ public class AgentShellMcpClientApplication {
5151
* @param args command line arguments passed to the application
5252
*/
5353
public static void main(String[] args) {
54-
SpringApplication.run(AgentShellMcpClientApplication.class, args);
54+
SpringApplication.run(JavaAgentShellMcpClientApplication.class, args);
5555
}
5656
}

examples-java/src/main/java/com/embabel/example/AgentMcpServerApplication.java renamed to examples-java/src/main/java/com/embabel/example/JavaMcpServerApplication.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,37 @@
1515
*/
1616
package com.embabel.example;
1717

18+
import com.embabel.agent.config.annotation.EnableAgents;
1819
import com.embabel.agent.config.annotation.McpServers;
1920
import org.springframework.boot.SpringApplication;
2021
import org.springframework.boot.autoconfigure.SpringBootApplication;
21-
import com.embabel.agent.config.annotation.EnableAgentMcpServer;
22-
import com.embabel.agent.config.annotation.EnableAgents;
2322

2423
/**
2524
* Spring Boot application that runs Embabel agents as an MCP (Model Context Protocol) server.
26-
*
25+
*
2726
* <p>This application exposes your agents as MCP-compatible tools that can be consumed by
2827
* AI assistants like Claude Desktop, development environments with MCP support, or other
2928
* MCP-compliant clients. It also enables Docker Desktop integration for containerized
3029
* tool execution.
31-
*
32-
* @since 1.0
30+
*
3331
* @author Embabel Team
32+
* @since 1.0
3433
*/
3534
@SpringBootApplication
3635
@EnableAgents(
37-
mcpServers = {McpServers.DOCKER_DESKTOP}
36+
mcpServers = {McpServers.DOCKER_DESKTOP}
3837
)
39-
public class AgentMcpServerApplication {
40-
38+
public class JavaMcpServerApplication {
39+
4140
/**
4241
* Application entry point.
43-
*
42+
*
4443
* <p>Starts the Spring Boot application with MCP server capabilities and
4544
* Docker Desktop integration enabled.
46-
*
45+
*
4746
* @param args command line arguments passed to the application
4847
*/
4948
public static void main(String[] args) {
50-
SpringApplication.run(AgentMcpServerApplication.class, args);
49+
SpringApplication.run(JavaMcpServerApplication.class, args);
5150
}
5251
}

0 commit comments

Comments
 (0)