const fetchWeather = async (params: { city: string }) => {
const res = await fetch(`https://api.weather.com/${params.city}`);
return res.json();
};
const result = await skills.toolCallRetry({
toolFn: fetchWeather,
args: { city: "Beijing" }
});
const result = await skills.toolCallRetry({
toolFn: callLLM,
args: { prompt: "Generate JSON output" },
validatorFn: (res) => typeof res === "object" && res !== null && res.code === 0,
maxRetries: 5
});
const result = await skills.toolCallRetry({
toolFn: callDatabase,
args: { sql: "SELECT * FROM users" },
errorHandlerFn: async (error, attempt) => {
if (error.message.includes("SQL syntax error")) {
// 自动修复SQL语法
const fixedSql = await fixSqlWithLLM(error.message);
return { args: { sql: fixedSql } };
}
if (attempt >= 2) {
// 重试2次失败后中止
return { abort: true };
}
}
});