类 LongTermMemoryTools

java.lang.Object
io.agentscope.core.memory.LongTermMemoryTools

public class LongTermMemoryTools extends Object
Tool adapter that exposes long-term memory operations as agent-callable tools.

This class provides a clean separation between the core memory API (defined in LongTermMemory) and the tool interface used by agents. It adapts the developer-facing record() and retrieve() methods into tool functions with agent-friendly signatures.

Architecture:

  • LongTermMemoryBase: Defines core storage API (record(), retrieve())
  • LongTermMemoryTools: Adapts core API to tool interface for agent control
  • ReActAgent: Registers tools when AGENT_CONTROL mode is enabled

Usage Example:


 // Create long-term memory instance
 LongTermMemoryBase memory = Mem0LongTermMemory.builder()
     .agentName("Assistant")
     .userName("user_123")
     .build();

 // Create tool adapter
 LongTermMemoryTools tools = new LongTermMemoryTools(memory);

 // Register in ReActAgent (done automatically by framework)
 ReActAgent agent = ReActAgent.builder()
     .name("Assistant")
     .model(model)
     .longTermMemory(memory)
     .longTermMemoryMode(LongTermMemoryMode.AGENT_CONTROL)
     .build();
 
另请参阅:
  • 构造器详细资料

    • LongTermMemoryTools

      public LongTermMemoryTools(LongTermMemory memory)
      Creates a new tool adapter for the given long-term memory instance.
      参数:
      memory - The long-term memory instance to adapt
      抛出:
      IllegalArgumentException - if memory is null
  • 方法详细资料

    • wrap

      public static String wrap(String text)
    • recordToMemory

      @Tool(description="Record important information to long-term memory for future reference. Use this when the user shares preferences, personal information, or important facts that should be remembered across conversations.") public reactor.core.publisher.Mono<String> recordToMemory(@ToolParam(name="thinking",description="Your reasoning about what to record and why") String thinking, @ToolParam(name="content",description="List of specific facts to remember. Each item should be clear and concise.") List<String> content)
      Tool function for agent to record important information to long-term memory.
      参数:
      thinking - Agent's reasoning about what to record and why
      content - List of specific facts to remember (should be clear and concise)
      返回:
      A status message indicating success or failure
    • retrieveFromMemory

      @Tool(description="Retrieve information from long-term memory based on keywords. Use this to recall user preferences, past conversations, or important facts.") public reactor.core.publisher.Mono<String> retrieveFromMemory(@ToolParam(name="keywords",description="Keywords to search for in memory. Be specific (e.g., person names, dates, locations).") List<String> keywords)
      Tool function for agent to retrieve information from long-term memory.

      This method adapts the agent's keyword input into a query message and calls the underlying memory's LongTermMemory.retrieve(Msg) method.

      When to use:

      • User asks about past preferences or information
      • Agent needs context from previous conversations
      • Looking for patterns or historical data
      • Verifying stored information

      Example Agent Usage:

      
       {
         "name": "retrieve_from_memory",
         "input": {
           "keywords": ["travel", "Hangzhou", "preferences"]
         }
       }
       
      参数:
      keywords - List of keywords to search for (should be specific and relevant)
      返回:
      The retrieved memories as text