Local LLMs and Coding Agents in Java
Run language models on your own machine and build a coding agent in Java: tokenizers, transformers, sampling, quantization, GGUF and Hugging Face, llama.cpp and vLLM, inference engineering, an inference engine in pure Java, and an Ollama-style CLI with picocli that downloads models, chats, and writes, runs, and fixes code with tools.
Start with What Is a Large Language Model? →How LLMs Work
What an LLM is, prompts and context, the vocabulary of agents and LLM engineering, a first run, next-token prediction, tokenizers and BPE, the math of transformers, self-attention, the transformer block, prefill, decode and the KV cache, sampling, training stages, and chat templates.
- 1.What Is a Large Language Model?
- 2.Talking to a Model: Prompts, Context, and Limits
- 3.Agents and LLM Engineering: The Vocabulary
- 4.Introduction and First Run
- 5.What a Language Model Computes
- 6.Tokens, Vocabularies, and Special Tokens
- 7.Building a BPE Tokenizer
- 8.The Math Behind Transformers, in Java
- 9.Self-Attention Step by Step
- 10.The Transformer Block and the Full Model
- 11.Generation, Prefill, Decode, and the KV Cache
- 12.Sampling: Greedy, Temperature, Top-k, Top-p, and Min-p
- 13.Penalties, Logit Bias, and Sampler Chains
- 14.How Models Are Trained, and the Variants You Download
- 15.Chat Templates, Roles, and Special Tokens
Hardware, Numbers, and Quantization
CPUs, GPUs, memory bandwidth and the roofline model, number formats from FP32 to FP4, memory math for weights and KV cache, and quantization from first principles to k-quants, i-quants, GPTQ, AWQ, and making your own GGUF.
- 16.CPUs, GPUs, and Memory for Inference
- 17.FLOPs, Bandwidth, and the Roofline Model
- 18.Number Formats: FP32, FP16, BF16, FP8, INT8, INT4, and FP4
- 19.Memory Math: Weights, KV Cache, and What Fits
- 20.Quantization Fundamentals
- 21.Building Q8_0 and Q4_0 Like ggml
- 22.k-quants, i-quants, and the Importance Matrix
- 23.GPTQ, AWQ, EXL3, NF4, and FP8 Serving
- 24.Making, Quantizing, and Testing Your Own GGUF
Model Files and Hugging Face
The Hugging Face Hub, its HTTP API and cache layout, and the safetensors and GGUF file formats, with a Java reader for each.
The loop CLI and Model Management
Build the loop command-line tool with picocli: options, subcommands, configuration, packaging, reliable large downloads, and the pull, list, show, rm, and fit commands.
Inference Engines
llama.cpp architecture, flags, tuning, and llama-server; the chat completions protocol and streaming in Java; vLLM; Ollama and the other engines; and the loop serve and chat commands.
- 33.llama.cpp Architecture
- 34.Running llama.cpp: Core Flags
- 35.Tuning llama.cpp
- 36.llama-server: Endpoints, Slots, and Prompt Cache
- 37.The Chat Completions Protocol and Streaming in Java
- 38.vLLM Architecture and Installation
- 39.Serving with vLLM
- 40.The Engine Landscape and How Ollama Works
- 41.Workshop: loop serve, run, and chat
Inference Engineering
FlashAttention and long context, batching and scheduling, paged KV cache and prefix caching, speculative decoding, constrained decoding, multi-GPU serving, and benchmarking.
Build an Inference Engine in Java
A transformer inference engine in plain Java: GGUF loading with the FFM API, a tokenizer from GGUF metadata, the forward pass, quantized kernels with the Vector API, and a chat engine.
Tool Calling and Coding Agents
Function calling, the agent loop, file, shell, and web tools, permissions and sandboxing, context engineering, edit formats, small-model reliability, MCP, evaluation, and the loop agent command.
- 54.Function Calling from First Principles
- 55.The Agent Loop and a Tool Framework
- 56.File Tools
- 57.The Shell Tool
- 58.Web Search and Fetch Tools
- 59.Permissions, Sandboxing, and Prompt Injection
- 60.Context Engineering for Coding Agents
- 61.Edit Formats
- 62.Making Small Local Models Reliable
- 63.Workshop: loop agent
- 64.The Model Context Protocol
- 65.Evaluating Models and Agents
An HTTP Gateway with Spring Boot
An Ollama-style HTTP layer in front of llama.cpp and vLLM with Spring Boot: an OpenAI-compatible API, streaming proxy, model loading and scheduling, security, metrics, and the loop gateway workshop.
Reading Real Codebases
Guided reading of open-source coding harnesses (Pi, Aider, mini-swe-agent, OpenHands, Crush) and inference engines (llama.cpp, vLLM, Ollama, SGLang).
