Local AI Workbench — libargus + LangChain4j + Spring Boot
A tiny, production-grade Spring Boot 3.5 + LangChain4j 1.23.0 reference application demonstrating in-process local GGUF inference, incremental Server-Sent Events (SSE) token & separated <think> reasoning streaming, StreamingHandle.cancel() + cooperative C++ ArgusAbortFlag cancellation, opt-in Multimodal Vision (mmproj / ImageContent), opt-in Whisper ASR & Speech-LLM TTS, and exact BPE / vision-patch token budgeting—with zero Python sidecars, zero external daemons, and zero cloud API keys.
[!TIP]
Powered by libargus — an open-source, unmanaged C++17 native AI execution runtime engineered for zero-allocation steady-state inference across LLM text generation, bidirectional RAG embeddings, Whisper speech-to-text (ASR), text-to-speech (TTS), and Vision/Audio/Video multimodal pipelines.
Explore and star ProjectArgus-cc/libargus.cc for full documentation, EmbeddingModel / RAG cookbooks, Android/JNI guides, and low-level Java FFI references. See CHANGELOG.md for version-pinned release notes.
View High-Resolution Workbench Screenshot (2.4.0)
Capabilities at a Glance (2.4.0)
| Modality / Feature |
HTTP / SSE Surface |
LangChain4j 1.23.0 Adapter |
Activation |
| Chat & Incremental SSE Streaming |
POST /api/chat, POST /api/chat/stream |
LibArgusChatModel, LibArgusStreamingChatModel, LibArgusTokenCountEstimator |
ARGUS_CHAT_MODEL_PATH (required) |
Separated <think> Reasoning |
event: thinking SSE + thinking / thinkingDurationMs JSON |
.returnThinking(true) (PartialThinking + collapsible UI drawer) |
Enabled by default (ARGUS_RETURN_THINKING=true) |
| Dual Cooperative Cancellation |
POST /api/chat/stop + SSE disconnect |
StreamingHandle.cancel() ↔ ArgusAbortFlag.abort() |
Always active |
Multimodal Vision (mmproj) |
Inline Base64 images on /api/chat* (PNG/JPEG/WEBP/GIF/BMP) |
.mmprojPath(...) + Zero-Trust allowLocalFileMedia(false) (ImageContent) |
ARGUS_VISION_MMPROJ_PATH (opt-in) |
| Local Whisper ASR & Speech-LLM TTS |
POST /api/audio/transcribe, POST /api/audio/speech |
LibArgusAudioTranscriptionModel, LibArgusTextToSpeechModel |
ARGUS_ASR_MODEL_PATH, ARGUS_TTS_MODEL_PATH + ARGUS_TTS_VOCODER_PATH (opt-in) |
1. Copy-Paste Into Your Own Spring Boot Project
Want to embed in-process local GGUF, <think>, Vision, Whisper ASR, and TTS directly inside an existing Spring Boot 3.5 + LangChain4j 1.23.0 service? Here is the complete pattern:
Minimal pom.xml Dependencies
<properties>
<!-- Align Jackson with LangChain4j 1.23.0 (prevents Spring Boot 3.5 BOM downgrade to Jackson 2.19.x) -->
<jackson-bom.version>2.22.4</jackson-bom.version>
</properties>
<dependencies>
<!-- In-process LangChain4j ChatModel, StreamingChatModel, AudioTranscriptionModel, TextToSpeechModel & TokenCountEstimator -->
<dependency>
<groupId>cc.projectargus</groupId>
<artifactId>libargus-langchain4j</artifactId>
<version>2.4.0</version>
</dependency>
<!-- Choose libargus-core (JDK 22+/25 Panama FFM) OR libargus-jni (JDK 17+ / Android — 100% API parity) -->
<dependency>
<groupId>cc.projectargus</groupId>
<artifactId>libargus-jni</artifactId>
<version>2.4.0</version>
</dependency>
<!-- Precompiled native SPI provider (auto-extracts libargus at runtime; swap for cuda/metal/rocm/vulkan) -->
<dependency>
<groupId>cc.projectargus</groupId>
<artifactId>libargus-native-linux-cpu</artifactId>
<version>2.4.0</version>
<scope>runtime</scope>
</dependency>
</dependencies>
[!IMPORTANT]
Spring Boot 3.5 + LangChain4j 1.23.0 Jackson BOM Note: LangChain4j 1.23.0 compiles against Jackson 2.22.4 (jackson-annotations:2.22), whereas spring-boot-starter-parent:3.5.x manages Jackson 2.19.x by default. Setting <jackson-bom.version>2.22.4</jackson-bom.version> in <properties> keeps Maven dependency convergence clean with zero runtime NoSuchMethodError conflicts.
Minimal @Configuration Wiring Shared Model Weights, <think> & Optional Vision
@Configuration(proxyBeanMethods = false)
public class LocalAiConfig {
@Bean(destroyMethod = "close")
public ArgusModel argusModel(@Value("${argus.chat.model-path}") Path modelPath) {
ArgusBackend.init();
return ArgusModel.load(modelPath, /* gpuLayers */ 99, /* useMlock */ false);
}
@Bean(destroyMethod = "close")
public LibArgusStreamingChatModel streamingChatModel(
ArgusModel sharedModel,
@Value("${argus.vision.mmproj-path:}") String mmprojPath
) {
LibArgusStreamingChatModel.Builder builder = LibArgusStreamingChatModel.builder()
.model(sharedModel) // Shares weights; owns its KV cache context
.chatFormatter(LibArgusChatFormatter.autoDetect())
.returnThinking(true) // Separates <think>...</think> into PartialThinking
.contextLength(4096)
.maxOutputTokens(512);
if (!mmprojPath.isBlank()) {
builder
.mmprojPath(Path.of(mmprojPath)) // Opt-in multimodal vision projection
.allowLocalFileMedia(false) // Zero-Trust: block file:// & http(s):// SSRF
.allowedMediaRoot(null)
.maxMediaBytes(4_194_304L);
}
return builder.build();
}
}
Optional @Bean Snippet: Local Whisper ASR & Speech-LLM TTS
@Bean(destroyMethod = "close")
public LibArgusAudioTranscriptionModel whisperModel(@Value("${argus.audio.asr-model-path}") Path asrPath) {
return LibArgusAudioTranscriptionModel.builder()
.modelPath(asrPath)
.trimOutput(true)
.padShortAudioToOneSecond(true)
.build();
}
@Bean(destroyMethod = "close")
public LibArgusTextToSpeechModel ttsModel(
@Value("${argus.audio.tts-model-path}") Path ttsPath,
@Value("${argus.audio.tts-vocoder-path}") Path vocoderPath
) {
return LibArgusTextToSpeechModel.builder()
.modelPath(ttsPath)
.vocoderPath(vocoderPath)
.defaultVoice("42")
.build();
}
Because LibArgusChatModel, LibArgusStreamingChatModel, LibArgusAudioTranscriptionModel, and LibArgusTextToSpeechModel implement standard LangChain4j 1.23.0 interfaces, they plug directly into LangChain4j AiServices, @SystemMessage, ChatMemory, ChatModelListener observability, Tools, and Flow.Publisher reactive streams—while this repository exposes constructor-injectable @Bean delegates in ArgusLangChain4jConfig backed by ArgusRuntimeManager for per-request cancellation and live model recovery.
2. Architecture & Why In-Process Matters
flowchart LR
UI["Obsidian Workbench / curl\n(Chat, <think>, Paste/Drop Image, Mic WAV, Audio Playback)"]
FILT["WebSecurityHeadersFilter (Strict CSP)\n+ JsonRequestBodySizeFilter (64 KiB | 8 MiB Vision | 10 MiB Audio)"]
SVC["ChatService & AudioService\n(Magic-Byte Preflight + BPE & Vision-Patch Eviction + LIFO Concurrency Gate)"]
MGR["ArgusRuntimeManager\n(Read/Write Lifecycle Lease + Platform GPU Workers)"]
NAT["In-Process libargus 2.4.0 (Panama FFM JDK 22+/25 | JNI JDK 17+)\n(Shared ArgusModel + mmproj Vision + Whisper ASR + Speech-LLM TTS + ArgusAbortFlag)"]
UI --> FILT --> SVC --> MGR --> NAT
| Engineering Dimension |
Loopback Sidecar Stack (Ollama + Whisper + TTS Containers) |
In-Process libargus + Spring Boot |
| Process Topology |
3–4 separate OS daemons/containers + JVM service |
Single JVM process (java -jar app.jar) |
| Multimodal & Audio Pipeline |
Separate HTTP/Base64/multipart hops across LLM, VLM, ASR, and TTS services |
Process-global backend singularity sharing ArgusModel weights across Chat, Vision mmproj, Whisper ASR, and Speech-LLM TTS |
| Per-Token Streaming Path |
C++ → Sidecar HTTP/JSON → Loopback TCP → JVM |
Direct FFI memory read (Panama FFM or JNI) |
| Mid-Prefill Cancellation |
Socket disconnect often waits until prefill completes |
Immediate C++ abort via StreamingHandle.cancel() + ArgusAbortFlag.abort() |
| Token Window Budgeting |
Approximate char heuristics or duplicate Java tokenizer |
Exact lock-free native BPE count (LibArgusTokenCountEstimator) + tokensPerImage vision patch reserve |
| GPU Thread Affinity |
Unmanaged external worker pools |
Dedicated daemon platform threads (argus-inference-worker-* / argus-model-async-*) avoiding virtual-thread carrier hopping across thread-local cublasHandle_t pools |
Production Patterns Demonstrated in This Repo
- First-Class Dual FFI (
JNI Baseline + Automatic Panama FFM Shift): Builds on portable libargus-jni (--release 17) for JDK 17–21 and automatically shifts to Project Panama FFM (libargus-core, --release 22) whenever Maven detects JDK 22+ / JDK 25 LTS—with Enable-Native-Access: ALL-UNNAMED stamped into MANIFEST.MF so java -jar needs zero extra CLI flags.
- Deterministic Native Lifecycle & Reverse-Order Teardown:
ArgusRuntimeManager initializes native handles in strict forward order, unwinds partial allocations on startup failure, coordinates with server.shutdown: graceful + ChatService.destroy() / AudioService.destroy(), and closes every handle in exact reverse order under a ReentrantReadWriteLock lifecycle lease.
- Separated
<think> Reasoning Without History Pollution: Streams model chain-of-thought over dedicated event: thinking SSE frames into a live collapsible <details class="thinking-trace">