INNER CODE UNIT · Python
_trim_tool_content
usepr/eva · eva.py:377
def _trim_tool_content(msg):
"""对 tool 消息内容做首尾各200字符截断(仅当长度超过400时)"""
if msg.get('role') == 'tool' and msg.get('content') and len(msg['content']) > 400:
c = msg['content']
msg = {**msg, 'content': c[:200] + '\n…(中间内容已省略)…\n' + c[-200:]}
return msg
def leave_memory_hints(hints):
global messages, COMPACT_PANIC, memory_hints, SYSTEM_PROMPT
compact_i = -1
for i in range(len(messages)-1, -1, -1):
if messages[i]['role'] == 'user' and messages[i]['content'] == COMPACT_PROMPT:
compact_i = i
break
last_user_i = compact_i - 1
for i in range(last_user_i, -1, -1):