Skip to content

Commit

Permalink
fix bug in summary node that was resulting in duplicated messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jfrank-summit committed Feb 4, 2025
1 parent f5b1b3e commit c5669be
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/agents/workflows/orchestrator/nodes/summaryNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const createSummaryNode = ({ orchestratorModel, prompts }: OrchestratorCo
}

logger.info('Not summarizing, not enough messages');
return { messages: state.messages };
return { messages: [] };
};
return runNode;
};
18 changes: 3 additions & 15 deletions src/agents/workflows/orchestrator/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,18 @@ export type OrchestratorInput = {
export const OrchestratorState = Annotation.Root({
messages: Annotation<readonly BaseMessage[]>({
reducer: (curr, update) => {
let combined: BaseMessage[];
if (
//TODO: Revisit this process, this is quite messy. Maybe we should add state for summary messages?
Array.isArray(update) &&
update.length > 0 &&
update[0]?.content &&
typeof update[0].content === 'string' &&
update[0].content.startsWith('Summary of conversation earlier:')
) {
combined = [
curr[0],
update[0],
...curr.slice(config.orchestratorConfig.MAX_WINDOW_SUMMARY),
];
return [curr[0], update[0], ...curr.slice(config.orchestratorConfig.MAX_WINDOW_SUMMARY)];
} else {
combined = [...curr, ...update];
return [...curr, ...update];
}

const unique: BaseMessage[] = [];
for (const msg of combined) {
if (!unique.some(existing => JSON.stringify(existing) === JSON.stringify(msg))) {
unique.push(msg);
}
}
return unique;
},
default: () => [],
}),
Expand Down

0 comments on commit c5669be

Please sign in to comment.