Skip to content

Implement Advanced "Smart Memory" as an Agent-Tool Ecosystem for Persistent, Goal-Driven Context #111

@matiasmolinas

Description

@matiasmolinas

Problem:
The Evolving Agents Toolkit (EAT) currently uses SmartContext for transient, task-specific context. It lacks a persistent, queryable long-term memory system that allows agents (especially SystemAgent) to learn from past workflows, decisions, and outcomes. This limits their ability to build cumulative knowledge and improve planning based on historical experience. The user desires a "smart memory based on agent goals, capabilities, and previous workflow tasks," a "smart list of messages," and a "mini database that is a memory and context that has database capabilities," all implemented following EAT's philosophy where "all is an agent or a tool."

Proposed Solution:
Implement an advanced "Smart Memory" system as an ecosystem of specialized agents and tools. This system will manage persistent storage (in MongoDB) of agent experiences and contextual facts. Core agents like SystemAgent will interact with this memory ecosystem via dedicated tools to retrieve relevant historical information, build richer contexts for sub-tasks, and record new learnings.

Key New Agents and Tools:

  1. MemoryManagerAgent (New Agent):

    • Purpose: The central agent responsible for orchestrating the storage and retrieval of long-term memories and contextual facts. It acts as an interface to the underlying MongoDB memory collections.
    • LLM: Can be a relatively simple LLM, primarily focused on understanding requests for its tools.
    • Capabilities (exposed via SmartAgentBus):
      • store_agent_experience: Allows other agents to submit structured data about a completed task/workflow to be stored.
      • retrieve_relevant_experiences: Allows agents to query for past experiences relevant to a current goal or task.
      • summarize_message_history: (Could be a capability) Takes a list of messages and a target goal, returns a concise summary.
      • (Optional) store_contextual_fact, retrieve_contextual_facts.
    • Internal Tools (not directly exposed, used by MemoryManagerAgent itself):
      • MongoExperienceStoreTool: Interacts with the eat_agent_experiences MongoDB collection (CRUD operations, embedding generation for queryable fields if not handled by direct Mongo write).
      • MongoFactStoreTool (Optional): Interacts with eat_contextual_facts.
      • SemanticExperienceSearchTool: Performs semantic searches over the eat_agent_experiences collection using embedded fields.
      • MessageSummarizationTool: Uses an LLM to summarize message lists.
  2. ContextBuilderTool (New Tool for SystemAgent and other complex agents):

    • Purpose: Dynamically constructs an optimized SmartContext object to be passed to another agent for a specific sub-task. This tool encapsulates the logic of assembling relevant information.
    • Functionality (invoked by SystemAgent):
      1. Receives: target agent details, assigned sub-task/goal description, current broad workflow context (e.g., SystemAgent's SmartContext).
      2. Uses RequestAgentTool (from SmartAgentBus tools) to call MemoryManagerAgent.retrieve_relevant_experiences with the sub-task/goal.
      3. Uses RequestAgentTool to call MemoryManagerAgent.summarize_message_history (if needed) on the current long message history, tailored to the sub-task.
      4. Queries SmartLibrary (using SearchComponentTool) for components relevant to the sub-task, potentially using context from retrieved experiences.
      5. Assembles a new, lean SmartContext instance containing:
        • The specific current_task description for the recipient.
        • Summaries of highly relevant past experiences from MemoryManagerAgent.
        • The "smart list of messages" (summarized history).
        • Pointers/metadata of necessary components from SmartLibrary.
      6. Returns the populated SmartContext object (or its JSON representation).
  3. ExperienceRecorderTool (New Tool for SystemAgent and other agents):

    • Purpose: Facilitates the recording of completed tasks/workflows as structured experiences.
    • Functionality (invoked by SystemAgent after a significant task/workflow):
      1. Receives: summary of the goal, components involved, input context summary, key decisions, final outcome, output summary, and any feedback.
      2. Structures this data into the format expected by MemoryManagerAgent.store_agent_experience.
      3. Uses RequestAgentTool to call MemoryManagerAgent.store_agent_experience to persist the memory.

MongoDB Collections (Managed by MemoryManagerAgent's internal tools):

  • eat_agent_experiences: (As defined in the previous version of this issue) Stores records of completed tasks/workflows with embeddable fields for semantic search.
    • experience_id, primary_goal_description (embedded), sub_task_description (embedded), initiating_agent_id, involved_components, input_context_summary (embedded), key_decisions_made, final_outcome, output_summary (embedded), feedback_signals, timestamp.
  • (Optional) eat_contextual_facts: For atomic learned facts.

Workflow:

  1. SystemAgent Planning:
    • When SystemAgent receives a new complex goal, it can use ContextBuilderTool to query for relevant past experiences related to this goal before generating a detailed plan.
    • The ContextBuilderTool internally calls MemoryManagerAgent.retrieve_relevant_experiences.
    • The retrieved experiences inform SystemAgent's decision on component selection, workflow structure, etc.
  2. SystemAgent Task Delegation:
    • When SystemAgent delegates a sub-task to a worker agent (via SmartAgentBus.request_capability), it first uses ContextBuilderTool.
    • ContextBuilderTool crafts a tailored SmartContext for the worker agent, including relevant past experiences and a summarized message history related to the sub-task.
  3. Worker Agent Execution:
    • The worker agent receives this rich, relevant SmartContext.
  4. SystemAgent Recording Experience:
    • After a workflow (or a significant part of it) is completed, SystemAgent uses ExperienceRecorderTool.
    • ExperienceRecorderTool formats the outcome and calls MemoryManagerAgent.store_agent_experience to save the learning.

Tasks:

  1. Define Schemas: Finalize MongoDB document structures for eat_agent_experiences (and eat_contextual_facts if pursued).
  2. Implement MemoryManagerAgent:
    • Develop its internal tools (MongoExperienceStoreTool, SemanticExperienceSearchTool, MessageSummarizationTool).
    • Define its AgentMeta and capabilities for the SmartAgentBus.
    • Implement its ReActAgent logic to handle requests for its capabilities by calling its internal tools.
  3. Implement ContextBuilderTool:
    • Develop the logic as described above, ensuring it interacts with MemoryManagerAgent (via bus) and SmartLibrary.
  4. Implement ExperienceRecorderTool:
    • Develop logic to structure data and call MemoryManagerAgent (via bus).
  5. Integrate Tools with SystemAgent:
    • Add ContextBuilderTool and ExperienceRecorderTool to SystemAgent's available tools.
    • Modify SystemAgent's main ReAct loop:
      • To use ContextBuilderTool during planning and before delegating tasks.
      • To use ExperienceRecorderTool after completing significant tasks.
  6. Register MemoryManagerAgent: Ensure MemoryManagerAgent is created and registered on the SmartAgentBus during EAT initialization.
  7. Testing: Create multi-step scenarios to test:
    • MemoryManagerAgent's ability to store and retrieve experiences.
    • ContextBuilderTool's effectiveness in creating relevant, lean contexts.
    • ExperienceRecorderTool's ability to correctly log experiences.
    • SystemAgent's improved planning and context passing due to the new memory ecosystem.
  8. Documentation: Update ARCHITECTURE.md describing the new Smart Memory agent-tool ecosystem.

Acceptance Criteria:

  • MemoryManagerAgent is functional and registered on the SmartAgentBus, managing experience data in MongoDB.
  • ContextBuilderTool and ExperienceRecorderTool are implemented and usable by SystemAgent.
  • SystemAgent demonstrates use of these tools to:
    • Retrieve relevant past experiences to inform its current planning.
    • Construct and pass tailored SmartContext (with summarized messages and relevant experience insights) to sub-agents.
    • Record outcomes of its orchestrations into the persistent memory via MemoryManagerAgent.
  • The "smart list of messages" (summarized message history) functionality is evident in the context passed between agents.
  • The "mini-database" capability (querying eat_agent_experiences) is demonstrable through MemoryManagerAgent.retrieve_relevant_experiences.
  • The entire system adheres to the "everything is an agent or a tool" philosophy for memory management.

Potential Challenges:

  • Defining effective prompts and logic for MemoryManagerAgent's internal tools (especially MessageSummarizationTool and SemanticExperienceSearchTool).
  • Ensuring the ContextBuilderTool doesn't become a bottleneck; its operations (multiple LLM calls, bus requests) need to be efficient.
  • The complexity of SystemAgent's ReAct loop increases with the integration of these new memory tools.
  • Robustly defining what constitutes a "significant task" worthy of being recorded as an experience.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions