Skip to content

feat(service-matcher): rank via languageModelService instead of llm-bridge#955

Draft
grypez wants to merge 2 commits into
mainfrom
grypez/matcher-uses-klms
Draft

feat(service-matcher): rank via languageModelService instead of llm-bridge#955
grypez wants to merge 2 commits into
mainfrom
grypez/matcher-uses-klms

Conversation

@grypez

@grypez grypez commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Summary

Replaces the matcher's @ocap/llm-bridge sidecar with the languageModelService kernel service from @metamask/kernel-language-model-service, deleting the bridge package entirely.

The bridge existed to get LLM access into the matcher vat, but the kernel already had a lockdown-safe LLM service package (klms) that does the same job without a sidecar process, a Unix socket, or a line-oriented wire protocol. This PR closes the one gap that kept klms from being usable here — the daemon had no way to register it — and rebuilds the matcher's ranking on top of it.

Daemon: llm.json config hook (@metamask/kernel-cli)

  • At startup, the daemon now reads llm.json from the OCAP home; when present, it registers a languageModelService kernel service backed by any Open /v1-compatible endpoint.
  • The config names the provider and base URL; the API key is deliberately indirected through apiKeyEnv or apiKeyFile — the struct rejects an inline key so tokens never live in the config file.
  • Missing file ⇒ no service; present-but-invalid file ⇒ the daemon fails loudly rather than silently dropping the service.

Matcher: stateless ranking (@ocap/service-matcher)

  • findServices now sends the full current registry digest plus the query in a single chat-completion request, instead of maintaining an incremental conversation in the bridge.
  • This eliminates the bridge mutex, the ingest-time LLM call on every registration, and the registry/LLM-context reconciliation problem that was blocking durable-registry work: there is no model-side state to drift out of sync, so registrations are purely local and synchronous (no rollback machinery).
  • Registration now succeeds even while the LLM endpoint is down; an empty registry short-circuits without burning a model call.
  • The vat takes a required model parameter via cluster config (e.g. openclaw or openclaw/<agentId> for an openclaw gateway).
  • Hallucination guards preserved: unknown cited IDs are skipped and logged; all-unknown replies throw loudly.

klms promoted to published scope

@ocap/kernel-language-model-service@metamask/kernel-language-model-service, since the published @metamask/kernel-cli now depends on it (yarn constraints forbid published→private deps). Licenses, README install section, and publishConfig added.

Deleted

  • packages/llm-bridge/ and all its plumbing in start-matcher.sh (build/spawn/pid/log/socket management).

Testing

  • New unit tests: llm-config.test.ts (config parsing, key resolution from env/file, service construction), ranker.test.ts (prompt formatting, reply parsing incl. markdown-fence tolerance), and a rewritten matcher-vat/index.test.ts (model param validation, registration-never-calls-LLM, registers-while-LLM-down, empty-registry short-circuit, prompt contents, hallucination skip/throw, error propagation).
  • Full build, lint, yarn constraints, and changelog validation pass; test suites pass for service-matcher, kernel-cli, kernel-language-model-service, kernel-agents, kernel-test, and kernel-test-local.

Caveat (why draft)

Ranking quality of the new stateless single-shot prompt should be validated against a live OpenClaw gateway (the VALIDATION.md walkthrough) before merge — the old bridge used an incremental conversation, and parity has only been verified at the unit-test level.

🤖 Generated with Claude Code

grypez added 2 commits June 11, 2026 17:00
…ridge

The matcher vat now calls the languageModelService kernel service
directly, replacing the external @ocap/llm-bridge process and its
Unix-socket IOChannel protocol. Ranking is stateless: each findServices
call sends the full current registry in one chat-completion request, so
registrations never involve the LLM and there is no model-side context
to drift out of sync with the registry.

- kernel-cli: the daemon registers languageModelService at startup from
  llm.json in the OCAP home (open-v1 provider; API key indirected via
  apiKeyEnv/apiKeyFile)
- kernel-language-model-service: promoted to published
  @metamask/kernel-language-model-service so the published CLI can
  depend on it
- service-matcher: stateless ranker module, model vat parameter,
  languageModelService in the cluster config; start-matcher.sh
  provisions llm.json instead of spawning a bridge
- llm-bridge: deleted
@grypez grypez added the no-changelog Indicates that no changelog updates are required, and that related CI checks should be skipped. label Jun 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 71.61%
⬆️ +0.49%
8754 / 12224
🔵 Statements 71.43%
⬆️ +0.49%
8897 / 12454
🔵 Functions 72.49%
⬆️ +0.30%
2101 / 2898
🔵 Branches 65.13%
⬆️ +0.47%
3548 / 5447
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/kernel-agents/src/agent.ts 81.48%
🟰 ±0%
72.72%
🟰 ±0%
60%
🟰 ±0%
80.76%
🟰 ±0%
107-109, 130-137
packages/kernel-agents/src/attempt.ts 100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
packages/kernel-agents/src/strategies/chat-agent.ts 90.9%
🟰 ±0%
87.5%
🟰 ±0%
100%
🟰 ±0%
90.32%
🟰 ±0%
141, 184-192
packages/kernel-cli/src/commands/daemon-entry.ts 0%
🟰 ±0%
0%
🟰 ±0%
0%
🟰 ±0%
0%
🟰 ±0%
14-150
packages/kernel-cli/src/commands/llm-config.ts 96.55% 83.33% 100% 96.55% 66
packages/kernel-test-local/src/lms-chat.ts 100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
packages/kernel-test-local/src/vats/lms-chat-vat.ts 0%
🟰 ±0%
0%
🟰 ±0%
0%
🟰 ±0%
0%
🟰 ±0%
22-38
packages/kernel-test/src/vats/lms-chat-vat.ts 0%
🟰 ±0%
0%
🟰 ±0%
0%
🟰 ±0%
0%
🟰 ±0%
22-40
packages/kernel-test/src/vats/lms-sample-vat.ts 0%
🟰 ±0%
0%
🟰 ±0%
0%
🟰 ±0%
0%
🟰 ±0%
24-32
packages/service-matcher/src/cluster-config.ts 100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
packages/service-matcher/src/matcher-vat/index.ts 89.92%
⬆️ +2.58%
71.66%
⬆️ +4.48%
96.15%
⬆️ +5.53%
89.84%
⬆️ +1.46%
116-118, 151, 182-184, 238-246, 300, 318, 340, 527, 537, 560-562
packages/service-matcher/src/matcher-vat/ranker.ts 100% 100% 100% 100%
Generated in workflow #4450 for commit 4b10448 by the Vitest Coverage Report Action

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changelog Indicates that no changelog updates are required, and that related CI checks should be skipped.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant