Skip to content

llmPlanner

llmPlanner(options): Stage<LlmPlannerInput, PlannerCandidate>

Defined in: packages/planner-llm/src/lib/llm-planner.ts:103

A planner that asks one LLM for the whole candidate in a single chat() call: the system prompt for the request’s layout mode, the user prompt serialized from the request (plus any hints), prior history, and the layout mode’s structured output schema.

On a retry from the engine’s withRetry the user prompt becomes the original prompt preceded by the previous attempt’s diagnostics; the system prompt is unchanged. The original prompt is reused rather than rebuilt, so prompt customizers and serializer warnings run once per request.

When the input’s Vessel catalog is the one in ctx.origin, the prompt reuses ctx.enumSnapshot, so the enum literals the model sees are exactly those validation accepts. Any other catalog gets a fresh snapshot.

Returns Err(ValidationError) on field 'prompt' when the user prompt cannot be built, and the callLLM errors (ProviderError, CancellationError) when the call fails; each is logged. The candidate is returned unvalidated.

Each model call is reported to ctx.instrument as an llm.call event with gen_ai.request.model (the adapter’s model), maelstrom.outcome (ok, error or cancelled) and maelstrom.latency_ms. Token usage is not reported: chat() exposes it only to middleware.

LlmPlannerOptions

Stage<LlmPlannerInput, PlannerCandidate>

If options is invalid or a system-prompt customizer is misconfigured. System prompts are built once here, so the error surfaces at construction. The message starts with Invalid LlmPlannerOptions: and the original error is attached as cause.

const planner = llmPlanner({ adapter: openaiText('gpt-4o') });