Compare commits
No commits in common. "c257a98a37bd7f92ecf51b61893ff2b7039154c7" and "5c4f36ff0d2b58b4097194b96dc4925e804188b0" have entirely different histories.
c257a98a37
...
5c4f36ff0d
@ -314,15 +314,7 @@ class ToolOutputLengthMiddleware(AgentMiddleware):
|
||||
if isinstance(result, ToolMessage):
|
||||
# Process ToolMessage
|
||||
content = result.text
|
||||
# 如果内容为空字符串,填充为 "empty"
|
||||
if content is None or content == '':
|
||||
logger.info(f"Tool output for '{tool_name}' is empty, filling with 'empty'")
|
||||
return ToolMessage(
|
||||
content="empty",
|
||||
tool_call_id=result.tool_call_id,
|
||||
name=result.name
|
||||
)
|
||||
if len(content) > self.max_length:
|
||||
if content and len(content) > self.max_length:
|
||||
# Truncate the content
|
||||
truncated_content, metadata = self.truncate_content(content, tool_name)
|
||||
|
||||
@ -363,16 +355,7 @@ class ToolOutputLengthMiddleware(AgentMiddleware):
|
||||
for msg in messages:
|
||||
if isinstance(msg, ToolMessage):
|
||||
tool_msg_tool_name = getattr(msg, 'name', tool_name)
|
||||
msg_content = msg.content if isinstance(msg.content, str) else str(msg.content) if msg.content else ''
|
||||
# 如果内容为空字符串,填充为 "empty"
|
||||
if msg_content == '':
|
||||
logger.info(f"Tool output for '{tool_msg_tool_name}' in Command is empty, filling with 'empty'")
|
||||
updated_messages.append(ToolMessage(
|
||||
content="empty",
|
||||
tool_call_id=msg.tool_call_id,
|
||||
name=msg.name
|
||||
))
|
||||
elif self.should_process_tool(tool_msg_tool_name) and len(msg_content) > self.max_length:
|
||||
if self.should_process_tool(tool_msg_tool_name) and len(msg.content) > self.max_length:
|
||||
# Truncate the ToolMessage content
|
||||
truncated_content, metadata = self.truncate_content(msg.content, tool_msg_tool_name)
|
||||
|
||||
@ -441,15 +424,7 @@ class ToolOutputLengthMiddleware(AgentMiddleware):
|
||||
# Handle different return types (same logic as sync version)
|
||||
if isinstance(result, ToolMessage):
|
||||
content = result.text
|
||||
# 如果内容为空字符串,填充为 "empty"
|
||||
if content is None or content == '':
|
||||
logger.info(f"Tool output for '{tool_name}' is empty, filling with 'empty'")
|
||||
return ToolMessage(
|
||||
content="empty",
|
||||
tool_call_id=result.tool_call_id,
|
||||
name=result.name
|
||||
)
|
||||
if len(content) > self.max_length:
|
||||
if content and len(content) > self.max_length:
|
||||
truncated_content, metadata = self.truncate_content(content, tool_name)
|
||||
|
||||
truncated_message = ToolMessage(
|
||||
@ -483,16 +458,7 @@ class ToolOutputLengthMiddleware(AgentMiddleware):
|
||||
for msg in messages:
|
||||
if isinstance(msg, ToolMessage):
|
||||
tool_msg_tool_name = getattr(msg, 'name', tool_name)
|
||||
msg_content = msg.content if isinstance(msg.content, str) else str(msg.content) if msg.content else ''
|
||||
# 如果内容为空字符串,填充为 "empty"
|
||||
if msg_content == '':
|
||||
logger.info(f"Tool output for '{tool_msg_tool_name}' in Command is empty, filling with 'empty'")
|
||||
updated_messages.append(ToolMessage(
|
||||
content="empty",
|
||||
tool_call_id=msg.tool_call_id,
|
||||
name=msg.name
|
||||
))
|
||||
elif self.should_process_tool(tool_msg_tool_name) and len(msg_content) > self.max_length:
|
||||
if self.should_process_tool(tool_msg_tool_name) and len(msg.content) > self.max_length:
|
||||
truncated_content, metadata = self.truncate_content(msg.content, tool_msg_tool_name)
|
||||
|
||||
truncated_msg = ToolMessage(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user