ModelChildPolicy
CORE · interface · Type contract
Request-wide limits, shared by every descendant. They cannot be enlarged by a child.
Import
ts
import type { ModelChildPolicy } from '@jangts/agent-core/model';js
/** @typedef {import('@jangts/agent-core/model').ModelChildPolicy} ModelChildPolicy */Other public entry points:@jangts/agent-core, @jangts/agent-core/model, @jangts/agent-core/types, @jangts/agent-core/structs.
Definition
ts
interface ModelChildPolicyField structure
| Field | Type | Required | Description |
|---|---|---|---|
maxDepth | number | undefined | Optional | Read-only. Maximum nesting depth of child runners; 0 forbids children. |
maxConcurrentCalls | number | undefined | Optional | Read-only. Maximum calls running at the same time across the request. |
maxChildren | number | undefined | Optional | Read-only. Maximum child runners created across the request. |
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
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('分析结果为空'); },
});
}