From c226215e9d10e78176c4874164fa80a360784414 Mon Sep 17 00:00:00 2001 From: xm0onh Date: Fri, 31 Jan 2025 14:33:32 -0800 Subject: [PATCH] fix parsing string error - update prompt for summary and pruning --- .../workflows/orchestrator/nodes/summaryNode.ts | 7 ++++++- src/agents/workflows/orchestrator/prompts.ts | 8 +------- src/agents/workflows/orchestrator/types.ts | 12 +++++++----- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/agents/workflows/orchestrator/nodes/summaryNode.ts b/src/agents/workflows/orchestrator/nodes/summaryNode.ts index 80c4f98..5084598 100644 --- a/src/agents/workflows/orchestrator/nodes/summaryNode.ts +++ b/src/agents/workflows/orchestrator/nodes/summaryNode.ts @@ -33,9 +33,14 @@ export const createSummaryNode = ({ orchestratorModel, prompts }: OrchestratorCo const newSummary = await orchestratorModel.invoke(formattedPrompt); logger.info('New Summary Result:', { newSummary }); + const summaryContent = + typeof newSummary.content === 'string' + ? newSummary.content + : JSON.stringify(newSummary.content, null, 2); + return { messages: [ - new AIMessage({ content: `Summary of conversation earlier: ${newSummary.content}` }), + new AIMessage({ content: `Summary of conversation earlier: ${summaryContent}` }), ], }; } diff --git a/src/agents/workflows/orchestrator/prompts.ts b/src/agents/workflows/orchestrator/prompts.ts index 6f66205..2d44d12 100644 --- a/src/agents/workflows/orchestrator/prompts.ts +++ b/src/agents/workflows/orchestrator/prompts.ts @@ -77,13 +77,7 @@ export const createPrompts = async () => { ` You are a helpful assistant that make the AI-to-AI conversations efficient. Prune the data that you find unnecessary. The result doesn't have to be concise, but it should be functional. - Some of the examples of unnecessary data: - - Messages that don't contribute to the main workflow - - Messages that are duplicates - - Messages that are not relevant to the main workflow - - Messages that are not important to the main workflow - - Messages that are not important to the main workflow - - Messages that are not important to the main workflow + You want to have a detailed version of the conversation with ALL IMPORTANT DATA (e.g. decisions, tweet text, tweet ids, tool calls, tool results, etc.) THE RESULT SHOULD BE EQUAL TO ORIGINAL IN TERMS OF FUNCTIONALITY diff --git a/src/agents/workflows/orchestrator/types.ts b/src/agents/workflows/orchestrator/types.ts index c0ba824..8e814c0 100644 --- a/src/agents/workflows/orchestrator/types.ts +++ b/src/agents/workflows/orchestrator/types.ts @@ -23,11 +23,13 @@ export type OrchestratorInput = { export const OrchestratorState = Annotation.Root({ messages: Annotation({ reducer: (curr, update) => { - if ( - update.length === 1 && - update[0].content.toString().startsWith('Summary of conversation earlier:') - ) { - return [curr[0], update[0], ...curr.slice(config.orchestratorConfig.MAX_WINDOW_SUMMARY)]; + if (Array.isArray(update) && update.length > 0 && update[0]?.content) { + if ( + typeof update[0].content === 'string' && + update[0].content.startsWith('Summary of conversation earlier:') + ) { + return [curr[0], update[0], ...curr.slice(config.orchestratorConfig.MAX_WINDOW_SUMMARY)]; + } } return [...curr, ...update]; },