Skip to content
pleach
Integrate

Host adapter

`setHarnessModuleLoader` — the dynamic-import seam hosts mid-migration use to wire their own implementations of capabilities the substrate hasn't fully absorbed yet.

new SessionRuntime() constructs with zero config. But runtime.executeMessage(...) reaches back into the host application for capabilities the substrate doesn't ship absorbed yet — streaming utilities, fabrication guards, intent detectors, citation enrichers, tool registries. The seam is setHarnessModuleLoader.

This page is for hosts mid-migration. If you're building a new agent on @pleach/core, prefer the typed config surfaces (provider, tools, plugins, metaToolNames) — the loader seam exists for hosts that grew up with the substrate inside a larger app and are unwinding the integration gradually.

import {
  setHarnessModuleLoader,
  type HarnessModuleKey,
  type HarnessModuleLoader,
} from "@pleach/core/runtime";
Subpath@pleach/core/adapters

What happens without it

Calling executeMessage without registering a loader produces:

HarnessModuleLoaderUnregisteredError: [harness] Module loader is not
registered. Tried to load key="orchestrator.intentDetector".
The host application must call setHarnessModuleLoader(...) at startup …

The error names the first key the runtime actually reaches for on a turn — an early turn-start key like orchestrator.intentDetector, not a later stream-phase key. Wire the loader at startup and the error goes away.

The 30-second contract

import { setHarnessModuleLoader, type HarnessModuleKey } from "@pleach/core/runtime";

setHarnessModuleLoader((key: HarnessModuleKey) => {
  switch (key) {
    case "orchestrator.streamDegenerationGuards":
      return import("@your-app/streamDegenerationGuards");
    case "orchestrator.fabricationGuard":
      return import("@your-app/fabricationGuard");
    case "orchestrator.intentDetector":
      return import("@your-app/intentDetector");
    // ... ~40 more keys ...
    default:
      throw new Error(`Unhandled harness module key: ${key}`);
  }
});

HarnessModuleKey is a string-literal union. TypeScript will tell you when a new key gets added — the default arm catches anything your switch doesn't cover.

The retirement direction

The loader surface is shrinking, not growing. Each @pleach/core release retires keys as the underlying capability moves into the substrate as typed config:

EraCapability sat inToday
0.xLoader seamLoader seam
1.0.0Loader seamLoader seam (absorption started)
1.1.xLoader seamSome keys retired; rest stable
FutureTyped SessionRuntimeConfig strategies, HarnessPlugin hooksLoader seam minimal residual

Keys retired so far:

Retired keyReplaced by
orchestrator.streamHelpersSessionRuntimeConfig.metaToolNames (typed config)
orchestrator.fabricationGuardsetOrchestratorHotpathModules({ fabricationGuard }) (registered shim)

Don't re-register a retired key; pass its typed replacement instead.

Migration paths

A loader key leaves the loader seam in one of three ways. You can adopt each independently.

PathWhat changes
AbsorptionThe capability moves into the runtime, with no surface change for you
Typed configThe loader-resolved value becomes a typed field on SessionRuntimeConfig
Plugin contractThe loader-resolved value becomes a HarnessPlugin contribution hook

The reference adapter in the package's examples/host-adapter/ directory comments each arm that moved into the runtime. If you copy from it, delete those arms rather than wiring them.

CreatePleachRuntimeConfig.host.{strategies, modules, raw}

createPleachRuntime() accepts a typed host carveout that groups the host-private substrate dependencies under three named fields. The carveout is the destination loader-bag keys absorb into as they retire — once a key lands here, the loader stops being asked for it on that runtime.

import {
  createPleachRuntime,
  type CreatePleachRuntimeConfig,
} from "@pleach/core";
FieldHolds
host.strategiesHost-private strategy injection slots — the cohort marked @strategy.host-private on SessionRuntimeConfig. Typed as Partial<Pick<SessionRuntimeConfig, ...>> over a 15-key list (see below).
host.modulesOperator-supplied module shims the runtime composes against — eventLogWriter, store, interrupt. These are substrate dependencies, not plugin contributions.
host.rawUncategorized escape hatch. Accepts any Partial<SessionRuntimeConfig>. Use only when neither the typed groups above nor the top-level options expose the field.

The 15 keys host.strategies accepts (from HostExtensionBundle):

orchestratorConfig, lineageTracker, agentRegistry, planManager, learningAuditor, preserveDataRefFields, getDataHandlerFactory, dataChannelRefetch, continuationShadowResolver, entityNameCounter, structurePrefetcher, artifactCacheReader, guestDeniedTools, fabricationDetectorRules, recordGarbledOutput.

The 3 keys host.modules accepts: eventLogWriter, store, interrupt.

const config: CreatePleachRuntimeConfig = {
  plugins: [compliancePlugin, gatewayPlugin],
  host: {
    strategies: {
      lineageTracker: myLineageTracker,
      planManager: myPlanManager,
      guestDeniedTools: GUEST_DENIED,
    },
    modules: {
      eventLogWriter: mySupabaseEventLogWriter,
      store: myMultiNamespaceKV,
    },
    // raw: { ... }  — only when a field is neither classified above nor a top-level option
  },
  userId: "user_123",
};

const runtime = createPleachRuntime(config);

