You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# gemini-java-client: The Autonomous AI Agent Engine for the JVM
6
6
7
7
**[Website](https://anahata-os.github.io/gemini-java-client/) | [Anahata TV (YouTube)](https://www.youtube.com/@anahata108) | [Discord](https://discord.gg/M396BNtX) | [v2 on its way!](https://github.com/anahata-os/anahata-asi)**
**The engine for Autonomous JVM Agents.** The `gemini-java-client` is a pure-Java platform specially engineered to exploit the full power of the **Google Gemini API**. It provides the infrastructure for an AI to write, compile, and execute Java code in-process, turning your application into a host for autonomous agents that don't just suggest code—they **live inside your JVM**.
11
+
**Stop building chatbots. Start spawning Agents.**
12
+
The `gemini-java-client` is a pure-Java engine specially engineered to exploit the full power of the **Google Gemini API**. It provides the infrastructure for an AI to inhabit your runtime, introspect your memory, and execute code in-process. It's the first framework that turns your application into a living, breathing host for autonomous agents that don't just suggest code—they **live inside your JVM**.
13
+
14
+
---
12
15
13
16
## 🚀 The Killer Advantage: Autonomous JVM Execution
14
17
15
18
While other AI tools are external observers, Anahata is an **insider**. It operates as an autonomous agent within your application's runtime, capable of executing any Java logic with any required classpath.
16
19
17
-
### The "Any Classpath" Superpower
20
+
### The "Any Framework" Superpower
18
21
The agent isn't restricted to the libraries already in your project. It can:
19
22
1.**Identify** a need for a specific library (e.g., Apache Commons, Jackson, or a specialized MIDI API).
20
-
2.**Download** the JARs from Maven Central at runtime.
23
+
2.**Download** the JARs from Maven Central or any other website at runtime.
21
24
3.**Compile** a Java class (`Anahata.java`) that implements `java.util.concurrent.Callable`.
22
25
4.**Execute** the logic directly within the running JVM.
26
+
5.**Augment** the runtime with external JARs or directories on any turn via the `extraClassPath` parameter.
Turn any Java method into a powerful, AI-callable function with a single annotation. The framework handles asynchronous execution and complex parameter mapping automatically.
34
+
35
+
```java
36
+
publicclassPianoTool {
37
+
@AIToolMethod("Plays a simple melody from a list of notes asynchronously.")
38
+
publicstaticStringplayMelody(
39
+
@AIToolParam("A list of notes to play.") List<Note>notes
40
+
) {
41
+
// Asynchronous MIDI playback logic...
42
+
pianoExecutor.submit(() -> {
43
+
// ...
44
+
});
45
+
return"Melody playback started.";
46
+
}
47
+
}
48
+
```
49
+
50
+
### 2. Easy POJOs & Schema Generation
51
+
Use standard `@Schema` annotations to provide the AI with deep structural understanding of your data models. The framework uses Jackson to generate precise JSON schemas and supports **custom Jackson modules** for advanced Java-to-JSON translation.
52
+
53
+
```java
54
+
@Getter
55
+
@AllArgsConstructor
56
+
@Schema(description="A POJO holding file metadata and content, used for context-aware file operations.")
57
+
publicclassFileInfoimplementsStatefulResource {
58
+
59
+
@Schema(description="The absolute path to the file.")
60
+
String path;
61
+
62
+
@Schema(description="The text content of the file.")
63
+
String content;
64
+
65
+
@Schema(description="The total number of lines of this file.")
66
+
long contentLines;
67
+
// ...
68
+
}
69
+
```
70
+
71
+
---
23
72
24
-
## 🏠 Real-World Agency: Beyond the IDE
73
+
## 🏠 Real-World Agency: The Hardware Orchestrator
25
74
26
-
Because the agent has full access to the host's shell and network, it can interact with the physical world. It's not just a coding assistant; it's a **Hardware Orchestrator**.
75
+
Because the agent has full access to the host's shell and network, it can bridge the gap between LLM logic and physical hardware.
27
76
28
77
### 🎯 Prompts that prove the power:
29
-
-**"Explore my LAN and find any Smart TVs connected to the network."** (Network discovery)
30
-
-**"Take a screenshot of the Lounge TV and show it to me."** (Remote device introspection via ADB)
31
-
-**"Turn down the volume on the TV and play a Gal Gadot video."** (IoT control)
32
-
-**"Perform a security assessment of my network and find open ports on local devices."** (Security auditing)
78
+
-**"Change the logging level of 'org.apache.http' to DEBUG and show me the logs."** (Runtime Introspection)
79
+
-**"Perform a thread dump, analyze it, and look for any potential deadlocks."** (Diagnostic Agency)
80
+
-**"Take a heap dump, download Eclipse MAT from Maven, and perform a leak analysis."** (Dynamic Tooling)
81
+
-**"Set the context window threshold to 200K tokens and prune aggressively as you go."** (Context Management)
82
+
-**"Scan the JVM for all loaded classes that implement 'java.io.Serializable' but lack a 'serialVersionUID'."** (Deep Introspection)
83
+
-**"Explore my LAN, find the TCL TV, turn down the volume, and play a Gal Gadot video."** (IoT Orchestration)
84
+
85
+
---
33
86
34
87
## 🖼️ Visual Showcase
35
88
@@ -43,58 +96,40 @@ Because the agent has full access to the host's shell and network, it can intera
Our core innovation is the **annotation-driven local tool system**, which transforms your Java methods into powerful, AI-callable functions.
103
+
### 1. The Butler Principle (Safety First)
104
+
Anahata operates with the precision and discretion of the world's best butler. It never acts without your **explicit consent**. Every tool call is visible, confirmable, and reversible.
61
105
62
-
| Feature | Description | Benefit |
63
-
| :--- | :--- | :--- |
64
-
|**`@AIToolMethod`**| Define tools using simple Java annotations. |**Zero boilerplate** for API schema generation. |
65
-
|**Dynamic Code Execution (`RunningJVM`)**| The AI can compile and execute arbitrary Java code directly within the host JVM. | Enables **hot-reload** development and complex calculations. |
66
-
|**JIT & Maven Integration**| Download and use any library from Maven at runtime. |**Infinite extensibility** for your AI assistant. |
67
-
|**Context-Aware File I/O (`LocalFiles`)**| Tools for reading, writing, and managing files with built-in version checks. | Ensures the AI always works with **valid, up-to-date** local files. |
68
-
|**Shell Access (`LocalShell`)**| Execute native shell commands (`bash -c`) and capture output. | Provides **full control** over the host operating system and network. |
106
+
### 2. Natural Language Context Management
107
+
Stop worrying about token limits. Both the user and the model can manage the context window using natural language.
108
+
*"Prune the last 5 tool responses but keep the summary of the analysis."* — **Done.**
69
109
70
-
### 2. Superior Context & Session Management
110
+
### 3. Pure Java, Zero Friction
111
+
-**Embeddable Swing UI**: Drop the `ChatPanel` into any Swing app.
112
+
-**Session Persistence**: Fast Kryo serialization to resume conversations instantly.
113
+
-**PAYG v2 Pruning**: AI-driven context management for infinite conversations.
71
114
72
-
We solve the token limit problem with intelligent, dependency-aware context management.
73
-
74
-
| Feature | Description | Benefit |
75
-
| :--- | :--- | :--- |
76
-
|**Prune-As-You-Go (PAYG) v2**| Automatically removes old or stale tool calls and responses. |**Maximizes context window** efficiency and reduces costs. |
77
-
|**Stateful Resource Tracking**| Tracks resources loaded into context, marking them as `STALE` if changed on disk. |**Prevents the AI from working with outdated information.**|
78
-
|**Session Persistence (Kryo)**| Saves and loads the entire chat history using fast Kryo serialization. |**Instant session resume** across application restarts. |
115
+
---
79
116
80
117
## Getting Started: Simple Integration
81
118
82
-
Integrating the AI agent into your Java application is now easier than ever.
83
-
84
119
```java
85
120
importuno.anahata.ai.swing.ChatPanel;
86
121
importjavax.swing.JFrame;
87
122
88
123
publicclassSimpleAiApp {
89
124
publicstaticvoidmain(String[] args) {
90
-
JFrame frame =newJFrame("My AI App");
125
+
JFrame frame =newJFrame("Anahata AI Agent");
91
126
92
127
// 1. Create the ChatPanel (zero boilerplate!)
93
128
ChatPanel chatPanel =newChatPanel();
94
129
95
130
// 2. Build the UI and add to frame
96
131
frame.add(chatPanel);
97
-
frame.setSize(800, 600);
132
+
frame.setSize(1024, 768);
98
133
frame.setVisible(true);
99
134
100
135
// 3. Start the session
@@ -107,11 +142,14 @@ public class SimpleAiApp {
107
142
108
143
## Support the Project
109
144
110
-
-**[Sponsor on GitHub](https://github.com/sponsors/anahata-os):**The most direct way to support the project.
145
+
-**[Sponsor on GitHub](https://github.com/sponsors/anahata-os):**Help us keep the engine running!
<p>The core <code>RunningJVM</code> tool allows the AI Agent to pull <strong>any Java framework in existence</strong> from Maven Central at runtime and execute LLM-generated code immediately.</p>
112
+
<p>The core <code>RunningJVM</code> tool allows the AI Agent to pull <strong>any Java framework in existence</strong> from Maven Central or any other website at runtime and execute LLM-generated code immediately.</p>
<liclass="prompt-item" style="border-left-color: var(--barca-gold);">"Change the logging level of 'org.apache.http' to DEBUG and show me the logs."</li>
125
125
<liclass="prompt-item" style="border-left-color: var(--barca-gold);">"Perform a thread dump, analyze it, and look for any potential deadlocks."</li>
126
126
<liclass="prompt-item" style="border-left-color: var(--barca-gold);">"Take a heap dump, download Eclipse MAT from Maven, and perform a leak analysis."</li>
127
-
<liclass="prompt-item" style="border-left-color: var(--barca-gold);">"Prune anything related to the heap dump and give me a breakdown of the context window."</li>
127
+
<liclass="prompt-item" style="border-left-color: var(--barca-gold);">"Set the context window threshold to 200K tokens and prune aggressively as you go."</li>
128
128
<liclass="prompt-item" style="border-left-color: var(--barca-gold);">"Scan the JVM for all loaded classes that implement 'java.io.Serializable' but lack a 'serialVersionUID'."</li>
129
129
<liclass="prompt-item" style="border-left-color: var(--barca-gold);">"Write a Swing script to visualize the current memory usage in a real-time chart."</li>
0 commit comments