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";@pleach/core/adaptersWhat 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:
| Era | Capability sat in | Today |
|---|---|---|
0.x | Loader seam | Loader seam |
1.0.0 | Loader seam | Loader seam (absorption started) |
1.1.x | Loader seam | Some keys retired; rest stable |
| Future | Typed SessionRuntimeConfig strategies, HarnessPlugin hooks | Loader seam minimal residual |
Keys retired so far:
| Retired key | Replaced by |
|---|---|
orchestrator.streamHelpers | SessionRuntimeConfig.metaToolNames (typed config) |
orchestrator.fabricationGuard | setOrchestratorHotpathModules({ 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.
| Path | What changes |
|---|---|
| Absorption | The capability moves into the runtime, with no surface change for you |
| Typed config | The loader-resolved value becomes a typed field on SessionRuntimeConfig |
| Plugin contract | The 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";| Field | Holds |
|---|---|
host.strategies | Host-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.modules | Operator-supplied module shims the runtime composes against — eventLogWriter, store, interrupt. These are substrate dependencies, not plugin contributions. |
host.raw | Uncategorized 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 entry | Use instead |
|---|---|
streamHelpers | SessionRuntimeConfig.metaToolNames (the entry is removed). |
toolCoupling | Contribute hints with HarnessPlugin.contributeToolCouplingHints and read them through runtime.plugins.collectToolCouplingHints(). |
fabricationGuard | Register 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/:
| File | Purpose |
|---|---|
index.mjs | Minimal no-op adapter that throws a doc-pointer error for every key |
production-reference.ts | Full 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:
| Phase | Keys resolved |
|---|---|
| Runtime construction | supabase, stores.*, registry constants |
| Turn start | orchestrator.intentDetector, orchestrator.fileIntentDetector |
| Stream phase | orchestrator.streamSingleTurn, orchestrator.streamDegenerationGuards |
| Tool dispatch | orchestrator.tools.* (registry, dataflow, guards, execution) |
| Synthesis | orchestrator.synthesis.*, orchestrator.finalization.finalizeContent |
| Quality / post-turn | orchestrator.quality.evaluator, orchestrator.workflow.workflowHintResolver |
| Middleware | orchestrator.middleware.creditBudget, orchestrator.middleware.safetyReview, orchestrator.middleware.enrichmentCitations |
| Provider fallback | orchestrator.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
providerconfig field for LLM execution. - Use the
pluginsconfig field for domain extensions. - Use
metaToolNamesfor continuation flow control. - Register tools through plugin
contributeToolsor the legacysetOrchestratorRegistryshim.
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
MCP integration
Integrate MCP servers from `@pleach/core` today — the `defineTool` wrapper pattern. Distinct from the `@pleach/mcp` SKU (see [/docs/mcp]).
@pleach/transport-azure-openai
First-party Azure OpenAI Service transport for cloud-routed Pleach runtimes — API-key, token-callback, or opt-in managed-identity auth, deployment-name routing, and generic auth errors.