Skip to content
English

ModelChildOptions ​

CORE · interface · 类型合同

Request-bound isolated runner settings; provider and ancestor budgets cannot be replaced.

导入 ​

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

其他公开入口:@jangts/agent-core、@jangts/agent-core/model、@jangts/agent-core/types、@jangts/agent-core/structs。

定义 ​

ts
interface ModelChildOptions

字段结构 ​

字段类型必需说明
idstring必需只读。Child stage id, reported in traces and events.
maxCallsnumber必需只读。Calls the child may use from the shared request budget.
reserveCallsnumber必需只读。Calls kept for the parent; the child cannot spend them.
timeoutMsnumber必需只读。Deadline for the child's own calls, in milliseconds.
transportsreadonly ModelTransportDefinition<unknown>[] | undefined可省略只读。Additional transports visible to the child.
diagnosticsDiagnosticContext | undefined可省略只读。见类型定义及调用场景。
signalAbortSignal | undefined可省略只读。Extra cancellation; can only shorten the parent's lifetime.

使用示例 ​

为子执行配置一次调用额度 ​

入门 · Node.js

ts
import { ModelRunner } from '@jangts/agent-core/model';
const provider = {
  async *stream(messages: readonly { content: string }[]) {
    yield '收到:' + messages.at(-1)!.content;
  },
};
const parent = new ModelRunner({ provider, maxCalls: 3 });
const child = parent.createChild({ id: 'service-review', maxCalls: 1, reserveCalls: 1,
  timeoutMs: 10000, transports: [] });
const report = await child.invoke('独立核对服务状态');
console.log(report.value, parent.totalCallCount, child.callCount);
js
import { ModelRunner } from '@jangts/agent-core/model';
const provider = {
    async *stream(messages) {
        yield '收到:' + messages.at(-1).content;
    },
};
const parent = new ModelRunner({ provider, maxCalls: 3 });
const child = parent.createChild({ id: 'service-review', maxCalls: 1, reserveCalls: 1,
    timeoutMs: 10000, transports: [] });
const report = await child.invoke('独立核对服务状态');
console.log(report.value, parent.totalCallCount, child.callCount);

子报告返回后再由父级完成回答 ​

配置 · Node.js

子任务完成后再调用父模型,没有 Promise.all。父级仍负责核对报告来源和业务完成性。

ts
import { ModelRunner } from '@jangts/agent-core/model';
const provider = {
  async *stream(messages: readonly { content: string }[]) {
    yield '收到:' + messages.at(-1)!.content;
  },
};
const parent = new ModelRunner({ provider, maxCalls: 3 });
const child = parent.createChild({ id: 'service-review', maxCalls: 1, reserveCalls: 1,
  timeoutMs: 10000, transports: [] });
const report = await child.invoke('核对状态证据');
const answer = await parent.invoke('根据已核对报告回答:' + report.value);
console.log(answer.value);
js
import { ModelRunner } from '@jangts/agent-core/model';
const provider = {
    async *stream(messages) {
        yield '收到:' + messages.at(-1).content;
    },
};
const parent = new ModelRunner({ provider, maxCalls: 3 });
const child = parent.createChild({ id: 'service-review', maxCalls: 1, reserveCalls: 1,
    timeoutMs: 10000, transports: [] });
const report = await child.invoke('核对状态证据');
const answer = await parent.invoke('根据已核对报告回答:' + report.value);
console.log(answer.value);

相关定义 ​

接口参考、使用示例与开发指南。