MCPcopy Create free account
hub / github.com/modelscope/ms-agent / _hash_block

Method _hash_block

ms_agent/memory/default_memory.py:361–379  ·  view source on GitHub ↗

Compute sha256 hash of a message block for comparison

(self, block: List[Message])

Source from the content-addressed store, hash-verified

359 return blocks
360
361 def _hash_block(self, block: List[Message]) -> str:
362 """Compute sha256 hash of a message block for comparison"""
363 data = [message.to_dict_clean() for message in block]
364 allow_role = ['user', 'system', 'assistant', 'tool']
365 allow_role = [
366 role for role in allow_role if role not in self.ignore_roles
367 ]
368 allow_fields = ['reasoning_content', 'content', 'tool_calls', 'role']
369 allow_fields = [
370 field for field in allow_fields if field not in self.ignore_fields
371 ]
372
373 data = [{
374 field: value
375 for field, value in msg.items() if field in allow_fields
376 } for msg in data if msg['role'] in allow_role]
377
378 block_data = json5.dumps(data)
379 return hashlib.sha256(block_data.encode('utf-8')).hexdigest()
380
381 def _analyze_messages(
382 self,

Callers 2

add_singleMethod · 0.95
_analyze_messagesMethod · 0.95

Calls 2

to_dict_cleanMethod · 0.80
encodeMethod · 0.80

Tested by

no test coverage detected