Skip to content
中文

ModelChildTask ​

SUPPORT · interface · Type contract

One child call in a group: its own limits plus the work to run with the child runner.

Import ​

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

Other public entry points:@jangts/agent-core/support, @jangts/agent-core/support/model.

Definition ​

ts
interface ModelChildTask<Value>

Extends or implements: ModelChildOptions.

Type parameters ​

Type parameterConstraintDefault type
Value——

Field structure ​

FieldTypeRequiredDescription
run(model: ModelRunner, signal: AbortSignal) => MaybePromise<Value>RequiredWork 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.
idstringRequiredRead-only. Child stage id, reported in traces and events.
maxCallsnumberRequiredRead-only. Calls the child may use from the shared request budget.
reserveCallsnumberRequiredRead-only. Calls kept for the parent; the child cannot spend them.
timeoutMsnumberRequiredRead-only. Deadline for the child's own calls, in milliseconds.
transportsreadonly ModelTransportDefinition<unknown>[] | undefinedOptionalRead-only. Additional transports visible to the child.
diagnosticsDiagnosticContext | undefinedOptionalRead-only. See the type definition and usage context.
signalAbortSignal | undefinedOptionalRead-only. Extra cancellation; can only shorten the parent's lifetime.

Member index ​

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

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.

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.

ParameterTypePassingDescription
modelModelRunner<string, readonly ModelTransportDefinition<unknown>[]>Required—
signalAbortSignalRequired—

Returns: MaybePromise<Value>.

Awaited value: Awaited<Value>.

Examples ​

Analyze two documents in sequence ​

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

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.

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

API reference, usage examples and developer guides.