Child execution: isolated records, shared ancestor quota
A child Runner does not inherit conversation or the output receiver, but cannot bypass parent budget, cancellation, or deadlines.
children configures the maxDepth, maxConcurrentCalls, and maxChildren shared across the request, defaulting to a single level and serial execution. Calls on the same Runner cannot overlap; model calls from multiple child Runners share the root capacity. transports explicitly specifies the set available to child execution and does not automatically inherit all model-visible tools of the parent.
maxCalls is the local limit for child execution, and reserveCalls keeps follow-up wrap-up quota for the parent; the call is rejected when no quota is available. The parent totalCallCount includes descendant consumption, while the parent callCount, journal, and children are isolated from each other. Child execution belongs to the lifecycle of the parent request, and business authorization is supplied by the App.
Progressive examples for the same business case
Configure a call quota for child execution
Beginner · Node.js
import { ModelRunner } from '@jangts/agent-core/model';
const provider = {
async *stream(messages: readonly { content: string }[]) {
yield '收到:' + messages.at(-1)!.content;
},
};
const parent = new ModelRunner({ provider, maxCalls: 3 });
const child = parent.createChild({ id: 'service-review', maxCalls: 1, reserveCalls: 1,
timeoutMs: 10000, transports: [] });
const report = await child.invoke('独立核对服务状态');
console.log(report.value, parent.totalCallCount, child.callCount);import { ModelRunner } from '@jangts/agent-core/model';
const provider = {
async *stream(messages) {
yield '收到:' + messages.at(-1).content;
},
};
const parent = new ModelRunner({ provider, maxCalls: 3 });
const child = parent.createChild({ id: 'service-review', maxCalls: 1, reserveCalls: 1,
timeoutMs: 10000, transports: [] });
const report = await child.invoke('独立核对服务状态');
console.log(report.value, parent.totalCallCount, child.callCount);Let the parent finish the answer after the child report returns
Configuration · Node.js
The parent model is called only after the child task completes; there is no Promise.all. The parent still owns verifying the report source and business completeness.
import { ModelRunner } from '@jangts/agent-core/model';
const provider = {
async *stream(messages: readonly { content: string }[]) {
yield '收到:' + messages.at(-1)!.content;
},
};
const parent = new ModelRunner({ provider, maxCalls: 3 });
const child = parent.createChild({ id: 'service-review', maxCalls: 1, reserveCalls: 1,
timeoutMs: 10000, transports: [] });
const report = await child.invoke('核对状态证据');
const answer = await parent.invoke('根据已核对报告回答:' + report.value);
console.log(answer.value);import { ModelRunner } from '@jangts/agent-core/model';
const provider = {
async *stream(messages) {
yield '收到:' + messages.at(-1).content;
},
};
const parent = new ModelRunner({ provider, maxCalls: 3 });
const child = parent.createChild({ id: 'service-review', maxCalls: 1, reserveCalls: 1,
timeoutMs: 10000, transports: [] });
const report = await child.invoke('核对状态证据');
const answer = await parent.invoke('根据已核对报告回答:' + report.value);
console.log(answer.value);