Skip to content
中文

ModelCallRequest ​

CORE · type · Type contract

One model call request. The input shape selects prompt mode or message mode.

Import ​

ts
import type { ModelCallRequest } from '@jangts/agent-core/model';
js
/** @typedef {import('@jangts/agent-core/model').ModelCallRequest} ModelCallRequest */

Other public entry points:@jangts/agent-core, @jangts/agent-core/model, @jangts/agent-core/types, @jangts/agent-core/structs.

Definition ​

Type: ModelCallRequest<Transport>

Type parameters ​

Type parameterConstraintDefault type
Transport—string

Union branch structure ​

Optional shapes of ModelCallRequest: choose one shape; required fields for each branch are listed separately.

Branch 1
FieldTypeRequiredDescription
loggerSubFlowLogger | undefinedOptionalRead-only. Record this call in the supplied logger; omission adds no sub-flow record.
signalAbortSignal | undefinedOptionalRead-only. Additional cancellation can shorten, never replace, the Runner lifetime.
diagnosticsDiagnosticContext | undefinedOptionalRead-only. Parent observation scope for this invocation; never changes execution budget or signal.
preparedPreparedModelCall<unknown> | undefinedOptionalRead-only. Reuse a prepared call; its stage, transport and output reservation then take precedence.
maxOutputTokensnumber | undefinedOptionalRead-only. See the type definition and usage context.
stageIdstring | undefinedOptionalRead-only. See the type definition and usage context.
transportTransport | undefinedOptionalRead-only. See the type definition and usage context.
inputstringRequiredSee the type definition and usage context.
instructionsstring | undefinedOptionalSee the type definition and usage context.
Branch 2
FieldTypeRequiredDescription
loggerSubFlowLogger | undefinedOptionalRead-only. Record this call in the supplied logger; omission adds no sub-flow record.
signalAbortSignal | undefinedOptionalRead-only. Additional cancellation can shorten, never replace, the Runner lifetime.
diagnosticsDiagnosticContext | undefinedOptionalRead-only. Parent observation scope for this invocation; never changes execution budget or signal.
preparedPreparedModelCall<unknown> | undefinedOptionalRead-only. Reuse a prepared call; its stage, transport and output reservation then take precedence.
maxOutputTokensnumber | undefinedOptionalRead-only. See the type definition and usage context.
stageIdstring | undefinedOptionalRead-only. See the type definition and usage context.
transportTransport | undefinedOptionalRead-only. See the type definition and usage context.
inputreadonly ModelMessage[] | BuiltContext | ContextPlanRequiredSee the type definition and usage context.
instructionsundefinedOptionalSee the type definition and usage context.

Examples ​

Two inputs for the same output ​

Beginner · Node.js

ts
import { ModelRunner } from '@jangts/agent-core/model';
const provider = {
  async *stream(messages: readonly { content: string }[]) {
    yield '收到:' + messages.at(-1)!.content;
  },
};
const runner = new ModelRunner({ provider });
const first = await runner.invoke('你好');
const second = await runner.invoke({ input: '你好' });
console.log(first.value, second.value);
console.log(first.invocation.invocationId);
js
import { ModelRunner } from '@jangts/agent-core/model';
const provider = {
    async *stream(messages) {
        yield '收到:' + messages.at(-1).content;
    },
};
const runner = new ModelRunner({ provider });
const first = await runner.invoke('你好');
const second = await runner.invoke({ input: '你好' });
console.log(first.value, second.value);
console.log(first.invocation.invocationId);

Add budget and request cancellation ​

Configuration · Node.js

ts
import { ModelRunner } from '@jangts/agent-core/model';
const provider = {
  async *stream(messages: readonly { content: string }[]) {
    yield '收到:' + messages.at(-1)!.content;
  },
};
const runner = new ModelRunner({ provider, maxCalls: 2, maxInputChars: 4000,
  maxOutputChars: 2000, callTimeoutMs: 15000,
  execution: { signal: AbortSignal.timeout(20000) },
});
const result = await runner.invoke({ input: '你好', stageId: 'reply', maxOutputTokens: 600 });
console.log(result.value, runner.remainingCalls);
js
import { ModelRunner } from '@jangts/agent-core/model';
const provider = {
    async *stream(messages) {
        yield '收到:' + messages.at(-1).content;
    },
};
const runner = new ModelRunner({ provider, maxCalls: 2, maxInputChars: 4000,
    maxOutputChars: 2000, callTimeoutMs: 15000,
    execution: { signal: AbortSignal.timeout(20000) },
});
const result = await runner.invoke({ input: '你好', stageId: 'reply', maxOutputTokens: 600 });
console.log(result.value, runner.remainingCalls);

API reference, usage examples and developer guides.