diff --git a/src/agent.ts b/src/agent.ts index 86b03f6..f68f6d8 100644 --- a/src/agent.ts +++ b/src/agent.ts @@ -13,7 +13,7 @@ import { SEARCH_PROVIDER, STEP_SLEEP, modelConfigs, - DEFAULT_BUDGET_SPLIT_RATIO + DEFAULT_BUDGET_SPLIT_RATIO, MAX_RECURSION_DEPTH } from "./config"; import {TokenTracker} from "./utils/token-tracker"; import {ActionTracker} from "./utils/action-tracker"; @@ -291,6 +291,7 @@ export async function getResponse(question: string, tokenBudget: number = 1_000_ console.log(`| Recursion ${recursionLevel} | Step ${totalStep} | Token Budget ${tokenBudget} | Budget Used: ${budgetPercentage}% | Q: ${currentQuestion} |`); // update all urls with buildURLMap + allowReflect = allowReflect && (recursionLevel < MAX_RECURSION_DEPTH); allowRead = allowRead && (Object.keys(allURLs).length > 0); allowSearch = allowSearch && (Object.keys(allURLs).length < 20); // disable search when too many urls already diff --git a/src/config.ts b/src/config.ts index 56e558d..e71909d 100644 --- a/src/config.ts +++ b/src/config.ts @@ -68,7 +68,7 @@ export const modelConfigs: ToolConfigs = { export const STEP_SLEEP = 1000; export const DEFAULT_BUDGET_SPLIT_RATIO = 0.3; // Each sub-question gets 30% of parent's budget - +export const MAX_RECURSION_DEPTH = 3; if (!GEMINI_API_KEY) throw new Error("GEMINI_API_KEY not found"); if (!JINA_API_KEY) throw new Error("JINA_API_KEY not found");