Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Docker 7 min read How-to mediumAdept

How to solve the context size issues with context packing with Docker Model Runner and Agentic Compose

Context packing works around small local LLMs' context window limits by having a second model summarize the conversation history once an estimated token count crosses a threshold, then replacing the history with that summary. The example configures Docker Model Runner models in compose.yml, using a Qwen2.5-Coder 3B chat model and Qwen2.5 1.5B as the summarizer. It estimates tokens as characters/4 with a 5120-token trigger, and implements the packing step in a LangChain.js conversation loop. In the demo, history shrinks from 4886 to 153 tokens (about 97% reduction). Raising context_size helps only partially because not all models support it and generation slows as the context fills.

Assumes: LLM context windowsDocker ComposeLangChain.js basics

Related posts

  • Making (Very) Small LLMs Smarter

    Docker mediumAdept

    A 3B-parameter local model (Qwen2.5-Coder-3B, Q4_K_M) can become a useful coding assistant for an unfamiliar, recent Go library (Nova) when it is given a small, focused RAG context. Markdown snippet sections are embedded with EmbeddingGemma and stored in an in-memory vector store. Each query retrieves at most 3 snippets above a cosine-similarity threshold of 0.45. Because small models degrade as context grows, conversation history is capped at 2 messages. The agent is built in Node.js with LangchainJS and runs via Docker Model Runner and Docker Compose's models section, with low temperature and a presence penalty to keep output focused.

  • OpenCode with Docker Model Runner for Private AI Coding

    Docker mediumAdept

    OpenCode can use locally hosted models by pointing an @ai-sdk/openai-compatible provider in opencode.json at Docker Model Runner's OpenAI-compatible endpoint (localhost:12434/v1, with TCP enabled on Docker Desktop). Prompts and code then stay on infrastructure you control, and there are no per-token costs. Coding models such as qwen3-coder and devstral-small-2 ship with 128K context, while gpt-oss defaults to 4,096 tokens. `docker model package --context-size` can repackage gpt-oss as a 128K OCI artifact that teams push to a registry to standardize and version model variants.

  • How to Make an AI Chatbot from Scratch using Docker Model Runner

    Docker mediumAdept

    A local GenAI chatbot built on Docker Model Runner, which runs llama.cpp models natively on the host and exposes an OpenAI-compatible API to containers. A Go backend uses the OpenAI client to stream tokens over SSE to a React/TypeScript UI. The backend also acts as a metrics bridge, exporting llama.cpp-specific Prometheus gauges such as tokens per second, context size, prompt evaluation time and memory per token, alongside Grafana dashboards and Jaeger tracing. The walkthrough covers pulling Llama 3.2 1B, starting the stack with docker compose, wiring Grafana to Prometheus, and the key code paths.

  • Run LLMs Locally with Docker: A Quickstart Guide to Model Runner

    Docker mediumAdept

    Docker Model Runner, in beta with Docker Desktop 4.40 on Apple silicon, pulls LLMs packaged as OCI artifacts and serves them through an OpenAI-compatible API backed by llama.cpp. Unlike `docker container run`, `docker model run` starts no container. The inference engine runs as a native host process for GPU acceleration, loads models on demand, and unloads them after 5 minutes of inactivity. Containers reach it at model-runner.docker.internal, and host processes can use an optional TCP port (12434), so any OpenAI client such as LangChain4j can point at it by setting a base URL and a model tag of the form {model}:{parameters}-{quantization}.

  • Why and How to Run Local Models in Zed

    Zed mediumAdept

    Local open-weight models run through LM Studio, Ollama or llama.cpp offer privacy, predictable cost, control and guaranteed availability, at the price of lower capability, fewer tokens per second and smaller context windows than frontier models. A Mixture-of-Experts model such as Qwen 3.6 35B A3B activates only about 3B parameters per token, so it runs roughly 10x faster than a dense 35B model and suits unified-memory chips like Apple M series. At Q4 quantization it needs about 17.5GB of VRAM. Zed connects to LM Studio at localhost:1234 or to any OpenAI-compatible server via its Ollama provider. To keep context clean with weaker models, edit earlier messages instead of sending corrections, and lean on subagents.

The quest for software engineering knowledge.

Look:
Layout: