@octocodeai/freellama-mcp-server 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONFIGURATION.md +108 -0
- package/DEVELOPING.md +109 -0
- package/README.md +130 -282
- package/dist/index.js +1509 -1411
- package/dist/research/bash-agent.js +2435 -0
- package/dist/research/octocode-agent.js +1639 -0
- package/docs/ARCHITECTURE.md +145 -81
- package/docs/CLI.md +83 -55
- package/docs/CPU_GPU_ROUTING.md +4 -3
- package/docs/MODEL_SELECTION.md +115 -5
- package/docs/MONITORING.md +19 -11
- package/docs/PRODUCTION.md +10 -13
- package/docs/README.md +9 -13
- package/docs/SCOPES_AND_WARMING.md +8 -9
- package/docs/TESTING.md +18 -30
- package/native/index.d.ts +179 -174
- package/native/index.js +3 -3
- package/package.json +11 -10
- package/adapters/agent_context.py +0 -850
- package/adapters/agent_transport.py +0 -215
- package/adapters/bash_agent.py +0 -345
- package/adapters/octocode_agent.py +0 -404
- package/adapters/shell_sandbox.py +0 -487
- package/docs/ECONOMICS.md +0 -110
- package/docs/INDEX.md +0 -21
- package/docs/MODEL_METADATA.md +0 -106
- package/docs/OLLAMA_SIDECAR.md +0 -78
- package/docs/PRODUCT_POSITIONING.md +0 -121
- package/docs/dev/ADR_RESOURCE_AWARE_BACKEND_ROUTING.md +0 -55
- package/docs/dev/FINDINGS_AND_POSITIONING.md +0 -290
- package/docs/dev/LOCAL_PERFORMANCE_TESTING.md +0 -298
- package/docs/dev/OLLAMA_SYSTEM_OPTIMIZATION.md +0 -255
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
# Ollama and FreeLlama optimization boundary
|
|
2
|
-
|
|
3
|
-
FreeLlama manages model selection and resources for tasks offloaded by agents. Ollama owns
|
|
4
|
-
inference optimization. FreeLlama can improve completed work per hour by avoiding unsuitable
|
|
5
|
-
routes and unnecessary model transitions; measure that effect for the target workload.
|
|
6
|
-
|
|
7
|
-
This page explains the active request flow, the settings Ollama owns, the
|
|
8
|
-
current machine audit, and the optimization work that remains.
|
|
9
|
-
|
|
10
|
-
The architecture is portable across Ollama's Metal, CUDA, ROCm, Vulkan, and CPU paths. The audit
|
|
11
|
-
later on this page is intentionally Mac-specific. FreeLlama discovers host RAM per operating system
|
|
12
|
-
and keeps device selection in each Ollama process; it does not translate one machine's memory tier,
|
|
13
|
-
core count, or benchmark into another machine's defaults.
|
|
14
|
-
|
|
15
|
-
## Decision
|
|
16
|
-
|
|
17
|
-
Use stock Ollama as the inference runtime. Keep FreeLlama as an optional Rust
|
|
18
|
-
control plane for evidence-qualified routing, bounded request profiles, session
|
|
19
|
-
affinity, and policy enforcement.
|
|
20
|
-
|
|
21
|
-
Do not advertise FreeLlama as an accelerator or an Ollama inference plugin. It does not tune
|
|
22
|
-
kernels or split one model's layers across CPU and GPU. It responds to observed host pressure by
|
|
23
|
-
holding managed work; the operating system manages physical memory. FreeLlama can assign different
|
|
24
|
-
models to isolated CPU and GPU-capable Ollama
|
|
25
|
-
processes, allowing independent workloads to overlap.
|
|
26
|
-
|
|
27
|
-
## Request flow
|
|
28
|
-
|
|
29
|
-
FreeLlama has four distinct paths:
|
|
30
|
-
|
|
31
|
-
| Request | FreeLlama work | Ollama work | Result |
|
|
32
|
-
|---|---|---|---|
|
|
33
|
-
| Native `/api/*` or `/v1/*` | Streams bytes to the primary compatibility upstream | Performs normal inference and scheduling | Exact Ollama response |
|
|
34
|
-
| `POST /_freellama/v1/routes` | Discovers models, filters capabilities, and applies policy | Supplies installed-model and residency data | Model and request profile; no inference |
|
|
35
|
-
| `POST /_freellama/v1/natural-routes` | Normalizes a schema-bound intent, then runs the deterministic router | Runs the small intent model | Model and request profile; selected task does not run |
|
|
36
|
-
| `POST /_freellama/v1/tasks` | Selects a route and backend, applies managed-task admission, and constructs one bounded request | Runs one nonstreaming chat or embedding request on the assigned process | Route receipt, placement, admission mode, prompt-free metrics, and Ollama response |
|
|
37
|
-
|
|
38
|
-
The natural-language path is intentionally two-stage. The small model cannot
|
|
39
|
-
name a final model. It returns only a task, objective, context hint, and tool or
|
|
40
|
-
vision requirements. Deterministic guards correct explicit requirements before
|
|
41
|
-
the ordinary router selects a model.
|
|
42
|
-
|
|
43
|
-
Calling `natural-routes` does not run the selected task. A client must use the
|
|
44
|
-
returned profile or submit a structured `tasks` request. There is no atomic
|
|
45
|
-
natural-language route-and-run endpoint in the current release.
|
|
46
|
-
|
|
47
|
-
Chat and embedding tasks forward route options. A captured-upstream contract
|
|
48
|
-
test verifies embedding option parity.
|
|
49
|
-
|
|
50
|
-
## What Ollama already optimizes
|
|
51
|
-
|
|
52
|
-
Across supported backends, Ollama provides the following behavior without FreeLlama:
|
|
53
|
-
|
|
54
|
-
- The runtime selects supported acceleration such as Metal, CUDA, ROCm, or Vulkan from the host and
|
|
55
|
-
its process-level device visibility.
|
|
56
|
-
- The scheduler fits model, context, and compute allocations to available
|
|
57
|
-
device memory.
|
|
58
|
-
- The runner selects CPU threads and GPU execution; applications do not need to
|
|
59
|
-
divide one inference manually between the CPU and GPU.
|
|
60
|
-
- Ollama manages request queues plus model loading and eviction. It supports
|
|
61
|
-
same-model parallel requests when memory permits.
|
|
62
|
-
- Ollama reports token counts plus load, prompt-processing, and generation
|
|
63
|
-
durations in API responses.
|
|
64
|
-
- Ollama supports request-specific context length and model residency through
|
|
65
|
-
`num_ctx` and `keep_alive`.
|
|
66
|
-
|
|
67
|
-
Ollama's documented concurrency controls are global server settings. Increasing
|
|
68
|
-
`OLLAMA_NUM_PARALLEL` multiplies context memory by the parallel-request count.
|
|
69
|
-
Increasing `OLLAMA_MAX_LOADED_MODELS` does not create memory; models still need
|
|
70
|
-
to fit. Use `1` for both values on an unmeasured deployment, then increase one variable at a time
|
|
71
|
-
only when a representative concurrent benchmark improves completed tasks per hour without memory
|
|
72
|
-
pressure.
|
|
73
|
-
|
|
74
|
-
Keep three signals distinct when operating FreeLlama: `context_window_fit` only compares requested
|
|
75
|
-
context with advertised model context; FreeLlama's K/V preflight is a conservative metadata lower
|
|
76
|
-
bound; and a completed runner is the only placement observation. None is live free-memory or
|
|
77
|
-
throughput proof. `doctor {view:"scheduler"}` reports configuration and a point-in-time admission
|
|
78
|
-
snapshot, not a fairness or parallel-decoding benchmark.
|
|
79
|
-
|
|
80
|
-
FreeLlama's admission queue and Ollama's internal queue solve different problems. FreeLlama limits
|
|
81
|
-
weighted managed work per backend and applies `--max-queue-wait-seconds`; `OLLAMA_MAX_QUEUE` bounds
|
|
82
|
-
requests that an Ollama process has accepted but cannot schedule. Raw compatibility traffic skips
|
|
83
|
-
FreeLlama admission and reaches the primary Ollama queue directly.
|
|
84
|
-
|
|
85
|
-
Ollama request context and research-adapter context are also separate budgets. Managed tasks set
|
|
86
|
-
request-specific `num_ctx` from the selected task profile. The coding adapters fit their tool
|
|
87
|
-
conversation inside `FREELLAMA_AGENT_NUM_CTX`: by default, they preserve the system prompt and
|
|
88
|
-
original question, compact the oldest observations first, retain recent evidence, and fail before
|
|
89
|
-
the Ollama call if pinned content cannot fit. Raising the Ollama server's global context does not
|
|
90
|
-
disable adapter compaction or increase its configured budget. See [adapter contracts](../../benchmark/local/docs/07-adapter-contracts.md)
|
|
91
|
-
for the complete pagination and compaction contract.
|
|
92
|
-
|
|
93
|
-
## Mac audit (2026-09-01)
|
|
94
|
-
|
|
95
|
-
This audit captures the following snapshot from September 1, 2026. Treat it as machine
|
|
96
|
-
evidence, not a portable default.
|
|
97
|
-
|
|
98
|
-
| Item | Observed value | Interpretation |
|
|
99
|
-
|---|---|---|
|
|
100
|
-
| Hardware | Apple M4 Pro, 14 CPU cores, 48 GB unified memory | CPU and GPU share the memory system |
|
|
101
|
-
| macOS | 15.7.2 | Native Ollama supports this Apple-silicon system |
|
|
102
|
-
| Ollama server | 0.33.2 | Active application server on `127.0.0.1:11434`; re-read with `doctor` rather than trusting this row |
|
|
103
|
-
| First CLI on `PATH` | `/usr/local/bin/ollama`, 0.33.2 | Matches the active server |
|
|
104
|
-
| Metal device budget | 36 GiB reported by Ollama | This is the scheduler's observed device budget, not all 48 GB |
|
|
105
|
-
| Default context | 32,768 tokens | Ollama selected its 24–48 GiB device-memory tier |
|
|
106
|
-
| Parallel requests | 1 | Appropriate baseline for interactive and large-model tests |
|
|
107
|
-
| Keep-alive | 5 minutes | Ollama default |
|
|
108
|
-
| Loaded-model limit | `OLLAMA_MAX_LOADED_MODELS=2` | Explicit service configuration for the measured topology |
|
|
109
|
-
| K/V-cache type | `OLLAMA_KV_CACHE_TYPE=q8_0` | Explicit memory-saving configuration; requalify quality per important model |
|
|
110
|
-
| Flash Attention | `auto` | Ollama enables it automatically on supported backends; force `1` only after a measured compatibility check. Required for quantized K/V cache. |
|
|
111
|
-
| GGUF CPU threads | 10 worker threads | Ollama selected the 10 performance cores rather than all 14 cores |
|
|
112
|
-
| MLX | GPU runner observed | MLX models use their own runner path, not the GGUF tuning path |
|
|
113
|
-
| Power mode | Automatic on battery and AC power | High Power Mode remains an unmeasured experiment |
|
|
114
|
-
|
|
115
|
-
The server log also showed Metal fusion, concurrent Metal execution, graph
|
|
116
|
-
optimization, and automatic parameter fitting. FreeLlama must not claim these
|
|
117
|
-
as its own optimizations.
|
|
118
|
-
|
|
119
|
-
### Verify CLI and server alignment
|
|
120
|
-
|
|
121
|
-
The selected CLI is `/usr/local/bin/ollama`, and both the CLI and active server report 0.33.2.
|
|
122
|
-
Verify this alignment after changing Ollama installations or service definitions:
|
|
123
|
-
|
|
124
|
-
```bash
|
|
125
|
-
command -v ollama
|
|
126
|
-
ollama --version
|
|
127
|
-
curl --silent http://127.0.0.1:11434/api/version
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
The client and server versions must match before you test a CLI feature. A mismatch does not prove
|
|
131
|
-
an inference slowdown, but it can produce incompatible commands, flags, or diagnostics.
|
|
132
|
-
|
|
133
|
-
## What FreeLlama adds today
|
|
134
|
-
|
|
135
|
-
The active Rust implementation adds:
|
|
136
|
-
|
|
137
|
-
- capability filtering before speed ranking;
|
|
138
|
-
- explicit `fastest`, `balanced`, and `quality` evidence contracts;
|
|
139
|
-
- fail-closed quality routing when the policy has no qualified model;
|
|
140
|
-
- task-specific context, output, thinking, and tool-validation profiles;
|
|
141
|
-
- session affinity and preference for an eligible resident model;
|
|
142
|
-
- separate transition locks for primary and CPU backends, with shared execution permits for
|
|
143
|
-
resident tasks and an exclusive permit for a cold transition;
|
|
144
|
-
- exact-model placement on an optional second CPU Ollama process, including `num_gpu=0` for its
|
|
145
|
-
managed requests;
|
|
146
|
-
- guarded agent placement preferences plus a normalized, three-warm-sample, 10%-advantage feedback
|
|
147
|
-
loop for `fastest` and `balanced` work;
|
|
148
|
-
- independent 3:2:1 priority-fair weighted GPU and CPU admission pools, so a GPU burst cannot
|
|
149
|
-
starve a CPU helper or indefinitely starve background managed work;
|
|
150
|
-
- prompt-free load, prompt-processing, and output-generation metrics derived
|
|
151
|
-
from Ollama's response fields;
|
|
152
|
-
- a local natural-language intent interpreter that cannot choose a model;
|
|
153
|
-
- an Ollama-compatible loopback endpoint and an escape hatch to port 11434.
|
|
154
|
-
|
|
155
|
-
These features can reduce reloads or avoid an unsuitable model. They do not
|
|
156
|
-
change the selected model's prompt-processing or decode rate.
|
|
157
|
-
|
|
158
|
-
The measured dual-backend workload improved median completion time from 37.997 to 28.233 seconds
|
|
159
|
-
(1.346 times, or 25.70%). Qwen reported 19,175,677,668 GPU-resident bytes, Nomic reported zero,
|
|
160
|
-
and all requests carried correct backend receipts with zero FreeLlama queue wait. One of three
|
|
161
|
-
parallel trials was slower than sequential, so this remains a workload-level optimization rather
|
|
162
|
-
than an inference-speed claim.
|
|
163
|
-
|
|
164
|
-
## Unsupported optimizations
|
|
165
|
-
|
|
166
|
-
FreeLlama does not provide:
|
|
167
|
-
|
|
168
|
-
- exact runner-allocation prediction. Managed admission uses observed available RAM, free VRAM
|
|
169
|
-
when available, and a metadata-backed F16 K/V estimate; unknown layouts remain unknown. Ollama
|
|
170
|
-
remains authoritative for runner allocation and final loading;
|
|
171
|
-
- coordination for processes that bypass FreeLlama. Mutating passthrough requests in `serve`
|
|
172
|
-
share the primary transition lock;
|
|
173
|
-
- direct control over thermal state, power mode, or swapping. Observed pressure can hold admission;
|
|
174
|
-
- model-quality scoring inferred from operational latency or errors;
|
|
175
|
-
- per-engine tuning for GGUF compared with MLX;
|
|
176
|
-
- unbounded automatic residency or concurrency. Runtime limits remain operator-owned;
|
|
177
|
-
- an atomic natural-language route-and-run operation;
|
|
178
|
-
- held-out quality policies for completion, coding, tools, browser, vision, or
|
|
179
|
-
long-context tasks in the example policy;
|
|
180
|
-
- quality-aware or thermal-aware CPU/GPU load balancing. Automatic placement uses persisted,
|
|
181
|
-
prompt-free warm-latency aggregates only within exact operator-owned assignments.
|
|
182
|
-
|
|
183
|
-
The RFC describes several of these capabilities as planned phases. Do not treat
|
|
184
|
-
the RFC as evidence that they have shipped.
|
|
185
|
-
|
|
186
|
-
## Optimization decisions
|
|
187
|
-
|
|
188
|
-
Use this table before changing Ollama or FreeLlama:
|
|
189
|
-
|
|
190
|
-
| Candidate change | Default decision | Reason |
|
|
191
|
-
|---|---|---|
|
|
192
|
-
| Expose Ollama beyond loopback | Do not add | Keep `OLLAMA_HOST` on loopback and put authenticated TLS ingress in front of FreeLlama instead |
|
|
193
|
-
| Permit Ollama cloud features in a local-only deployment | Do not add | Set `OLLAMA_NO_CLOUD=1` when the deployment promises local-only operation |
|
|
194
|
-
| Force layers of one model between CPU and GPU | Do not add | Ollama already fits and offloads the model; partial CPU fallback usually reduces decode throughput |
|
|
195
|
-
| Assign different models to isolated CPU and GPU-capable processes | Supported, benchmark per workload | Process isolation is reliable, but CPU speed and shared-memory pressure still determine whether overlap helps |
|
|
196
|
-
| Add macOS kernel or `sysctl` tuning | Do not add | Ollama does not document a supported, product-specific kernel setting. Unified-memory behavior belongs to macOS and Metal |
|
|
197
|
-
| Run Ollama in Docker on macOS | Do not use for performance | Docker Desktop does not provide Ollama GPU acceleration on macOS |
|
|
198
|
-
| Increase context globally | Do not add | Context memory grows with length; set the smallest sufficient `num_ctx` per request |
|
|
199
|
-
| Set parallel requests above 1 | Benchmark first | It can improve concurrent throughput but multiplies context memory and can hurt interactive latency |
|
|
200
|
-
| Keep more than one model loaded per process | Benchmark first | Model weights, runtime buffers, and every active context must fit together; start with `OLLAMA_MAX_LOADED_MODELS=1` |
|
|
201
|
-
| Leave Ollama's queue without a deployment limit | Do not add | Set a measured `OLLAMA_MAX_QUEUE`; it remains separate from FreeLlama's admission deadline |
|
|
202
|
-
| Pin multiple 18–21 GB models | Do not add by default | The observed 36 GiB Metal budget cannot safely establish that two heavy models plus contexts fit |
|
|
203
|
-
| Force Flash Attention | Benchmark per engine and model | The inspected GGUF path already enabled it automatically; MLX has a different runner |
|
|
204
|
-
| Use `q8_0` K/V cache | Qualify quality and memory effects per workload | KV quantization changes memory use and precision for the whole process; compare representative task quality and resident memory before deployment |
|
|
205
|
-
| Use `q4_0` K/V cache | Reject as a default | It saves more memory with a larger possible quality loss |
|
|
206
|
-
| Enable High Power Mode | Sustained-load experiment only | Apple documents higher sustained performance. Local token-rate and energy effects are not measured |
|
|
207
|
-
| Keep the small intent model resident | Keep bounded | It reduces routing latency but consumes memory and can affect a large-model transition |
|
|
208
|
-
|
|
209
|
-
## Measurement contract
|
|
210
|
-
|
|
211
|
-
Measure optimization with Ollama's response fields:
|
|
212
|
-
|
|
213
|
-
- prompt tokens per second = `prompt_eval_count / prompt_eval_duration` in
|
|
214
|
-
seconds;
|
|
215
|
-
- output tokens per second = `eval_count / eval_duration` in seconds;
|
|
216
|
-
- cold-load cost = `load_duration`;
|
|
217
|
-
- end-to-end latency = `total_duration` plus measured FreeLlama overhead;
|
|
218
|
-
- workload throughput = successful, quality-qualified tasks per hour.
|
|
219
|
-
|
|
220
|
-
Compare one variable at a time against stock Ollama. Include cold and warm runs,
|
|
221
|
-
fixed prompts, fixed output budgets, exact-output guardrails, quality guardrails, resident
|
|
222
|
-
memory, swap, and failure counts. A higher token rate is not an improvement if
|
|
223
|
-
quality falls, requests fail, or model transitions dominate the workload.
|
|
224
|
-
|
|
225
|
-
Use `cargo run -- bench-all` (`packages/rust-core/src/model_bench.rs`) for model selection evidence.
|
|
226
|
-
Use [CPU and GPU model routing](../CPU_GPU_ROUTING.md) for the separate-process benchmark and
|
|
227
|
-
verification procedure.
|
|
228
|
-
|
|
229
|
-
- Local-model router RFC — lived in the gitignored `.octocode/` workspace and is no longer in the tree; the shipped design it argued for is [ARCHITECTURE.md](../ARCHITECTURE.md)
|
|
230
|
-
|
|
231
|
-
## Recommended next work
|
|
232
|
-
|
|
233
|
-
1. Keep the CLI executable aligned with the active Ollama server; `doctor` reports the selected
|
|
234
|
-
path, both versions, and effective memory-related settings.
|
|
235
|
-
2. Back up the versioned prompt-free feedback snapshot with the policy and deployed binary.
|
|
236
|
-
Verified warm work-unit latency and queue wait survive restart; raw prompts are never stored.
|
|
237
|
-
3. Validate the metadata-backed K/V lower bound against a frozen alternating-model workload before
|
|
238
|
-
widening it beyond CPU/unified-memory impossible-floor refusal. Keep Ollama as final authority.
|
|
239
|
-
4. Extend transition coordination only if managed streaming or another parsed
|
|
240
|
-
execution path needs it. Native passthrough remains Ollama-owned.
|
|
241
|
-
5. Evaluate request-specific context and residency profiles before testing global K/V-cache or
|
|
242
|
-
concurrency changes. Keep Flash Attention automatic on supported backends or set it explicitly
|
|
243
|
-
to `1` before selecting a quantized K/V cache.
|
|
244
|
-
6. Promote a hardware-and-engine profile only after `benchmark/hardware/run_validation.py` and its
|
|
245
|
-
held-out quality workload pass on a real self-hosted runner.
|
|
246
|
-
|
|
247
|
-
## Sources
|
|
248
|
-
|
|
249
|
-
- [Ollama FAQ and server settings](https://docs.ollama.com/faq)
|
|
250
|
-
- [Ollama context length](https://docs.ollama.com/context-length)
|
|
251
|
-
- [Ollama hardware and Metal support](https://docs.ollama.com/gpu)
|
|
252
|
-
- [Ollama API usage metrics](https://docs.ollama.com/api/usage)
|
|
253
|
-
- [Ollama embedding API](https://docs.ollama.com/api/embed)
|
|
254
|
-
- [Ollama macOS support](https://docs.ollama.com/macos)
|
|
255
|
-
- [Apple power modes](https://support.apple.com/en-lamr/101613)
|