mirror of
https://github.com/jina-ai/node-DeepResearch.git
synced 2026-03-22 07:29:35 +08:00
fix: refine subproblem handling and aggregation logic in agent
This commit is contained in:
66
src/agent.ts
66
src/agent.ts
@@ -796,39 +796,45 @@ But then you realized you have asked them before. You decided to to think out of
|
|||||||
|
|
||||||
if (teamSize > 1) {
|
if (teamSize > 1) {
|
||||||
const subproblems = await researchPlan(question, teamSize, soundBites, context, SchemaGen);
|
const subproblems = await researchPlan(question, teamSize, soundBites, context, SchemaGen);
|
||||||
// parallel call getResponse for each subproblem with exact same parameters from the current step, but their teamSize is 1
|
if (subproblems.length > 1) {
|
||||||
const subproblemResponses = await Promise.all(subproblems.map(subproblem => getResponse(subproblem,
|
|
||||||
tokenBudget,
|
|
||||||
maxBadAttempts,
|
|
||||||
context,
|
|
||||||
messages,
|
|
||||||
numReturnedURLs,
|
|
||||||
noDirectAnswer,
|
|
||||||
boostHostnames,
|
|
||||||
badHostnames,
|
|
||||||
onlyHostnames,
|
|
||||||
maxRef,
|
|
||||||
minRelScore, languageCode, searchLanguageCode, searchProvider, withImages, 1)));
|
|
||||||
// convert current step to AnswerAction
|
|
||||||
thisStep = {
|
|
||||||
action: 'answer',
|
|
||||||
think: thisStep.think,
|
|
||||||
answer: subproblemResponses.map(r => (r.result as AnswerAction).answer).join('\n\n'),
|
|
||||||
mdAnswer: subproblemResponses.map(r => (r.result as AnswerAction).mdAnswer).join('\n\n'),
|
|
||||||
references: subproblemResponses.map(r => (r.result as AnswerAction).references).flat(),
|
|
||||||
isFinal: true,
|
|
||||||
isAggregated: true
|
|
||||||
} as AnswerAction;
|
|
||||||
candidateAnswers = subproblemResponses.map(r => (r.result as AnswerAction).mdAnswer).filter(a => a) as string[];
|
|
||||||
|
|
||||||
// aggregate urls
|
// parallel call getResponse for each subproblem with exact same parameters from the current step, but their teamSize is 1
|
||||||
visitedURLs.push(...subproblemResponses.map(r => r.readURLs).flat());
|
const subproblemResponses = await Promise.all(subproblems.map(subproblem => getResponse(subproblem,
|
||||||
weightedURLs = subproblemResponses.map(r => r.allURLs.map(url => ({ url, title: '' } as BoostedSearchSnippet))).flat();
|
tokenBudget,
|
||||||
|
maxBadAttempts,
|
||||||
|
context,
|
||||||
|
messages,
|
||||||
|
numReturnedURLs,
|
||||||
|
noDirectAnswer,
|
||||||
|
boostHostnames,
|
||||||
|
badHostnames,
|
||||||
|
onlyHostnames,
|
||||||
|
maxRef,
|
||||||
|
minRelScore, languageCode, searchLanguageCode, searchProvider, withImages, 1)));
|
||||||
|
// convert current step to AnswerAction
|
||||||
|
thisStep = {
|
||||||
|
action: 'answer',
|
||||||
|
think: thisStep.think,
|
||||||
|
answer: subproblemResponses.map(r => (r.result as AnswerAction).answer).join('\n\n'),
|
||||||
|
mdAnswer: subproblemResponses.map(r => (r.result as AnswerAction).mdAnswer).join('\n\n'),
|
||||||
|
references: subproblemResponses.map(r => (r.result as AnswerAction).references).flat(),
|
||||||
|
isFinal: true,
|
||||||
|
isAggregated: true
|
||||||
|
} as AnswerAction;
|
||||||
|
candidateAnswers = subproblemResponses.map(r => (r.result as AnswerAction).mdAnswer).filter(a => a) as string[];
|
||||||
|
|
||||||
// TODO aggregate images @shazhou2015
|
// aggregate urls
|
||||||
|
visitedURLs.push(...subproblemResponses.map(r => r.readURLs).flat());
|
||||||
|
weightedURLs = subproblemResponses.map(r => r.allURLs.map(url => ({ url, title: '' } as BoostedSearchSnippet))).flat();
|
||||||
|
|
||||||
// break the loop, jump directly final boxing
|
// TODO aggregate images @shazhou2015
|
||||||
break;
|
|
||||||
|
// break the loop, jump directly final boxing
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
// if there is only one subproblem, then we skip the recurrsion
|
||||||
|
gaps.push(subproblems[0]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// rewrite queries with initial soundbites
|
// rewrite queries with initial soundbites
|
||||||
|
|||||||
Reference in New Issue
Block a user