Skip to content

Conversation

@keshav1sharma
Copy link

@keshav1sharma keshav1sharma commented Aug 22, 2025

🧠 Implement Memory System for BrowserOS Agent

Overview

This PR implements a comprehensive memory system that enables the BrowserOS agent to maintain context across browser sessions, learn from user interactions, and provide personalized experiences. The memory system uses Mem0 for cloud-based persistent storage and integrates seamlessly with the existing tool architecture.

🎯 What This Adds

  • Persistent Memory: Agent remembers important information across sessions
  • Task Continuity: Complex workflows can be resumed and continued
  • User Personalization: Learns and remembers user preferences
  • Pattern Learning: Stores successful interaction patterns for reuse
  • Context Sharing: Share information between tabs and browsing sessions

🔧 Technical Implementation

Core Components Added

  • MemoryManager: Central memory management with Mem0 integration
  • Memory Tools: Two new tools for storing and retrieving information
    • memory_tool: Core memory operations (add, search, get_context, store_result, get_preferences)
  • Memory Categories: Structured categorization system for different types of information
  • Event System: Memory event bus for real-time updates

Architecture Changes

src/lib/
├── memory/                    # Core memory system
│   ├── MemoryManager.ts      # Main memory orchestrator
│   ├── Mem0ClientWrapper.ts  # Cloud storage integration
│   ├── MemoryEventBus.ts     # Event system
│   └── types.ts              # Memory schemas and types
└── tools/memory/             # Memory tools implementation
    ├── MemoryTool.ts         # Core memory operations tool
    └── MemoryTool.prompt.ts  # Tool-specific prompts

Tool Integration

  • Memory tools follow the same pattern as existing tools
  • Integrated into BrowserAgent tool registry
  • Tool descriptions include comprehensive usage prompts
  • Self-contained prompts within tool descriptions (no global prompt pollution)

🎬 Demo Video

Screen.Recording.2025-08-22.at.6.25.00.PM.mp4

🚀 Key Features

Memory Categories

  • search_result - Information found through searches
  • user_preference - User's stated preferences and requirements
  • task_result - Intermediate results from task steps
  • interaction_pattern - Successful UI interaction sequences
  • workflow_pattern - Successful task completion patterns
  • error_solution - Solutions to encountered problems
  • research_data - Collected research information
  • context_data - General contextual information

Automatic Memory Triggers

The agent automatically uses memory when users say:

  • "save this", "remember that", "store this information"
  • "what did I search for before?", "my usual preferences"
  • "continue where I left off", "like last time"
  • Any reference to past interactions or personalization

Example Usage

// Store user preferences
memory_tool({ 
  action: "add", 
  content: "User prefers window seats, budget under $500", 
  category: "user_preference", 
  importance: 0.9 
})

// Search for relevant context
memory_tool({ 
  action: "search", 
  query: "flight booking preferences", 
  limit: 5 
})

// Store task results for continuation
memory_tool({ 
  action: "store_result", 
  content: "Found 3 flight options: AA $299, Delta $349, United $399" 
})

🔄 Changes Made

Files Added

  • src/lib/memory/ - Complete memory system implementation
  • src/lib/tools/memory/ - Memory tools and prompts

Files Modified

  • src/lib/agent/BrowserAgent.ts - Added memory tool registration
  • src/lib/tools/index.ts - Export memory tools
  • src/lib/runtime/ExecutionContext.ts - Memory manager integration
  • package.json - Added mem0ai and uuid dependencies

Environment Variables

  • MEM0_API_KEY - Required for cloud memory storage (optional, graceful fallback if not provided)

🧪 Testing

  • ✅ Build system updated and compiling successfully
  • ✅ Memory tools properly registered and exported
  • ✅ Tool descriptions include comprehensive prompts
  • ✅ Graceful fallback when memory is disabled
  • ✅ TypeScript compilation without errors

🎨 Design Decisions

Tool-First Approach

  • Memory prompts are embedded in tool descriptions rather than global system prompt
  • Follows existing tool architecture patterns
  • Self-contained and modular design

