Skip to content

Commit e3e2161

Browse files
Merge pull request #453 from bernardladenthin/agent-readme-getting-started
llama-atmosphere-agent: document the from-scratch workflow
2 parents 438f831 + 2f9e4a0 commit e3e2161

3 files changed

Lines changed: 97 additions & 12 deletions

File tree

‎.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ hs_err_pid*
4343
replay_pid*
4444

4545
models/*.gguf
46+
# the agent README downloads its model next to the agent: llama-atmosphere-agent/models/
47+
llama-atmosphere-agent/models/*.gguf
4648
llama/src/main/cpp/net_ladenthin_llama_*.h
4749
llama/src/main/resources_linux_cuda/
4850
# Per-classifier native trees, staged by CI before the matching Maven profile runs,

‎README.md‎

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,12 +1026,35 @@ essentials, fully offline; it edits files and, with `--allow-shell`, runs any co
10261026
(`docker`, `git`, build tools) — built from [Atmosphere](https://github.com/Atmosphere/atmosphere)'s
10271027
built-in OpenAI-compatible agent runtime (streaming, tool loop, workspace file tools) driven
10281028
**headless** against this project's OpenAI-compatible server. It is a standalone Maven project (not a
1029-
reactor module, not published); you copy the folder and run it. With java-llama.cpp already running
1030-
(`--jinja` is required for tool calling):
1029+
reactor module, not published); you clone the repository and run it from that folder. It needs only
1030+
JDK 21+ and Maven — the core jar from Maven Central ships the natives:
1031+
1032+
```bash
1033+
# get the folder and a tool-capable model (Qwen3-4B-Instruct-2507, 2.3 GB)
1034+
git clone --depth 1 https://github.com/bernardladenthin/java-llama.cpp.git
1035+
cd java-llama.cpp/llama-atmosphere-agent
1036+
curl -L --create-dirs -o models/Qwen3-4B-Instruct-2507-Q4_K_M.gguf \
1037+
https://huggingface.co/unsloth/Qwen3-4B-Instruct-2507-GGUF/resolve/main/Qwen3-4B-Instruct-2507-Q4_K_M.gguf
1038+
1039+
# the agent with the model loaded in-process — a you> prompt appears (/clear, /exit)
1040+
mvn -q compile exec:java \
1041+
-Dexec.args="--model models/Qwen3-4B-Instruct-2507-Q4_K_M.gguf --ctx-size 16384 --workspace /path/to/project --allow-shell"
1042+
```
1043+
1044+
> [!WARNING]
1045+
> With `--allow-shell` the model runs any command it decides to run, with your user's rights and
1046+
> without asking. Use a machine and a workspace you are willing to hand to the model.
1047+
1048+
On Windows PowerShell quote the whole argument (`"-Dexec.args=--model models\… --allow-shell"`); for
1049+
the GPU add e.g. `-Dllama.classifier=vulkan-windows-x86-64` and `--ngl 99`. The agent's
1050+
[README](llama-atmosphere-agent/) walks through all of it step by step. Other ways to run it, e.g.
1051+
against a java-llama.cpp server that is already running (`--jinja` is required for tool calling;
1052+
the fat jars are [GitHub release](https://github.com/bernardladenthin/java-llama.cpp/releases) assets,
1053+
`llama-<version>-all-<os>-<arch>-jar-with-dependencies.jar` picks a GPU backend itself):
10311054

10321055
```bash
10331056
# 1. the server, e.g. from the release fat jar
1034-
java -jar llama-5.2.0-jar-with-dependencies.jar -m /models/Qwen2.5-7B-Instruct-Q4_K_M.gguf --jinja --port 8080
1057+
java -jar llama-5.2.0-jar-with-dependencies.jar -m models/Qwen3-4B-Instruct-2507-Q4_K_M.gguf --jinja --port 8080
10351058

10361059
# 2. the agent, from the llama-atmosphere-agent/ folder — a you> prompt appears (/clear, /exit)
10371060
mvn -q compile exec:java \
@@ -1043,11 +1066,11 @@ mvn -q compile exec:java \
10431066

10441067
# or without a separate server: load the GGUF in-process
10451068
mvn -q compile exec:java \
1046-
-Dexec.args="--model /models/Qwen2.5-7B-Instruct-Q4_K_M.gguf --ngl 99 --workspace /path/to/project"
1069+
-Dexec.args="--model models/Qwen3-4B-Instruct-2507-Q4_K_M.gguf --ngl 99 --workspace /path/to/project"
10471070

10481071
# everything at once: shell access plus your own system prompt (replaces the built-in one)
10491072
mvn -q compile exec:java \
1050-
-Dexec.args="--model /models/Qwen3-4B-Instruct-2507-Q4_K_M.gguf --ngl 99 --ctx-size 16384 --workspace /path/to/project --allow-shell --system 'You are a local assistant on this machine with full shell access. run_command executes any command line, including docker, git and build tools. When asked about the system, run a command instead of explaining it. Answer in the language of the user.'"
1073+
-Dexec.args="--model models/Qwen3-4B-Instruct-2507-Q4_K_M.gguf --ngl 99 --ctx-size 16384 --workspace /path/to/project --allow-shell --system 'You are a local assistant on this machine with full shell access. run_command executes any command line, including docker, git and build tools. When asked about the system, run a command instead of explaining it. Answer in the language of the user.'"
10511074
```
10521075

10531076
The full streaming tool-calling loop (tools → `delta.tool_calls` → Java tool → `role:"tool"` result →

‎llama-atmosphere-agent/README.md‎

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,74 @@ published: CI builds and tests it against the core of the same checkout; you cop
2626
run it. Its `pom.xml` pins `llama.version` to the release these instructions describe (**5.2.0**);
2727
pass `-Dllama.version=…` to run against another core, e.g. a `-SNAPSHOT` before a release.
2828

29-
## Quick start
29+
> [!WARNING]
30+
> With `--allow-shell` the model runs **any** command it decides to run, with **your** user's
31+
> rights, without asking — deleting files, pushing to git, stopping containers included. Start it on
32+
> a machine and account you are willing to hand to the model, and point `--workspace` at a copy of
33+
> a project, not your only one. Without the flag it can only use the file tools inside `--workspace`.
34+
35+
## Getting started from scratch
36+
37+
You need **JDK 21+** and **Maven** (`mvn -v` must report Java 21 or newer). No C++ toolchain, no
38+
CMake and no separate llama.cpp install: the core jar from Maven Central ships the native libraries
39+
for Windows, Linux and macOS.
40+
41+
**1. Get this folder.** It is not published as an artifact; clone the repository (or download it
42+
as a ZIP from GitHub) and work in `llama-atmosphere-agent/`. The folder is self-contained — you can
43+
copy it anywhere, `.mvn/jvm.config` included:
44+
45+
```bash
46+
git clone --depth 1 https://github.com/bernardladenthin/java-llama.cpp.git
47+
cd java-llama.cpp/llama-atmosphere-agent
48+
```
49+
50+
**2. Get a model.** Any tool-capable instruct GGUF works; a fast default that fits an 8 GB GPU with a
51+
16k context is Qwen3-4B-Instruct-2507 (2.3 GB):
52+
53+
```bash
54+
curl -L --create-dirs -o models/Qwen3-4B-Instruct-2507-Q4_K_M.gguf \
55+
https://huggingface.co/unsloth/Qwen3-4B-Instruct-2507-GGUF/resolve/main/Qwen3-4B-Instruct-2507-Q4_K_M.gguf
56+
```
3057

31-
Requirements: JDK 21+ and Maven. No native toolchain: the core jar ships the natives.
58+
**3. Start the agent.** The first run downloads `net.ladenthin:llama` and Atmosphere from Maven
59+
Central; then a `you>` prompt appears (`/clear` drops the history, `/exit` quits).
60+
61+
Linux / macOS:
62+
63+
```bash
64+
mvn -q compile exec:java \
65+
-Dexec.args="--model models/Qwen3-4B-Instruct-2507-Q4_K_M.gguf --ctx-size 16384 --workspace /path/to/project --allow-shell"
66+
```
67+
68+
Windows (PowerShell — quote the whole `-D` argument, no line continuation with `\`):
69+
70+
```powershell
71+
mvn -q compile exec:java "-Dexec.args=--model models\Qwen3-4B-Instruct-2507-Q4_K_M.gguf --ctx-size 16384 --workspace C:\path\to\project --allow-shell"
72+
```
73+
74+
**4. Optional: use the GPU.** Add a core classifier and offload the layers, e.g.
75+
`-Dllama.classifier=vulkan-windows-x86-64` (or `vulkan-linux-x86-64`; any current GPU driver) or
76+
`cuda13-linux-x86-64` (needs the CUDA 13 toolkit), plus `--ngl 99` inside `-Dexec.args`. macOS uses
77+
Metal with the default jar already. The root README's classifier table lists every backend.
78+
79+
## Quick start
3280

3381
**A. Against a java-llama.cpp server that is already running** (you keep every llama.cpp flag):
3482

35-
1. java-llama.cpp is running, for example started from the release fat jar like this
83+
1. java-llama.cpp is running, for example started from a release fat jar
3684
(`--jinja` is required for tool calling: it enables the model's tool-call chat template):
3785

3886
```bash
39-
java -jar llama-5.2.0-jar-with-dependencies.jar -m /models/Qwen2.5-7B-Instruct-Q4_K_M.gguf --jinja --port 8080
87+
java -jar llama-5.2.0-jar-with-dependencies.jar -m models/Qwen3-4B-Instruct-2507-Q4_K_M.gguf --jinja --port 8080
4088
```
4189

42-
Upstream `llama-server` with the same flags works too; any OpenAI-compatible endpoint does.
90+
The fat jars are assets of each [GitHub release](https://github.com/bernardladenthin/java-llama.cpp/releases):
91+
`llama-5.2.0-jar-with-dependencies.jar` runs on the CPU (and Metal on macOS);
92+
`llama-5.2.0-all-<os>-<arch>-jar-with-dependencies.jar` (`linux-x86-64`, `linux-aarch64`,
93+
`windows-x86-64`, `windows-aarch64`) additionally carries every GPU backend for that platform and
94+
uses the first one whose vendor runtime loads — CUDA, ROCm, SYCL, Vulkan, OpenCL, OpenVINO — falling
95+
back to the CPU; `-Dnet.ladenthin.llama.backend=vulkan` (or `cpu`) forces one. Upstream
96+
`llama-server` with the same flags works too; any OpenAI-compatible endpoint does.
4397

4498
2. Start the agent from this folder (`llama-atmosphere-agent/`):
4599

@@ -66,14 +120,14 @@ If the server was started with `--api-key <key>`, add `--api-key <key>` to the a
66120

67121
```bash
68122
mvn -q compile exec:java \
69-
-Dexec.args="--model /models/Qwen2.5-7B-Instruct-Q4_K_M.gguf --ngl 99 --workspace /path/to/project"
123+
-Dexec.args="--model models/Qwen3-4B-Instruct-2507-Q4_K_M.gguf --ngl 99 --workspace /path/to/project"
70124
```
71125

72126
**Everything at once — shell access and your own system prompt:**
73127

74128
```bash
75129
mvn -q compile exec:java \
76-
-Dexec.args="--model /models/Qwen3-4B-Instruct-2507-Q4_K_M.gguf --ngl 99 --ctx-size 16384 --workspace /path/to/project --allow-shell --system 'You are a local assistant on this machine with full shell access. run_command executes any command line, including docker, git and build tools. When asked about the system, run a command instead of explaining it. Read a file before you edit it. Answer in the language of the user.'"
130+
-Dexec.args="--model models/Qwen3-4B-Instruct-2507-Q4_K_M.gguf --ngl 99 --ctx-size 16384 --workspace /path/to/project --allow-shell --system 'You are a local assistant on this machine with full shell access. run_command executes any command line, including docker, git and build tools. When asked about the system, run a command instead of explaining it. Read a file before you edit it. Answer in the language of the user.'"
77131
```
78132

79133
Then ask, for example, *"which docker images are available?"* or *"build the project and fix the
@@ -209,5 +263,11 @@ starter are the *deployment* layer on top of the same runtime — not needed for
209263
- Tool rounds are not kept in the cross-turn history (only `user`/`assistant` text is replayed).
210264
- No approval prompts for destructive tools yet (`ToolDefinition.requiresApproval` exists in Atmosphere).
211265
- An engine error after the stream started ends the turn silently (see the table).
266+
- **One in-process agent per machine at a time.** The core extracts its native library to a fixed
267+
name (`jllama.dll` / `libjllama.so` in the temp directory); on Windows a second JVM cannot replace
268+
the file while the first one has it loaded, so a second `--model` agent fails at startup with
269+
`Failed to delete old native lib` followed by `No native library found`. Two in-process models
270+
also share the GPU's memory — a second 4B model on an 8 GB card can stall instead of failing.
271+
To run several agents, start one server (mode A) and point each agent at it with `--base-url`.
212272
- The Spring Boot `@Agent` + WebSocket/SSE UI variant is untested here; it uses the same runtime and
213273
the same `LLM_BASE_URL`, so it is expected to work but is not CI-covered.

0 commit comments

Comments
 (0)