Contenox

Modeld architecture: more context on your own GPU

Updated

Modeld is the local inference service in Contenox Runtime. Its architecture is built around a practical goal: more useful context and fast generation on the GPU you already own. An agent needs room for project instructions, code, tool definitions and the results of its own work. Filling the card with model weights leaves too little space for that conversation.

The target is 70+ generated tokens per second, with a capable model resident on the GPU and memory left for context. A larger model crawling through an agent loop at 20 tokens per second is a different tradeoff. Modeld puts the effort into the working context: how it is assembled, what stays resident, what can be reused and what can move out of the way. This matters most when your machine does not have a 5090.

More room for the work#

Model weights and context compete for the same memory. The KV cache holds the model’s working state for tokens it has already processed. As a conversation grows, that cache grows too.

Modeld reads the model’s architecture and a live snapshot of available memory. It accounts for weights, runtime overhead, reserved headroom, KV precision and attention layout, then calculates the usable context budget. Quantized KV reduces the memory cost of that working state. Sliding-window layers are costed according to their window instead of charging every layer for the entire history. The capacity planner makes those decisions explicit.

The goal is to keep model computation on the GPU and spend the remaining memory well. Moving cold context state into host memory serves that goal; spreading an oversized model’s layers onto the CPU serves a different one.

Assemble context so it can stay useful#

A coding task contains material with very different lifetimes. Project rules may stay unchanged for an entire session. Terminal output can change on every tool call. Putting both into one constantly changing prompt throws away opportunities for reuse.

Modeld’s context assembler gives that material a structure:

Context Placement and retention
System instructions, tool schemas, repository rules Stable prefix; highest retention priority
Repository map and pinned files Stable workspace context
Current diff, terminal output, new user turn Changing suffix; more readily evicted

Stable segments are ordered consistently and recorded in a manifest with their identities and boundaries. A new test result can change the suffix without invalidating the unchanged project instructions ahead of it. Contenox Runtime sends EnsurePrefix, then PrefillSuffix, so the worker can reuse prepared context and process the new input.

When the hot window fills, the residency planner uses those priorities to decide what stays. It protects task-defining material and recent context, and parks evictable ranges in cold storage. During streaming, it preserves the initial attention anchors and recent tail while moving older middle blocks out of the hot window. The llama.cpp worker performs native KV operations; the OpenVINO worker uses its own export and recomputation path.

The Modeld R&D measurements show why reuse matters: on a 6 GB laptop GPU, a 9,350-token stable prefix took 1.77 seconds to prepare cold and 0.03 seconds warm. The next turn reused all of it. That is time an agent would otherwise spend reading the same instructions again.

Why isn’t this just Ollama or llama.cpp?#

Ollama makes a chosen model available to applications. Modeld also takes responsibility for how an agent’s working context occupies memory. In Ollama’s Go prompt assembly path, messages are rendered and tokenized against the configured context limit. When truncation is enabled, older messages are removed until the prompt fits, preserving system messages and the latest message. That path does not assign repository rules, pinned files and terminal output their own retention classes.

Ollama’s llama-server integration enables prompt caching and delegates native execution to llama.cpp. Modeld adds the coding-aware assembly, manifest identity and hot/cold residency decisions described above. The distinction is what the system knows about the context and how it manages that context through an agent loop.

llama.cpp supplies the inference engine inside Modeld’s llama worker. Its memory fitting code works with tensor placement, device budgets and context allocation. Modeld builds on those native capabilities with a policy for the agent’s work: keep a capable model fast, preserve useful context and avoid repeating prompt work. OpenVINO sits behind the same Modeld session contract.

Contenox Harness can also connect to Ollama as a separate provider. Its native local AI path runs through Modeld directly.

Who owns what?#

Contenox Runtime clients connect to a shared Modeld owner over gRPC. The owner connects to llama.cpp and OpenVINO workers through the same session protocol, with device claims and admission coordinated back through the owner.

Part Responsibility
Contenox Runtime Runs the agent conversation, prepares prompts, executes tools and enforces permissions.
Modeld owner Discovers installed models, starts or reuses workers, coordinates device capacity and admits work.
Native worker Loads model weights, maintains inference state and generates tokens using llama.cpp or OpenVINO.

Native libraries stay in the workers. Runtime can remain a Go process without linking either inference engine. A model can return a tool call, but Runtime still decides whether and how that tool runs.

What travels over the wire?#

Runtime connects to Modeld over gRPC. The current service is contenox.transport.v1.Compute, using protocol version 4. Its hand-written bindings encode messages as JSON with the contenoxtransportjson content subtype. This is a gRPC service with JSON payloads, not an OpenAI-compatible chat endpoint.

Operation Transport
Inspect models, manage workers, open and prepare sessions Request/response RPCs
Generate with Decode Server stream carrying text, thinking, tool calls and usage
Push model files with PushModel Client stream

The owner speaks the same session protocol to its workers. Workers also call back to coordinate device claims and admission. This keeps backend-specific inference behind a common contract while the owner accounts for competing uses of the hardware.

ACP is a separate boundary between an editor or the desktop app and Runtime. Requests arriving through ACP, the CLI or Runtime’s HTTP API use the same Modeld client underneath. The Runtime transport documentation describes these interfaces.

Why expose sessions?#

An agent repeatedly adds tool results and new instructions to a conversation. Reprocessing the entire prompt every turn wastes work. Modeld gives Runtime explicit control over that sequence:

Open session → EnsurePrefix → PrefillSuffix → Decode
                    ↑                            |
                    └──── next agent turn ────────┘
Close session

EnsurePrefix establishes reusable prompt state. PrefillSuffix processes the added input. Decode generates the response. Closing the session releases its handle; the worker can remain loaded for another request.

Safe reuse depends on more than matching text. Model assets, adapters, backend, prompt template and context configuration must agree. Where the backend supports snapshots, compatible native state can be saved and restored across worker lifetimes. A mismatch starts a fresh session.

The session reports tokens reused, prefilled and resident, alongside its effective context capacity. Runtime can inspect what the worker is doing with the budget.

How do clients find the owner?#

A lease in the data root records the local owner’s endpoint and identity. Runtime discovers it there and can start an owner on demand. Ownership is scoped to that data root. Requests carry the expected owner identity so a replacement owner can reject stale clients; workers also track their owner’s lifetime.

A remote owner uses the same protocol, so a worker on another machine presents the same session interface as a local one.

Further reading#