Graceful Degradation

  • Agent works normally when MEM0_API_KEY is not provided
  • Memory operations return helpful error messages
  • No breaking changes to existing functionality

Clean Architecture

  • Memory system is completely optional and modular
  • Existing tools and workflows unaffected
  • Clear separation of concerns

🔮 Future Enhancements

  • Local storage fallback for offline memory
  • Memory analytics and insights
  • Implement temporary memory with life till tab is not closed.
  • Smart memory cleanup and optimization
  • Integration with other tools.

This implementation transforms the BrowserOS agent from a stateless automation tool into an intelligent assistant that learns, remembers, and personalizes the browsing experience. The memory system enables true task continuity and creates a foundation for advanced AI assistant capabilities.

Ready for review and testing! 🚀

@github-actions
Copy link
Contributor

github-actions bot commented Aug 26, 2025

CLA Assistant Lite bot ✅ All contributors have signed the CLA. Thank you for helping make BrowserOS better!
Posted by the CLA Assistant Lite bot.

@keshav1sharma
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

@felarof99
Copy link
Contributor

I started reviewing. But looking through the file changes, it looks like there are a number of linter/formatting fixes mixed in with the core logic for the memory system.

To keep this PR focused purely on the new memory feature (which makes it much easier to review), would you mind reverting the linting changes for now?

We can always tackle the code formatting in a separate, dedicated PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's a basic unit test for this file. You can look at unit tests for tools as reference.

The style guide we follow for unit test is -- have describe and within it the string should start with "tests...." to explain what it is testing. it("tests....)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the test files

@felarof99
Copy link
Contributor

Looks great, thanks for the contribution @keshav1sharma!

I have few minor nits.

Let's also add a global flag to enable/disable this feature add a small unit test to check that when it is disabled MemoryManager is not created.

@keshav1sharma
Copy link
Author

Hi @felarof99 I have added a global flag to enable/disable this feature and unit test files for it. Please take a look and let me know if any other changes required.

…n, tools, and prompts

- Added MemoryConfig interface and default configuration in config.ts
- Implemented memory management functionalities in index.ts
- Defined memory types and schemas in types.ts
- Created memory tools including MemoryTool and MemoryAwarePlannerTool
- Developed prompts for memory tool usage and system instructions
- Added memory system prompts to BrowserAgent for task continuity and learning.
- Implemented memory tool registration in BrowserAgent.
- Introduced memory management in NxtScape for improved task execution.
- Updated ExecutionContext to support memory manager.
- Enhanced tool result storage in memory based on tool type and importance.
- Configured webpack to inject memory API key at build time.
@felarof99 felarof99 force-pushed the feature/agent_memory_implementation branch from 0c3191d to 16e7604 Compare September 2, 2025 14:51
@felarof99
Copy link
Contributor

I rebased the PR, fixing merge conflicts.

@felarof99
Copy link
Contributor

felarof99 commented Sep 2, 2025

Thanks Keshav for addressing my previous questions.

Follow-up question: why are we storing results from planner tool, search tool into long term memory? This would be end up being quite expensive -- per users * number of agent queries per day * number of times planning/validating is called within execution.

image

Also, mem0 is long term memory, I think task execution doesn't really help with long term memory. Could you please think through this and fix it?

Let's use mem0 for long term memory preferences. For memory/storage within a multi-step task, we can just use chrome.local storage using StorageTool.

@felarof99
Copy link
Contributor

@keshav1sharma

@keshav1sharma
Copy link
Author

You’re right @felarof99 — storing planner/search results in mem0 would quickly add up and isn’t ideal for long-term memory. We can set custom expirations (e.g. 1 day) for temporary tool outputs if we really need to persist them, but I agree that it’s still costly. I’ll adjust the approach so mem0 is mainly used for longer-term preferences and context, while short-term task execution data will rely on chrome.local storage via the StorageTool.

@shadowfax92 shadowfax92 force-pushed the main branch 2 times, most recently from 3403b8b to 4d94b11 Compare October 1, 2025 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants