@arnilo/prism-compaction-llm
v0.3.0
Published
LLM-backed compaction strategy package for Prism.
Maintainers
Readme
@arnilo/prism-compaction-llm
Optional LLM-backed compaction strategy package for Prism. It is inert until a host imports it and passes a strategy to session.compact() or AgentConfig.compaction.
import { createLlmCompactionStrategy } from "@arnilo/prism-compaction-llm";
const strategy = createLlmCompactionStrategy({
provider: summaryProvider,
model: { provider: "mock", model: "cheap-summary" },
keepRecentTokens: 20_000,
reserveTokens: 16_384,
maxSummaryTokens: 4_096,
maxErrorBytes: 1_024,
providerOptions: { cacheRetention: "short" },
customInstructions: "Focus on current files and failing tests.",
});
await session.compact({ strategy, secrets: [apiKey] });For a coding-session focus, use the fixed coding preset. It retains the same limits, provider call count, raw history, and redaction behavior while prioritizing paths, patch intent, commands/checks, plan/todos, blockers, and next verification.
import { createCodingCompactionStrategy } from "@arnilo/prism-compaction-llm";
await session.compact({ strategy: createCodingCompactionStrategy({ provider: summaryProvider, model: summaryModel }) });Extension registration is optional and inert until the host selects the contribution:
import { createExtensionKernel } from "@arnilo/prism";
import { createLlmCompactionExtension } from "@arnilo/prism-compaction-llm";
const kernel = createExtensionKernel();
await kernel.load([createLlmCompactionExtension({ provider: summaryProvider, model: summaryModel })]);
const selected = kernel.registries.compactionStrategies.resolve("llm-compaction");Use summaryProvider plus credential when the provider must be built from a per-call credential:
const strategy = createLlmCompactionStrategy({
summaryProvider: (apiKey) => createProvider({ apiKey }),
credential: credentials,
credentialRequest: { provider: "example", name: "apiKey" },
summaryModel: { provider: "example", model: "cheap-summary" },
});Summary retention defaults to 16,384 approximate tokens (131,072 hard), reserve defaults to 16,384 (131,072 hard), and provider error detail defaults to 1 KiB (8 KiB hard). Limits reject invalid values at strategy creation. Every request keeps finite model.parameters.maxTokens; streamed text/event retention stops at the configured budget and provider errors are bounded/redacted.
No provider SDKs, credentials, network calls, or filesystem discovery run at import/setup time.
