Skip to content
English

ModelChildrenOptions ​

SUPPORT · interface · 类型合同

Group options: worker count, extra cancellation and accept/commit hooks.

导入 ​

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

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

定义 ​

ts
interface ModelChildrenOptions<Value>

泛型参数 ​

类型参数约束默认类型
Value——

字段结构 ​

字段类型必需说明
concurrencynumber | undefined可省略只读。Parallel workers; defaults to, and may not exceed, the parent's concurrency limit.
signalAbortSignal | undefined可省略只读。Optional caller cancellation, combined with the parent signal and group failure.
accept((value: Value, id: string) => MaybePromise<void>) | undefined可省略Called as each task finishes, before commit; must settle with void.
commit((value: Value, id: string) => MaybePromise<void>) | undefined可省略Called in declaration order after every result is accepted; App owns atomicity/receipts.

使用示例 ​

顺序分析两段资料 ​

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

相关策略源码 ​

相关定义 ​

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