ContextAssemblyOptions
SUPPORT · interface · Type contract
Assembly options for placement-based projections.
Import
ts
import type { ContextAssemblyOptions } from '@jangts/agent-core/support';1
js
/** @typedef {import('@jangts/agent-core/support').ContextAssemblyOptions} ContextAssemblyOptions */1
Other public entry points:@jangts/agent-core, @jangts/agent-core/types, @jangts/agent-core/structs, @jangts/agent-core/support, @jangts/agent-core/support/context.
Definition
ts
interface ContextAssemblyOptions<Input, Id, Placement>1
Extends or implements: ContextBuilderOptions<Input>.
Type parameters
| Type parameter | Constraint | Default type |
|---|---|---|
Input | — | — |
Id | string | — |
Placement | string | — |
Field structure
| Field | Type | Required | Description |
|---|---|---|---|
fragment | (id: Id, value: ContextFragment["value"]) => ContextFragment | Required | Read-only. Builds a fragment for a single-fragment projection. |
contributions | Readonly<Record<Placement, (input: Input) => readonly ContextFragment[]>> | undefined | Optional | Read-only. Contribution handlers keyed by placement; each expands to zero or more fragments. |
maxInputChars | number | ((input: Input) => number) | undefined | Optional | Read-only. Character budget, constant or derived from the request; at least one of these is required. |
transform | ((fragment: ContextFragment, input: Input) => ContextFragment) | undefined | Optional | Read-only. Applied to every produced fragment before assembly; must be synchronous. |
Member index
| Member | Purpose |
|---|---|
fragment | Builds a fragment for a single-fragment projection. |
Member details
fragment
Builds a fragment for a single-fragment projection.
ts
ContextAssemblyOptions.fragment(id: Id, value: ContextFragment["value"]): ContextFragment1
| Parameter | Type | Passing | Description |
|---|---|---|---|
id | Id | Required | — |
value | string | Record<string, unknown> | Required | — |
Returns: ContextFragment.
Return value structure
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Required | Unique, stable id matching ^[a-z][a-zA-Z0-9:._-]*$; duplicates are rejected. |
sourceId | string | Required | Owning source (module or registration) used to explain where the content came from. |
trust | ContextTrust | Required | Producer trust level. user and tool content cannot become a system message. |
lifetime | ContextLifetime | Required | Declared validity window of this content. |
maxChars | number | Required | Hard upper bound in JSON characters; must be a positive safe integer. |
role | "system" | "user" | Required | Message slot the fragment occupies when assembled. |
value | string | Record<string, unknown> | Required | Rendered content. A system message accepts a string only, never a record. |
Examples
- Context assembly: configure stable metadata once: Support binds fragment metadata, formatting, and order in advance, and requests supply only the changing business input.
Configure once, then supply only question and history
Beginner · Node.js
ts
import { Support } from '@jangts/agent-core';
type Input = { question: string; history: readonly { role: string; content: string }[] };
const builder = Support.defineContextFragments<Input>([
{ id: 'question', sourceId: 'request', trust: 'user', lifetime: 'turn', maxChars: 1000,
role: 'user', format: input => input.question },
{ id: 'history', sourceId: 'conversation', trust: 'user', lifetime: 'turn', maxChars: 10000,
role: 'user', format: input => ({ messages: input.history }) },
], { maxInputChars: 1200 });
const context = builder.build({ input: { question: '服务状态?', history: [] } });
console.log(context.messages);1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
js
import { Support } from '@jangts/agent-core';
const builder = Support.defineContextFragments([
{ id: 'question', sourceId: 'request', trust: 'user', lifetime: 'turn', maxChars: 1000,
role: 'user', format: input => input.question },
{ id: 'history', sourceId: 'conversation', trust: 'user', lifetime: 'turn', maxChars: 10000,
role: 'user', format: input => ({ messages: input.history }) },
], { maxInputChars: 1200 });
const context = builder.build({ input: { question: '服务状态?', history: [] } });
console.log(context.messages);1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
The same builder produces a plan in advance
Configuration · Node.js
ts
import { Support } from '@jangts/agent-core';
type Input = { question: string; history: readonly { role: string; content: string }[] };
const builder = Support.defineContextFragments<Input>([
{ id: 'question', sourceId: 'request', trust: 'user', lifetime: 'turn', maxChars: 1000,
role: 'user', format: input => input.question },
{ id: 'history', sourceId: 'conversation', trust: 'user', lifetime: 'turn', maxChars: 10000,
role: 'user', format: input => ({ messages: input.history }) },
], { maxInputChars: 1200 });
const input = { question: '服务状态?', history: [] };
const plan = builder.plan({ input });
const expanded = builder.fragments(input);
console.log(plan.maxInputChars, expanded.map(fragment => fragment.id));
const largerRequest = builder.build({ input, maxInputChars: 2000 });
console.log(largerRequest.maxInputChars);1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
js
import { Support } from '@jangts/agent-core';
const builder = Support.defineContextFragments([
{ id: 'question', sourceId: 'request', trust: 'user', lifetime: 'turn', maxChars: 1000,
role: 'user', format: input => input.question },
{ id: 'history', sourceId: 'conversation', trust: 'user', lifetime: 'turn', maxChars: 10000,
role: 'user', format: input => ({ messages: input.history }) },
], { maxInputChars: 1200 });
const input = { question: '服务状态?', history: [] };
const plan = builder.plan({ input });
const expanded = builder.fragments(input);
console.log(plan.maxInputChars, expanded.map(fragment => fragment.id));
const largerRequest = builder.build({ input, maxInputChars: 2000 });
console.log(largerRequest.maxInputChars);1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13