Centralized context management for Sammy Agent conversations with automatic memory searches and pull-based retrieval
The Context Management System uses a “pull” strategy where the AI model naturally requests context through tool calls rather than having context pushed to it. This ensures seamless integration with the Gemini Live API.
Fixed getContext tool registration and added automatic system prompt augmentation for context tool usage. The AI now proactively calls the tool when needing user information, page context, or memories.
The SystemPromptAugmentor is a singleton that manages all system prompt modifications, ensuring the AI knows about available tools and context.
Copy
const augmentor = SystemPromptAugmentor.getInstance();// Set language for the sessionaugmentor.setLanguage('es-ES');// Add custom augmentationaugmentor.addAugmentation({ id: 'custom-rules', content: '## Custom Rules\n\nAlways be polite and professional.', priority: 40, enabled: true,});// Apply augmentations to base promptconst finalPrompt = augmentor.augmentPrompt(basePrompt);
Handles automatic memory searches based on transcriptions:
Copy
const memoryManager = new ContextMemoryManager( memoryService, contextStateManager, { userInputThreshold: 20, // Min chars for user input agentOutputThreshold: 50, // Min chars for agent output searchLimit: 3, // Max memories to return similarityThreshold: 0.2 // Min relevance score });
Context management is automatically initialized when creating a new agent. No manual setup required!
Copy
const agent = new SammyAgentCore({ // ... other options});// Context management is initialized automatically// ✅ Transcriptions trigger memory searches// ✅ GetContext tool is registered// ✅ System prompt includes context instructions
## Context Retrieval ToolIMPORTANT: When the user asks questions about themselves, their preferences, or their context, you MUST use the getContext tool to retrieve this information. The getContext tool provides:- User information (name, preferences, settings)- Current page context (URL, title, domain)- Relevant memories from past interactions- Custom contextual informationCall getContext with queries like:- "user information" - for user details- "current page" - for page context- "everything" - for all available context- "memories about [topic]" - for specific memoriesAlways use this tool when you need contextual information to provide personalized assistance.
When a non-English language is configured, appropriate instructions are added in the target language. For example, for Spanish:
Copy
## Language SettingsEl idioma elegido por el usuario es español (España). DEBES hablar SOLO en español.
Copy
## Memory ManagementWhen handling conversations:1. Pay attention to context provided through the getContext tool2. Use retrieved memories to maintain conversation continuity3. Reference past interactions when relevant4. Personalize responses based on user preferences and history
Copy
## Tool Usage GuidelinesWhen using tools:1. Always check if a tool can help answer the user's question2. Use tools proactively rather than asking users for information3. Combine multiple tools when needed for comprehensive responses4. Explain what you're doing when using tools that affect the user's system
The system formats context with clear sections for easy AI parsing:
Copy
[CONTEXT RETRIEVED]📍 Current Page: URL: https://example.com/dashboard Title: User Dashboard Timestamp: 2024-01-15T10:30:00Z👤 User Information: Name: Joseph Marinio Preferences: {"theme":"dark"}💭 Relevant Knowledge: 1. User prefers dark theme (0.95) 2. User is an admin (0.87) 3. Last login was yesterday (0.72)🔧 Additional Context: currentTask: "reviewing invoices"Use this context to provide personalized and accurate assistance.
🎯 [CONTEXT-STATE-MANAGER] initialized📚 [CONTEXT-STATE-MANAGER] Updating memories: 3 entries🌐 [CONTEXT-STATE-MANAGER] Updating page metadata🔍 [GET-CONTEXT-TOOL] Called with query: user information💭 [CONTEXT-MEMORY-MANAGER] Searching memories for user: What is my name...🔧 [SAMMY-AGENT-CORE] Registered getContext tool✅ [SAMMY-AGENT-CORE] getContext tool is present in declarations