PreparedModelInteraction
CORE · interface · Type contract
Adapter output for one stage, before the caller binds capability resolution.
Import
ts
import type { PreparedModelInteraction } from '@jangts/agent-core/support';js
/** @typedef {import('@jangts/agent-core/support').PreparedModelInteraction} PreparedModelInteraction */Other public entry points:@jangts/agent-core, @jangts/agent-core/types, @jangts/agent-core/structs, @jangts/agent-core/support, @jangts/agent-core/support/model.
Definition
ts
interface PreparedModelInteraction<Result>Type parameters
| Type parameter | Constraint | Default type |
|---|---|---|
Result | — | unknown |
Field structure
| Field | Type | Required | Description |
|---|---|---|---|
options | Pick<ModelOptions, "functions" | "json" | "toolChoice" | "parallelToolCalls"> | Required | Read-only. Provider options produced from the stage's tools. |
schemaChars | number | Required | Read-only. Characters the compiled schemas add to the input, counted against the schema budget. |
instruction | string | undefined | Optional | Read-only. Instruction text that teaches the model how to answer; absent when the format is native. |
createResponse | () => ModelResponseCollector | Required | Creates a fresh collector for one call; never reuse a collector across calls. |
resolve | (selection: ModelSelection, stage: string) => Result | Required | Resolves a validated selection into the stage result. |
Member index
| Member | Purpose |
|---|---|
createResponse | Creates a fresh collector for one call; never reuse a collector across calls. |
resolve | Resolves a validated selection into the stage result. |
Member details
createResponse
Creates a fresh collector for one call; never reuse a collector across calls.
ts
PreparedModelInteraction.createResponse(): ModelResponseCollectorCreates a fresh collector for one call; never reuse a collector across calls.
No call parameters.
Returns: ModelResponseCollector<ModelSelection>.
Return value structure
| Field | Type | Required | Description |
|---|---|---|---|
call | { id: string; name: string; argumentChars: number; } | undefined | Optional | Read-only. Native function call that carried the selection, when the response used one. |
calls | readonly { id: string; name: string; argumentChars: number; toolId?: string; }[] | undefined | Optional | Read-only. All native calls carried by a session response; omitted by single-selection collectors. |
outputChars | number | Required | Read-only. Output characters accumulated so far, for output-budget accounting. |
push | (part: ModelPart) => void | Required | Appends one streamed part; parts arrive in provider order. |
finish | () => ModelSelection | Required | Finalizes the response. Throws when the accumulated content is not a valid selection. |
resolve
Resolves a validated selection into the stage result.
ts
PreparedModelInteraction.resolve(selection: ModelSelection, stage: string): ResultResolves a validated selection into the stage result.
| Parameter | Type | Passing | Description |
|---|---|---|---|
selection | ModelSelection | Required | — |
stage | string | Required | — |
Fields of selection
| Field | Type | Required | Description |
|---|---|---|---|
input | Record<string, unknown> | Required | Read-only. Arguments exactly as produced by the model, before schema parsing. |
call | { id: string; name: string; argumentChars: number; } | undefined | Optional | Read-only. Native function call that carried the selection, when the provider used one. |
toolId | string | Required | Read-only. Capability the selection resolved to. |
Returns: Result.
Awaited value: Awaited<Result>.
Examples
- Model transport and stage projection: Generate a sealed catalog and stage projections from tool definitions; native functions and JSON adapters share the same tool contract.
Create a named text transport
Beginner · Node.js
ts
import { ModelRunner, Support } from '@jangts/agent-core';
const text = Support.createTextTransport({ id: 'brief', options: { temperature: 0.2 } });
const runner = new ModelRunner({ provider: { async *stream() { yield '服务正常'; } }, transports: [text] });
console.log((await runner.invoke({ input: '简答服务状态', transport: text })).value);js
import { ModelRunner, Support } from '@jangts/agent-core';
const text = Support.createTextTransport({ id: 'brief', options: { temperature: 0.2 } });
const runner = new ModelRunner({ provider: { async *stream() { yield '服务正常'; } }, transports: [text] });
console.log((await runner.invoke({ input: '简答服务状态', transport: text })).value);Generate transports for two stages from same-source tools
Configuration · Node.js
ts
import { Support } from '@jangts/agent-core';
const inputSchema = Support.defineSchema({
jsonSchema: { type: 'object', properties: {}, additionalProperties: false },
parse(value: unknown) {
if (!value || typeof value !== 'object' || Array.isArray(value) || Object.keys(value).length) throw new TypeError('需要空对象');
return {};
},
});
const tools = Support.defineModelTools([
{ id: 'greet', description: '问候', inputSchema, resolve: () => 'greet' },
{ id: 'status', description: '状态查询', inputSchema, resolve: () => 'status' },
]);
const transport = Support.createStageModelTransport({ id: 'intent', tools,
stages: [{ id: 'recognize', toolIds: ['greet', 'status'] }, { id: 'status-only', toolIds: ['status'] }],
});
console.log(transport.prepare('status-only').schemaChars);js
import { Support } from '@jangts/agent-core';
const inputSchema = Support.defineSchema({
jsonSchema: { type: 'object', properties: {}, additionalProperties: false },
parse(value) {
if (!value || typeof value !== 'object' || Array.isArray(value) || Object.keys(value).length)
throw new TypeError('需要空对象');
return {};
},
});
const tools = Support.defineModelTools([
{ id: 'greet', description: '问候', inputSchema, resolve: () => 'greet' },
{ id: 'status', description: '状态查询', inputSchema, resolve: () => 'status' },
]);
const transport = Support.createStageModelTransport({ id: 'intent', tools,
stages: [{ id: 'recognize', toolIds: ['greet', 'status'] }, { id: 'status-only', toolIds: ['status'] }],
});
console.log(transport.prepare('status-only').schemaChars);Related policy source
- Stage list validation and dynamic source snapshots
- Explicit model interaction adapter catalog
- Session transport for prose and multiple tool calls