Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 12, 2025

Adds short-term and long-term memory to enable the agent to maintain context across multi-step interactions.

Architecture

Three-tier memory system:

  • ShortTermMemory: Sliding window (50 entries) for recent context
  • LongTermMemory: Importance-filtered (threshold 0.7) persistent storage (200 entries)
  • CompositeMemory: Unified interface with deduplication and relevance-ranked retrieval

LLM integration:

  • Added memory field to ObserveElement schema for LLM to provide contextual observations
  • PromptBuilder injects relevant memories into prompts based on current instruction
  • Automatic importance scoring (0.3-1.0) based on action success and task completion

Checkpoint persistence:

  • MemorySnapshot serialization for checkpoint save/restore
  • Memories automatically persisted and restored across sessions

Configuration

val config = AgentConfig(
    enableMemory = true,                    // Toggle memory system
    shortTermMemorySize = 50,               // Sliding window size
    longTermMemorySize = 200,               // Max long-term entries
    longTermMemoryThreshold = 0.7,          // Min importance for long-term storage
    memoryRetrievalLimit = 10               // Max memories in prompts
)

Usage

val agent = BrowserPerceptiveAgent(driver, session, config)

// Memories auto-collected from LLM responses and auto-injected into prompts
agent.resolve("Search for products and compare prices")

// Manual memory operations
agent.memory.add("User prefers items under $100", importance = 0.9)
val relevant = agent.memory.retrieve(query = "price", limit = 5)

Files Changed

  • Core: BrowserPerceptiveAgent.kt, PromptBuilder.kt, PerceptiveAgent.kt, CheckpointManager.kt
  • New: AgentMemory.kt, ShortTermMemory.kt, LongTermMemory.kt, CompositeMemory.kt
  • Tests: Comprehensive coverage for all memory components (100% pass rate)
  • Docs: English and Chinese documentation with architecture, examples, and best practices
Original prompt

为 BrowserPerceptiveAgent 增加记忆支持。


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits November 12, 2025 06:03
- Created AgentMemory interface and implementations (ShortTermMemory, LongTermMemory, CompositeMemory)
- Added memory configuration to AgentConfig
- Integrated memory into BrowserPerceptiveAgent
- Updated PromptBuilder to include memory context in prompts
- Added memory field to ObserveElement
- Implemented automatic memory saving from LLM responses
- Created comprehensive unit tests for all memory components

Co-authored-by: galaxyeye <[email protected]>
- Added MemorySnapshot data class for serialization
- Updated AgentCheckpoint to include memory snapshot
- Implemented createSnapshot and restoreFromSnapshot in CompositeMemory
- Updated saveCheckpoint to capture memory state
- Updated restoreFromCheckpoint to restore memory state
- Added tests for memory snapshot functionality

Co-authored-by: galaxyeye <[email protected]>
- Created comprehensive English documentation in docs/agent-memory.md
- Created Chinese documentation in docs/zh/agent-memory.md
- Documented architecture, configuration, usage examples, and best practices
- Included LLM integration details and performance considerations

Co-authored-by: galaxyeye <[email protected]>
Copilot AI changed the title [WIP] Add memory support to BrowserPerceptiveAgent Add memory system to BrowserPerceptiveAgent Nov 12, 2025
Copilot AI requested a review from galaxyeye November 12, 2025 06:13
Copilot finished work on behalf of galaxyeye November 12, 2025 06:13
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