Interface: ContextAssembler
Defined in: internal/context-assembler/ContextAssembler.ts:99
ContextAssembler -- ten inputs in, one request out
About
The one place where the order and the shape of what the model reads is decided.
Renders the tenant's CHAT_MAIN template with its slots (output format, addendum, skills, today, locale, timezone, the
call's instructions and context, the memory, the knowledge-base chunks), asks the WorkingMemory for the thread's window
with the budget the system prompt leaves (D122), inlines the files the model can read, trims an overflow and returns the
IModelRequest with its provenance: template version, chunk ids, estimated tokens, warnings. With promptCaching the
prompt is split at {cacheBreakpoint} into the stable block, marked for the provider's cache, and the per-call block
(D123); the stable block is scoped to the tenant unless sharing is on.
Sits between prepareCall, which gathers the inputs, and the LLMClient, which sends the request.
Who needs it
prepareCall, once per ask and run. Constructed once from IAIGatewayConfig.contextAssembler; a host replaces it
through IAIGatewayDeps.contextAssembler.
What needs
IContextAssemblerConfig: the output reserve and the two prompt-cache switches. IContextAssemblerDeps: the
PromptTemplateStore, the SkillRegistry and the WorkingMemory.
Pitfalls
Pure transform, no I/O but the template render and the memory's load. The template is the tenant admin's: a {skills}
placeholder missing or a per-call slot before {cacheBreakpoint} is reported as a WARNING, never thrown. The file
bytes are not in the token estimate of the trim; reserveOutputTokens covers that gap.
Implements
Methods
build()
build(
__namedParameters):Promise<IAssembledContext>
Defined in: internal/context-assembler/ContextAssembler.ts:127
build -- the model request of one call
About
System prompt first, then the history that fits, then the trim.
Renders CHAT_MAIN (output format, addendum, skills, today, locale, timezone, instructions, context, memory,
knowledge-base chunks) and asks the working memory for the thread's window with the budget that is left
(contextTokens − reserveOutputTokens − system); its notes are rendered into {memory} after the user's facts. While
the request would still overflow the model's window, the oldest messages are left out first (turns_trimmed), then the
lowest-ranked chunks (kb_chunks_trimmed); the notes and the facts are never cut. The skills are listed by name and
description when dyna_aigw_load_skill is among the tools, written out otherwise; a stored CHAT_MAIN without {skills} drops
them with the WARNING skills_slot_missing. The files of the question go into its message when the model can read
their type (images, PDF); another file is left out with the WARNING file_dropped. Returns the request, the template
version, the chunk ids that are in it, the estimated input tokens and the warnings.
Who needs it
prepareCall, for every ask and run.
Parameters
__namedParameters
input
Returns
Promise<IAssembledContext>
Implementation of
IContextAssembler.build