ModelChildOptions
CORE · interface · 类型合同
Request-bound isolated runner settings; provider and ancestor budgets cannot be replaced.
导入
ts
import type { ModelChildOptions } from '@jangts/agent-core/model';1
js
/** @typedef {import('@jangts/agent-core/model').ModelChildOptions} ModelChildOptions */1
其他公开入口:@jangts/agent-core、@jangts/agent-core/model、@jangts/agent-core/types、@jangts/agent-core/structs。
定义
ts
interface ModelChildOptions1
字段结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
id | string | 必需 | 只读。Child stage id, reported in traces and events. |
maxCalls | number | 必需 | 只读。Calls the child may use from the shared request budget. |
reserveCalls | number | 必需 | 只读。Calls kept for the parent; the child cannot spend them. |
timeoutMs | number | 必需 | 只读。Deadline for the child's own calls, in milliseconds. |
transports | readonly ModelTransportDefinition<unknown>[] | undefined | 可省略 | 只读。Additional transports visible to the child. |
diagnostics | DiagnosticContext | undefined | 可省略 | 只读。见类型定义及调用场景。 |
signal | AbortSignal | undefined | 可省略 | 只读。Extra cancellation; can only shorten the parent's lifetime. |
使用示例
- 子执行:隔离记录,共享祖先额度:子 Runner 不继承对话和输出接收器,但不能绕过父级预算、取消和期限。
为子执行配置一次调用额度
入门 · 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);1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
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);1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
子报告返回后再由父级完成回答
配置 · 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);1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
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);1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12