Skip to content
中文

Explicit fallback only when a specific model protocol fails ​

Handle unsupported parallel proposals without taking over all of the App's retries and business errors.

retryMultipleModelCalls catches only errors with the MODEL_MULTIPLE_CALLS code and calls the explicit retry(error); other failures propagate unchanged. The fallback happens before any tool execution and must not repeat proposals that already produced side effects.

Both calls must use the same request budget and cancellation. This helper does not reset quotas or automatically switch protocols based on model names; the input, transport, and business acceptance of the fallback call are still defined by the App.

Progressive examples for the same business case ​

A normal call keeps the same return contract ​

Beginner · Node.js

ts
import { ModelRunner, Support } from '@jangts/agent-core';
const runner = new ModelRunner({ provider: { async *stream() { yield '服务正常'; } }, maxCalls: 2 });
const result = await Support.retryMultipleModelCalls({
  invoke: () => runner.invoke('查询服务状态'),
  retry: () => runner.invoke('只选择一个服务状态结论'),
});
console.log(result.value);
js
import { ModelRunner, Support } from '@jangts/agent-core';
const runner = new ModelRunner({ provider: { async *stream() { yield '服务正常'; } }, maxCalls: 2 });
const result = await Support.retryMultipleModelCalls({
    invoke: () => runner.invoke('查询服务状态'),
    retry: () => runner.invoke('只选择一个服务状态结论'),
});
console.log(result.value);

Business rejections are not treated as automatic retry conditions ​

Configuration · Node.js

ts
import { Support } from '@jangts/agent-core';
try {
  await Support.retryMultipleModelCalls({
    invoke: async () => { throw new Error('当前请求没有权限'); },
    retry: async () => '此回退不会被执行',
  });
} catch (error) { console.log((error as Error).message); }
js
import { Support } from '@jangts/agent-core';
try {
    await Support.retryMultipleModelCalls({
        invoke: async () => { throw new Error('当前请求没有权限'); },
        retry: async () => '此回退不会被执行',
    });
}
catch (error) {
    console.log(error.message);
}

Policies & implementations ​

API reference, usage examples and developer guides.