retryMultipleModelCalls
CORE · function · 运行时值
Retry once when the failure is a rejected multi-call proposal.
Only the MODEL_MULTIPLE_CALLS code is retried; every other failure is rethrown unchanged. The caller owns the fallback prompt and the budget it consumes.
导入
ts
import { retryMultipleModelCalls } from '@jangts/agent-core/support';js
import { retryMultipleModelCalls } from '@jangts/agent-core/support';其他公开入口:@jangts/agent-core/support。
定义
泛型参数
| 类型参数 | 约束 | 默认类型 |
|---|---|---|
Value | — | — |
调用
ts
retryMultipleModelCalls<Value>(request: { readonly logger?: import("../structs/debug.js").SubFlowLogger; readonly signal?: AbortSignal; readonly invoke: () => Promise<Value>; readonly retry: (error: unknown) => Promise<Value>; }): Promise<Value>Retry once when the failure is a rejected multi-call proposal.
Only the MODEL_MULTIPLE_CALLS code is retried; every other failure is rethrown unchanged. The caller owns the fallback prompt and the budget it consumes.
| 类型参数 | 约束 | 默认类型 |
|---|---|---|
Value | — | — |
| 参数 | 类型 | 传递 | 说明 |
|---|---|---|---|
request | { readonly logger?: import("../structs/debug.js").SubFlowLogger; readonly signal?: AbortSignal; readonly invoke: () => Promise<Value>; readonly retry: (error: unknown) => Promise<Value>; } | 必需 | — |
request 的字段
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
logger | SubFlowLogger | undefined | 可省略 | 只读。见类型定义及调用场景。 |
signal | AbortSignal | undefined | 可省略 | 只读。见类型定义及调用场景。 |
invoke | () => Promise<Value> | 必需 | 只读。见类型定义及调用场景。 |
retry | (error: unknown) => Promise<Value> | 必需 | 只读。见类型定义及调用场景。 |
返回: Promise<Value>。
等待后的值: Awaited<Value>。
使用示例
- 仅在特定模型协议失败时显式回退:处理不支持的并行提议,不接管 App 的全部重试和业务错误。
正常调用保持同一返回合同
入门 · 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);业务拒绝不会被当成自动重试条件
配置 · 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);
}