The three fields are independent. A host can fill strategies without touching modules; a host with no operator-supplied module shims can omit modules entirely. raw is the safety valve — prefer strategies/modules when applicable so the autocomplete surface stays meaningful.

Merge precedence

Top-level fields → host.strategies → host.modules → host.raw → (deprecated) advanced. Higher precedence wins on key collision. advanced?: Partial<SessionRuntimeConfig> stays in the shape for 1.x back-compat with the pre-1.0 surface; it retires in 2.0. New hosts shouldn't reach for advanced.

Moving off the orchestratorHotpath bag

The orchestratorHotpath bag is a legacy fallback. Each entry has a typed replacement; move to it and stop reading getOrchestratorHotpathModules() directly.

Bag entryUse instead
streamHelpersSessionRuntimeConfig.metaToolNames (the entry is removed).
toolCouplingContribute hints with HarnessPlugin.contributeToolCouplingHints and read them through runtime.plugins.collectToolCouplingHints().
fabricationGuardRegister through the typed contributeFabricationGuard hook.

Hosts adopting facets read through the plugins facet (runtime.plugins.collect*), not the bag. See Facets.

From bare properties to contribute* methods

Move the four soft-deprecated bare properties to their typed contribute* method form by hand:

tools: [a, b]            →  contributeTools: () => [a, b]
events: { foo: ... }     →  contributeEventTypes: () => ({ foo: ... })
customEventTypes: [...]  →  contributeEventTypes: () => [...]
batchingHints: [a, b]    →  contributeBatchingHints: () => [a, b]

Each change is a one-line edit in the plugin's object literal. If a contribute* method already exists next to the bare property, merge the two by hand. Keep one contributeEventTypes: fold customEventTypes and events into it.

The result composes with definePleachPlugin without further edits.

setOrchestratorHotpathModules

A second registration helper for hot-path modules — capabilities called synchronously inside the per-call seam loop, where dynamic import overhead would matter.

import { setOrchestratorHotpathModules } from "@pleach/core/runtime";

setOrchestratorHotpathModules({
  fabricationGuard: fabricationGuardModule as never,
  // ... other hotpath modules
});

Used for capabilities that are domain-coupled in a way the substrate doesn't want to absorb. The fabrication guard, for example, carries host-specific regex tables (tool aliases, phantom tool replacements, identifier patterns) — registering it synchronously keeps host-domain rules in host code without introducing dynamic-import latency on the per-call path.

metaToolNames

Hosts that previously resolved the continuation meta-tool names through the loader should now pass them as typed config:

import { SessionRuntime } from "@pleach/core";

const runtime = new SessionRuntime({
  metaToolNames: new Set([
    "set_step_complete",
    "wait_for_jobs",
    // ... your meta-tool names
  ]),
  // ...other config
});

Without the field, the runtime fires a one-shot probe lazily on the first read of the meta-tool set (not at construction) — the _getMetaToolNames() accessor emits it the first time a guard reaches for the set and finds it undefined:

[UXParity:metaToolNames-config-missing] { reason: "metaToolNames-undefined-at-read", ... }

The runtime then falls back to a shared empty set, which silently disables continuation and fabrication guards that key off the set. (setOrchestratorAdapter is unrelated — it's a deprecated delegating stub that forwards to the adapter facet and emits no metaToolNames warning.) Fix by passing the field; never ship past the probe in production.

The reference adapter

The package ships two reference adapter files at examples/host-adapter/:

FilePurpose
index.mjsMinimal no-op adapter that throws a doc-pointer error for every key
production-reference.tsFull production-shaped adapter with vendor paths neutralized to @your-app/*

Start from index.mjs for a brand-new host — implement one key at a time as you need it. Crib from production-reference.ts to see the full set of keys a mature integration wires.

What gets called when

Different keys resolve at different turn phases. A rough map:

PhaseKeys resolved
Runtime constructionsupabase, stores.*, registry constants
Turn startorchestrator.intentDetector, orchestrator.fileIntentDetector
Stream phaseorchestrator.streamSingleTurn, orchestrator.streamDegenerationGuards
Tool dispatchorchestrator.tools.* (registry, dataflow, guards, execution)
Synthesisorchestrator.synthesis.*, orchestrator.finalization.finalizeContent
Quality / post-turnorchestrator.quality.evaluator, orchestrator.workflow.workflowHintResolver
Middlewareorchestrator.middleware.creditBudget, orchestrator.middleware.safetyReview, orchestrator.middleware.enrichmentCitations
Provider fallbackorchestrator.providers.circuitBreaker, orchestrator.providers.fallbackExecutor, orchestrator.providers.modelAvailabilityChecker

The runtime does not cache resolved modules itself — dynamicImportApp re-invokes the registered loader on every call. Deduplication comes from the process-wide import() module cache the loader delegates to, so a key resolves cheaply on repeat reaches but the loader still runs each time (scope is process-wide, not per-runtime-lifetime).

When you don't need the loader

For a brand-new host that's not bringing a legacy orchestrator into the substrate:

  • Use the typed provider config field for LLM execution.
  • Use the plugins config field for domain extensions.
  • Use metaToolNames for continuation flow control.
  • Register tools through plugin contributeTools or the legacy setOrchestratorRegistry shim.

You'll still hit some loader-required keys (the substrate is mid- migration), but the minimum set is small. The no-op adapter at examples/host-adapter/index.mjs implements just the keys required for a first-turn execution to land.

Where to go next