From 8c46108a852128d1d0792c149746631d83fc58cf Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Fri, 30 May 2025 10:57:00 -0700 Subject: feat: Implement retry with backoff for API calls (#613) --- packages/server/src/tools/web-fetch.ts | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'packages/server/src/tools/web-fetch.ts') diff --git a/packages/server/src/tools/web-fetch.ts b/packages/server/src/tools/web-fetch.ts index 7a8a1515..24617902 100644 --- a/packages/server/src/tools/web-fetch.ts +++ b/packages/server/src/tools/web-fetch.ts @@ -10,6 +10,7 @@ import { BaseTool, ToolResult } from './tools.js'; import { getErrorMessage } from '../utils/errors.js'; import { Config } from '../config/config.js'; import { getResponseText } from '../utils/generateContentResponseUtilities.js'; +import { retryWithBackoff } from '../utils/retry.js'; // Interfaces for grounding metadata (similar to web-search.ts) interface GroundingChunkWeb { @@ -121,18 +122,21 @@ export class WebFetchTool extends BaseTool { const userPrompt = params.prompt; try { - const response = await this.ai.models.generateContent({ - model: this.modelName, - contents: [ - { - role: 'user', - parts: [{ text: userPrompt }], + const apiCall = () => + this.ai.models.generateContent({ + model: this.modelName, + contents: [ + { + role: 'user', + parts: [{ text: userPrompt }], + }, + ], + config: { + tools: [{ urlContext: {} }], }, - ], - config: { - tools: [{ urlContext: {} }], - }, - }); + }); + + const response = await retryWithBackoff(apiCall); console.debug( `[WebFetchTool] Full response for prompt "${userPrompt.substring(0, 50)}...":`, -- cgit v1.2.3