Class: HTM::MCP::GetWorkingMemoryTool

Inherits:
FastMcp::Tool
  • Object
show all
Defined in:
lib/htm/mcp/tools.rb

Overview

Tool: Get working memory contents for session restore

Instance Method Summary collapse

Instance Method Details

#callObject



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/htm/mcp/tools.rb', line 90

def call
  htm   = Session.htm_instance
  robot = HTM::Models::Robot[htm.robot_id]
  Session.logger&.info "GetWorkingMemoryTool called for robot=#{htm.robot_name}"

  nodes = robot.robot_nodes_dataset
               .in_working_memory
               .eager(node: :tags)
               .order(Sequel.desc(:last_remembered_at))
               .all
               .filter_map { |rn| format_working_memory_entry(rn) }

  Session.logger&.info "GetWorkingMemoryTool complete: #{nodes.length} nodes in working memory"
  { success: true, robot_id: htm.robot_id, robot_name: htm.robot_name, count: nodes.length, working_memory: nodes }.to_json
rescue StandardError => e
  Session.logger&.error "GetWorkingMemoryTool error: #{e.message}"
  { success: false, error: e.message, count: 0, working_memory: [] }.to_json
end