Commit 4fa6147
feat(kernel-language-model-service): Add language model client (#876)
## Summary
Adds a client constructor to `@ocap/kernel-language-model-service`,
allowing wiring ollama or any OpenAI-compatible language model server
into the kernel as a first-class kernel service; and extends
`@ocap/kernel-agents` with a chat-completion-based agent that uses the
standard tool-calling interface. Verified end-to-end with integration
and e2e tests in `@ocap/kernel-test-local`.
### `feat(kernel-language-model-service): Add /v1 API support and
language model client`
**Language model service supported backends**:
- Open /v1: The OpenAI `/v1/chat/completions` API is de facto standard
across industry, as evidenced by spaghetti compatibility across LiteLLM,
Ollama, llama.cpp, and anthropic.
- Ollama: Finer detail is possible with the ollama raw completions API,
which generates raw token streams instead of structured chat objects.
The REPL strategies depend upon such support.
**Vat clients** (`src/client.ts`): `makeChatClient` returns an
OpenAI-SDK-shaped object (`client.chat.completions.create(...)`) that
routes calls through a CapTP `ChatService` reference via `E()`.
`makeSampleClient` is the equivalent for raw token sampling.
**Test utilities** (`src/test-utils/`): Replaces the previous
queue-based mock model with `makeMockOpenV1Fetch` — a deterministic SSE
mock that emits a configured sequence of token strings, keeping
integration tests CI-safe and fast. `makeMockSample` provides the same
for the sample path.
Also updates `kernel-test` to use the new chat/sample API: replaces
`lms-user-vat` / `lms-queue-vat` with `lms-chat-vat` / `lms-sample-vat`
and the corresponding test files.
### `feat(kernel-agents): chat-completion-based agent with tool-calling`
Adds `makeChatAgent` to `@ocap/kernel-agents` (exported as
`@ocap/kernel-agents/chat`), a capability-augmented agent built on the
chat completions API. Capabilities are passed as `tools`, responses
arrive via `tool_calls`, and results are returned as `role: "tool"`
messages.
### `test(kernel-test-local): kernel-LMS integration tests`
Adds two test variants that share a common `runLmsChatKernelTest`
helper:
- **`lms-chat.test.ts`**: injects `makeMockOpenV1Fetch` — no network,
runs under `test:dev`.
- **`lms-chat.e2e.test.ts`** (local): uses real `fetch` against a local
Ollama instance, run via `test:e2e:local`.
Both launch a subcluster with `lms-chat-vat` through the kernel,
register the LMS kernel service, and assert that the vat logs the
model's response.
Also adds `agents.e2e.test.ts` exercising chat/json/repl agents
end-to-end, and `test/suite.test.ts` as a language-model-service
pre-flight check, whether using ollama, llama-cpp, lite-llm, etc.
Package layout is conformed to `kernel-test`: all vats, helpers, and
test files live under `src/`; `test/` holds only the pre-flight suite.
## Test plan
- [ ] `yarn workspace @ocap/kernel-test-local test:dev:quiet` — unit +
integration tests pass (no Ollama required)
- [ ] `yarn workspace @ocap/kernel-language-model-service
test:dev:quiet` — all klms unit tests pass
- [ ] `yarn workspace @ocap/kernel-agents test:dev:quiet` — all
kernel-agents unit tests pass
- [ ] With Ollama running and `llama3.2:3b` pulled: `yarn workspace
@ocap/kernel-test-local test:e2e:local`
- [ ] Or, with llama.cpp on localhost:8080 and `glm-4.7-flash` pulled
and served, `yarn workspace @ocap/kernel-test-local
test:e2e:local:llama-cpp`
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Moderate risk due to introducing new public exports and wiring for
chat/tool-calling plus new Open /v1 and expanded Ollama service paths,
which could affect downstream integrations and streaming behavior.
>
> **Overview**
> Adds a first-class chat-completions client layer to
`@ocap/kernel-language-model-service`
(`makeChatClient`/`makeSampleClient`) plus a kernel-service wrapper
(`makeKernelLanguageModelService`) so vats can call LMS backends via a
stable `/v1`-style API.
>
> Introduces an OpenAI-compatible `/v1` Node.js backend with
parameter/response validation, JSON stripping, and SSE streaming
support, and expands the Ollama backend to support `chat` and both
streaming and non-streaming raw `sample` requests (including tool-call
argument parsing).
>
> Extends `@ocap/kernel-agents` with a new `makeChatAgent` strategy
(exported as `@ocap/kernel-agents/chat`) that drives tool-calling loops,
validates tool args via new `kernel-utils` JSON-schema→Superstruct
helpers, and records chat turns as experiences; updates local and kernel
tests to exercise the new service/client paths and replaces the old
queue-based LMS test utils with deterministic
`makeMockOpenV1Fetch`/`makeMockSample`.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
6b23244. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Dimitris Marlagkoutsos <info@sirtimid.com>1 parent 7fe14e2 commit 4fa6147
72 files changed
Lines changed: 3837 additions & 1231 deletions
File tree
- packages
- kernel-agents
- src
- capabilities
- strategies
- kernel-language-model-service
- src
- ollama
- open-v1
- test-utils
- queue
- utils
- kernel-test-local
- src
- vats
- test
- e2e
- kernel-test/src
- vats
- kernel-utils
- src
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
36 | 46 | | |
37 | 47 | | |
38 | 48 | | |
| |||
186 | 196 | | |
187 | 197 | | |
188 | 198 | | |
| 199 | + | |
189 | 200 | | |
190 | 201 | | |
191 | 202 | | |
| |||
Lines changed: 59 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
Lines changed: 17 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
Lines changed: 240 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
0 commit comments