ModelChildTask
SUPPORT · interface · 类型合同
One child call in a group: its own limits plus the work to run with the child runner.
导入
ts
import type { ModelChildTask } from '@jangts/agent-core/support';js
/** @typedef {import('@jangts/agent-core/support').ModelChildTask} ModelChildTask */其他公开入口:@jangts/agent-core/support、@jangts/agent-core/support/model。
定义
ts
interface ModelChildTask<Value>继承或实现: ModelChildOptions。
泛型参数
| 类型参数 | 约束 | 默认类型 |
|---|---|---|
Value | — | — |
字段结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
run | (model: ModelRunner, signal: AbortSignal) => MaybePromise<Value> | 必需 | Work executed with the child runner bound to this task's limits. The supplied signal also aborts when a sibling fails, so long work should observe it. |
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. |
成员目录
| 成员 | 用途 |
|---|---|
run | Work executed with the child runner bound to this task's limits. The supplied signal also aborts when a sibling fails, so long work should observe it. |
成员详情
run
Work executed with the child runner bound to this task's limits.
The supplied signal also aborts when a sibling fails, so long work should observe it.
ts
ModelChildTask.run(model: ModelRunner, signal: AbortSignal): MaybePromise<Value>Work executed with the child runner bound to this task's limits.
The supplied signal also aborts when a sibling fails, so long work should observe it.
| 参数 | 类型 | 传递 | 说明 |
|---|---|---|---|
model | ModelRunner<string, readonly ModelTransportDefinition<unknown>[]> | 必需 | — |
signal | AbortSignal | 必需 | — |
返回: MaybePromise<Value>。
等待后的值: Awaited<Value>。
使用示例
- 子任务组合:顺序执行与受控并行:复用 createChild 和共享预算,检查全部结果后按声明顺序提交。
顺序分析两段资料
入门 · Node.js
ts
import { ModelRunner, Support } from '@jangts/agent-core';
import type { ChatProvider } from '@jangts/agent-core';
export async function analyze(provider: ChatProvider, inputs: readonly [string, string], signal: AbortSignal) {
const model = new ModelRunner({ provider, maxCalls: 5, execution: { signal } });
return Support.runChildren(model, inputs.map((input, index) => ({
id: 'analysis-' + index, maxCalls: 2, reserveCalls: 1, timeoutMs: 30000, transports: [],
async run(child: ModelRunner) { return (await child.invoke(input)).value; },
})), {
accept(value) { if (!value.trim()) throw new Error('分析结果为空'); },
});
}js
import { ModelRunner, Support } from '@jangts/agent-core';
export async function analyze(provider, inputs, signal) {
const model = new ModelRunner({ provider, maxCalls: 5, execution: { signal } });
return Support.runChildren(model, inputs.map((input, index) => ({
id: 'analysis-' + index, maxCalls: 2, reserveCalls: 1, timeoutMs: 30000, transports: [],
async run(child) { return (await child.invoke(input)).value; },
})), {
accept(value) { if (!value.trim())
throw new Error('分析结果为空'); },
});
}同一组分析增加并发容量
配置 · Node.js
同一个函数与任务清单,只增加根 Runner 的容量配置。局部预算和父级预留仍生效。
ts
import { ModelRunner, Support } from '@jangts/agent-core';
import type { ChatProvider } from '@jangts/agent-core';
export async function analyze(provider: ChatProvider, inputs: readonly [string, string], signal: AbortSignal) {
const model = new ModelRunner({ provider, maxCalls: 5, execution: { signal }, children: { maxConcurrentCalls: 2 } });
return Support.runChildren(model, inputs.map((input, index) => ({
id: 'analysis-' + index, maxCalls: 2, reserveCalls: 1, timeoutMs: 30000, transports: [],
async run(child: ModelRunner) { return (await child.invoke(input)).value; },
})), {
accept(value) { if (!value.trim()) throw new Error('分析结果为空'); },
});
}js
import { ModelRunner, Support } from '@jangts/agent-core';
export async function analyze(provider, inputs, signal) {
const model = new ModelRunner({ provider, maxCalls: 5, execution: { signal }, children: { maxConcurrentCalls: 2 } });
return Support.runChildren(model, inputs.map((input, index) => ({
id: 'analysis-' + index, maxCalls: 2, reserveCalls: 1, timeoutMs: 30000, transports: [],
async run(child) { return (await child.invoke(input)).value; },
})), {
accept(value) { if (!value.trim())
throw new Error('分析结果为空'); },
});
}