Two-Stage Spreading Activation For Reconstructive Recall
In the realm of simulated brains and memory systems, the quest for realistic and human-like recall mechanisms is ongoing. Current recall implementations often rely on semantic search and relationship-aware synthesis, which, while effective, can implicitly favor identity memories through priority weighting. To truly mimic the reconstructive nature of human memory, a two-stage spreading activation approach is essential. This article delves into the intricacies of implementing such a system, exploring the challenges, solutions, and benefits of this advanced technique. Let’s embark on this journey to understand how two-stage spreading activation can revolutionize reconstructive recall.
The Need for Reconstructive Recall
Reconstructive recall is a memory retrieval process where the brain actively rebuilds past experiences rather than passively recalling stored information. This process is crucial for creating a more realistic and contextually relevant recall system in simulated brains. The SIMULATED_BRAIN specification emphasizes the importance of making recall reconstructive, moving beyond simple top-K vector searches to a system that leverages type-aware and priority-aware selection, relationships, and knowledge graph edges. This approach allows self, belief, and pattern memories to shape the answers generated, even if they don't score highest in initial semantic searches. The goal is to mimic how human memory works, where personal beliefs and past experiences heavily influence how we recall and interpret information.
The current implementation uses a combination of semantic search and relationship-aware synthesis, as detailed in prompts/memory-recall.txt. This involves using search_memories (a hybrid vector and keyword search) followed by reasoning about relationships between memories. The system is already priority-aware, with higher-priority memories ranking higher due to currentPriority boosts. It's also identity-biased, giving self and belief memories higher priority floors and type-dependent weighting. Furthermore, it's relationship-aware, with the agent pulling related memories via get_memories and reasoning over these relationships. However, this approach falls short of true reconstructive recall because it lacks an explicit spreading activation mechanism. Explicit spreading activation is essential to ensure that memories related to the query, even if not directly semantically relevant, can influence the recall process. This is particularly important for incorporating personal beliefs and long-held assumptions into the recall, making the responses more contextually rich and aligned with the simulated persona’s identity. By implementing a two-stage spreading activation, we aim to bridge this gap and achieve a more nuanced and realistic memory recall system.
Current Implementation and Its Limitations
Currently, the system uses a "seed search + grab neighbors" approach, where an initial semantic search provides seed memories, and related memories are fetched based on explicit links. The LLM (Language Learning Model) then reasons over these fetched memories. This method, while functional, has limitations. For instance, consider a query like "How do I handle creative burnout?" The system performs a semantic search to find top-K memories matching "creative burnout." If these memories have relatedIds, the agent may call get_memories to fetch neighboring memories. The LLM then synthesizes an answer from the search results and fetched relationships. Self and belief memories appear only if they score well semantically or are explicitly linked. The primary issue here is that if the user’s core belief about work-life balance doesn't use the exact words "creative burnout," it might not appear in the results, even if it's highly relevant to the persona's philosophy. This is a critical gap because personal beliefs and values often play a significant role in how we interpret and respond to situations. Without an explicit mechanism to activate and incorporate these related memories, the system can miss crucial contextual information, leading to less personalized and potentially less relevant responses. Therefore, the current approach, while a good starting point, lacks the depth and nuance required for truly reconstructive recall. The challenge is to develop a system that can intelligently activate related memories, such as those representing core beliefs, even if they are not directly semantically connected to the initial query. This requires a more sophisticated approach that goes beyond simple neighbor-grabbing and embraces a spreading activation model.
The Two-Stage Spreading Activation Approach
The two-stage spreading activation approach aims to address the limitations of the current system by explicitly propagating activation across related memories. This process allows the recall system to consider a broader context, incorporating memories that might not be semantically close to the initial query but are still highly relevant due to their relationship with other memories. The two stages involved are the Seed Stage and the Activation Stage.
Seed Stage
In the seed stage, the system performs an initial semantic search to retrieve top-K memories relevant to the query. This stage acts as the foundation for the recall process, identifying the most directly related episodic and pattern memories. For instance, when responding to the query, "How do I handle creative burnout?" this stage would return memories that specifically address burnout experiences, coping strategies, or recognized patterns related to similar situations. These seed memories serve as the starting points for the next stage, where activation spreads through the network of related memories. The key to this stage is finding a balance between retrieving enough relevant memories to kickstart the activation process and not overwhelming the system with too many irrelevant ones. The selection criteria often involve a combination of semantic similarity scores and keyword matches to ensure that the initial set of memories is highly pertinent to the query. This stage sets the stage for the more nuanced and context-aware recall that follows. By beginning with a focused set of relevant memories, the subsequent activation process can intelligently explore related concepts and beliefs, ultimately contributing to a more comprehensive and personalized response.
Activation Stage
The activation stage is where the magic happens. It involves spreading activation along relationship edges, boosting activation for self, belief, and pattern memory types to ensure identity bias. Activation propagates for one to two hops, accumulating activation scores. This process allows memories that are not semantically close to the initial query but are highly relevant to the user's identity and beliefs to be considered. This stage comprises several crucial steps: spreading activation along relationship edges, boosting activation for specific memory types, and propagating activation over multiple hops. The result is a recall set that combines semantically matched memories with relationally activated memories. For example, consider a scenario where the system is asked about handling creative burnout. In the activation stage, related memories such as those about work-life balance, stress management techniques, or personal values regarding productivity and self-care can be activated. These memories might not contain the exact phrase "creative burnout" but are crucial in shaping a response that reflects the user's unique perspective and values. By prioritizing self, belief, and pattern memories, the system ensures that the recall is identity-biased, meaning that the generated response aligns with the user's core beliefs and past experiences. The number of hops (typically one to two) determines how far the activation spreads, with each hop potentially bringing in a new set of related memories. Accumulating activation scores across multiple paths ensures that memories with stronger or more frequent connections are prioritized. This intricate process culminates in a recall set that not only includes directly relevant memories but also those that provide essential context and personal significance. This enables the LLM to generate answers that are not just factually accurate but also deeply personalized and reflective of the user’s identity.
Expected Behavior and Benefits
With the two-stage spreading activation in place, the expected behavior of the recall system changes significantly. When faced with a query like, “How do I handle creative burnout?” the system will first perform a semantic search to retrieve episodic and pattern memories related to burnout. Then, in the activation stage, it will spread activation along relationship edges, boosting memories associated with self, belief, and patterns. This process will propagate activation for one to two hops, accumulating activation scores. The final recall set will then combine both semantically matched and relationally activated memories. The LLM will synthesize an answer using both the direct matches and the identity-relevant beliefs. The most significant benefit of this approach is that the answer will include the user’s core belief about work-life balance, even if that belief wasn’t initially semantically top-scoring. This reconstructive, identity-biased response ensures that the character’s philosophy and values influence the answer, making it more personalized and contextually relevant. By integrating core beliefs and values, the system ensures that the responses are not just accurate but also authentic. The ability to tap into a broader range of memories, including those that provide crucial context, leads to more comprehensive and insightful answers. This method more closely mirrors human memory recall, where our personal beliefs and experiences significantly shape our understanding and responses. As a result, the recall system becomes more adept at providing solutions that are aligned with the user's unique identity and circumstances.
Affected Components and Implementation Options
Implementing two-stage spreading activation requires modifications across several components of the system, including prompts, agents, tools, repositories, and data types. The prompts/memory-recall.txt file will need to be updated to include instructions for spreading activation. The prompts/memory-base.txt file might reference spreading activation as part of the agent persona. On the agent/tools side, the src/llm/agent/runtime/ToolRuntime.ts file might require the addition of a spread_activation internal tool, and the src/llm/MemoryAgent.ts file will need adjustments in recall mode orchestration. The src/memory/IMemoryRepository.ts and src/memory/MemoryRepositoryPostgres.ts files will likely need updates to efficiently traverse relationships. Lastly, the src/memory/types.ts file already supports relationship weights, which will be crucial in the activation stage. There are several implementation options to consider.
Option 1: Explicit Spreading Activation Tool
One approach is to add a new internal tool called spread_activation to ToolRuntime. This tool would take seed memory IDs, the maximum number of hops, type boost settings, and a top-K limit as parameters. The implementation would involve starting with seed IDs each at an activation level of 1.0. For each hop, the system would query memories related to the current activated set via relationship edges. The activation would propagate as follows: newActivation = currentActivation * relationshipWeight * typeBoost * decayFactor. Activation scores would accumulate across multiple paths, and the tool would return the top-K memories by final activation score. The prompt update in memory-recall.txt would instruct the agent to use search_memories to find semantically relevant memories, then call spread_activation with the seed IDs, boosting self/belief/pattern types. The agent would then combine the semantic matches with activated memories and synthesize an answer. This approach provides a clear separation of concerns, encapsulating the activation logic within a dedicated tool.
Option 2: Repository-Level Spreading Activation Query
Another option is to add a dedicated repository method for spreading activation. This method would take the same parameters as the spread_activation tool but would be implemented directly within the IMemoryRepository. The SQL implementation in Postgres would use recursive CTEs to traverse relationship edges, apply type-dependent boosts, accumulate activation across multiple paths, and return results ordered by final activation score. The prompt would reference this through a modified search_memories function with a useSpreadingActivation: true flag. This approach centralizes the activation logic within the repository, potentially optimizing database queries and performance.
Option 3: Prompt-Level Orchestration
A third option, which requires no code changes, involves instructing the agent to manually implement spreading activation using existing tools. This can be achieved by updating the prompt to guide the agent through the steps of searching for initial memories, extracting relationships, fetching related memories, filtering by type, and synthesizing the answer. While this approach is less efficient due to multiple round-trips, it offers the advantage of immediate testing and validation of the spreading activation pattern before committing to code changes. It allows for a phased approach, where the concept is proven effective before investing in infrastructure modifications. Each option has its trade-offs in terms of complexity, performance, and maintainability. Choosing the right approach depends on the project's specific requirements and constraints. For instance, starting with Prompt-Level Orchestration might be ideal for quickly validating the concept, whereas adopting an Explicit Spreading Activation Tool could be more efficient and reusable in the long run.
Recommendation and Implementation Plan
Given the options, it’s best to start with Option 3, the prompt-level orchestration. This approach requires no immediate code changes and allows for testing the spreading activation pattern using existing tools. If this proves successful, the system can be refactored to Option 1 or 2 for improved performance and maintainability. If spreading activation proves valuable, implementing Option 1, the explicit tool, is recommended. This provides a clean separation of concerns, with the activation logic residing in a tool and the synthesis in the prompt. It's also reusable across recall modes and easier to optimize and test. The implementation plan can be divided into three phases.
Phase 1: Prompt-Based Prototype
Phase 1 focuses on creating a prompt-based prototype. This involves updating prompts/memory-recall.txt with a spreading activation pattern using existing tools. The agent should be explicitly instructed to prioritize self/belief/pattern memories from the activated set. The prototype should be tested with character memory queries to verify that identity-relevant memories appear even when they are not semantically top-scoring. Performance should be measured by counting tool calls and response latency. The primary goal of this phase is to validate the effectiveness of the spreading activation pattern before investing in more complex implementations. By using existing tools and focusing on prompt engineering, the team can quickly assess the feasibility and benefits of this approach. This phase ensures that the fundamental concept works in practice, setting the stage for more efficient and robust implementations in subsequent phases.
Phase 2: Dedicated Tool (if prototype succeeds)
If Phase 1 is successful, Phase 2 involves creating a dedicated tool for spreading activation. This includes designing the spread_activation tool interface with parameters for hops, type boosts, and top-K limits. The tool should be implemented in src/llm/agent/runtime/ToolRuntime.ts or as a repository method. A relationship traversal query should be added to src/memory/MemoryRepositoryPostgres.ts. The prompt should be updated to use the spread_activation tool instead of manual orchestration. Tests should be added to verify that activation propagates correctly, type boosts apply, and top-K limits work. Performance should be benchmarked against the prompt-based approach. This phase aims to create a robust and efficient tool for spreading activation, improving the recall system’s performance and maintainability. By encapsulating the activation logic in a dedicated tool, the system becomes more modular and easier to optimize. Rigorous testing ensures that the tool functions correctly and efficiently, laying the groundwork for broader integration and use. This phase is crucial for scaling the spreading activation mechanism and making it a core component of the memory recall system.
Phase 3: Tuning and Observability
Phase 3 focuses on tuning and observability. Activation scores should be added to the recall response for debugging. The spreading activation behavior should be documented in CHARACTER_MEMORY.md. Recommended type boost settings for different use cases should be provided. The team should consider automatic co-activation tracking to strengthen frequently co-recalled memory links. This phase aims to fine-tune the spreading activation process and make it more transparent and understandable. By adding activation scores to the recall response, developers can gain insights into how the system is working and identify areas for improvement. Clear documentation helps ensure that the spreading activation mechanism is well-understood and can be effectively used and maintained. Tuning type boost settings for various scenarios and exploring automatic co-activation tracking enhances the system’s adaptability and learning capabilities. This final phase ensures that the spreading activation mechanism is not only functional but also optimized for performance and long-term maintainability.
Acceptance Criteria
To ensure the successful implementation of two-stage spreading activation, specific acceptance criteria must be met in each phase.
Phase 1 (Prompt-Based)
In Phase 1, the recall prompt should instruct the agent to fetch related memories from search results. The agent should explicitly prioritize self/belief/pattern memories from the related set. A test query about burnout should include the user’s work-life balance belief, even if it wasn't semantically matched. A test query about content strategy should include self-identity memories about channel focus. These criteria ensure that the prompt-based prototype effectively implements the spreading activation pattern and prioritizes identity-relevant memories.
Phase 2 (Dedicated Tool)
In Phase 2, the spread_activation tool should accept seedIds, maxHops, typeBoost, and topK as parameters. Activation should propagate along relationship edges with the correct decay. Type boosts should apply, with self/belief memories receiving a 1.5-2.0x activation multiplier. Relationship weights should influence activation propagation. The tool should return the top-K memories by final activation score. Performance should be such that spreading activation adds less than 300ms to the recall operation. These criteria ensure that the dedicated tool functions correctly and efficiently, meeting the performance requirements for the recall system.
Phase 3 (Observability)
In Phase 3, the recall response should include activation scores for debugging. Documentation should explain how spreading activation creates identity-biased recall. These criteria ensure that the spreading activation mechanism is transparent, understandable, and can be effectively monitored and maintained. By providing activation scores and clear documentation, the system becomes more accessible for troubleshooting and optimization.
Conclusion
Implementing two-stage spreading activation is a significant step toward achieving truly reconstructive, identity-biased recall in simulated brains. By explicitly propagating activation along relationship edges and boosting self/belief/pattern memories, the system can generate more personalized, contextually relevant responses. Starting with prompt-level orchestration allows for rapid prototyping and validation, while a dedicated spreading activation tool ensures efficiency and scalability. This enhancement moves the memory system from simply “feeling like a personality” to explicitly embodying reconstructive, identity-biased recall. This approach mirrors the complexity of human memory retrieval, where past experiences and core beliefs shape how we recall and interpret information. The result is a more realistic and engaging simulation that can better reflect the nuances of human thought and behavior. By embracing two-stage spreading activation, we pave the way for more intelligent and human-like artificial intelligence systems. For further reading on memory systems and spreading activation, you can explore resources like The Spreading Activation Theory.