Skip to content

Commit

Permalink
add cap for queue of messages - update prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
Xm0onh committed Jan 31, 2025
1 parent 8c3fabb commit 45faf0e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
1 change: 1 addition & 0 deletions characters/character.example/config/config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ memory:

orchestrator:
MAX_WINDOW_SUMMARY: 20
MAX_QUEUE_SIZE: 50
7 changes: 5 additions & 2 deletions src/agents/workflows/orchestrator/nodes/summaryNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ export const createSummaryNode = ({ orchestratorModel, prompts }: OrchestratorCo
logger.info('Summary Node');
logger.info('State size:', { size: state.messages.length });

if (state.messages.length > config.orchestratorConfig.MAX_WINDOW_SUMMARY) {
if (state.messages.length > config.orchestratorConfig.MAX_QUEUE_SIZE) {
const prevSummary = state.messages[1]?.content || 'No previous summary';
const messagesToSummarize = state.messages.slice(1);
const messagesToSummarize = state.messages.slice(
1,
config.orchestratorConfig.MAX_WINDOW_SUMMARY,
);

const newMessages = messagesToSummarize
.map(msg => {
Expand Down
22 changes: 11 additions & 11 deletions src/agents/workflows/orchestrator/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,17 @@ export const createPrompts = async () => {

const summarySystemPrompt = await PromptTemplate.fromTemplate(
`
You are a helpful assistant that summarizes AI-to-AI conversations.
Maintain the key points and context while being concise.
Focus on:
- Main tasks and workflows executed
- Key decisions made by AI agents
- Important data exchanged between AI systems (e.g. tool calls, tool results, etc.)
- PAY ATTENTION TO IMPORTANT DETAILS
- MAKE SURE YOU INCLUDE ALL THE TOOL CALLS AND TOOL RESULTS IN THE SUMMARY
- IF it is twitter related messages, INCLUDE TWEET TEXT AND IDS IN THE SUMMARY
THE SUMMARY SHOULD BE EQUAL TO ORIGINAL IN TERMS OF FUNCTIONALITY
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
THE RESULT SHOULD BE EQUAL TO ORIGINAL IN TERMS OF FUNCTIONALITY
Format the summary in a clear, bulleted structure.`,
).format({});
Expand Down
3 changes: 2 additions & 1 deletion src/agents/workflows/orchestrator/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { BaseLanguageModelInput } from '@langchain/core/language_models/base';
import { AIMessageChunk } from '@langchain/core/messages';
import { ToolNode } from '@langchain/langgraph/prebuilt';
import { ChatPromptTemplate } from '@langchain/core/prompts';
import { config } from '../../../config/index.js';

export type OrchestratorConfig = {
orchestratorModel: Runnable<BaseLanguageModelInput, AIMessageChunk>;
Expand All @@ -26,7 +27,7 @@ export const OrchestratorState = Annotation.Root({
update.length === 1 &&
update[0].content.toString().startsWith('Summary of conversation earlier:')
) {
return [curr[0], ...update];
return [curr[0], update[0], ...curr.slice(config.orchestratorConfig.MAX_WINDOW_SUMMARY)];
}
return [...curr, ...update];
},
Expand Down
3 changes: 2 additions & 1 deletion src/config/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ const memoryConfigSchema = z.object({
});

const orchestratorConfigSchema = z.object({
MAX_WINDOW_SUMMARY: z.number().int().positive().default(3),
MAX_WINDOW_SUMMARY: z.number().int().positive().default(20),
MAX_QUEUE_SIZE: z.number().int().positive().default(50),
});

const SERPAPI_API_KEY = z.string().optional();
Expand Down

0 comments on commit 45faf0e

Please sign in to comment.