Skip to content

Commit

Permalink
fix parsing string error - update prompt for summary and pruning
Browse files Browse the repository at this point in the history
  • Loading branch information
Xm0onh committed Jan 31, 2025
1 parent 45faf0e commit c226215
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
7 changes: 6 additions & 1 deletion src/agents/workflows/orchestrator/nodes/summaryNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}` }),
],
};
}
Expand Down
8 changes: 1 addition & 7 deletions src/agents/workflows/orchestrator/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions src/agents/workflows/orchestrator/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ export type OrchestratorInput = {
export const OrchestratorState = Annotation.Root({
messages: Annotation<readonly BaseMessage[]>({
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];
},
Expand Down

0 comments on commit c226215

Please sign in to comment.