Skip to content
English

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.
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.

成员目录 ​

成员用途
runWork 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.

参数类型传递说明
modelModelRunner<string, readonly ModelTransportDefinition<unknown>[]>必需—
signalAbortSignal必需—

返回: MaybePromise<Value>。

等待后的值: Awaited<Value>。

使用示例 ​

顺序分析两段资料 ​

入门 · 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('分析结果为空'); },
    });
}

相关策略源码 ​

相关定义 ​

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