ModelChildTask
SUPPORT · interface · Type contract
One child call in a group: its own limits plus the work to run with the child runner.
Import
import type { ModelChildTask } from '@jangts/agent-core/support';/** @typedef {import('@jangts/agent-core/support').ModelChildTask} ModelChildTask */Other public entry points:@jangts/agent-core/support, @jangts/agent-core/support/model.
Definition
interface ModelChildTask<Value>Extends or implements: ModelChildOptions.
Type parameters
| Type parameter | Constraint | Default type |
|---|---|---|
Value | — | — |
Field structure
| Field | Type | Required | Description |
|---|---|---|---|
run | (model: ModelRunner, signal: AbortSignal) => MaybePromise<Value> | Required | 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 | Required | Read-only. Child stage id, reported in traces and events. |
maxCalls | number | Required | Read-only. Calls the child may use from the shared request budget. |
reserveCalls | number | Required | Read-only. Calls kept for the parent; the child cannot spend them. |
timeoutMs | number | Required | Read-only. Deadline for the child's own calls, in milliseconds. |
transports | readonly ModelTransportDefinition<unknown>[] | undefined | Optional | Read-only. Additional transports visible to the child. |
diagnostics | DiagnosticContext | undefined | Optional | Read-only. See the type definition and usage context. |
signal | AbortSignal | undefined | Optional | Read-only. Extra cancellation; can only shorten the parent's lifetime. |
Member index
| Member | Purpose |
|---|---|
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. |
Member details
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.
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.
| Parameter | Type | Passing | Description |
|---|---|---|---|
model | ModelRunner<string, readonly ModelTransportDefinition<unknown>[]> | Required | — |
signal | AbortSignal | Required | — |
Returns: MaybePromise<Value>.
Awaited value: Awaited<Value>.
Examples
- Child task composition: sequential execution and controlled parallelism: Reuse createChild and the shared budget, check every result, and commit in declaration order.
Analyze two documents in sequence
Beginner · Node.js
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('分析结果为空'); },
});
}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('分析结果为空'); },
});
}Add concurrent capacity to the same set of analyses
Configuration · Node.js
The same function and task list, adding only the root Runner capacity setting. Local budgets and the parent reservation still apply.
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('分析结果为空'); },
});
}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('分析结果为空'); },
});
}