Improve forum communication mechanism between agents.
This commit is contained in:
@@ -18,6 +18,17 @@ from ..utils.text_processing import (
|
||||
format_search_results_for_prompt
|
||||
)
|
||||
|
||||
# 导入论坛读取工具
|
||||
import sys
|
||||
import os
|
||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
||||
try:
|
||||
from utils.forum_reader import get_latest_host_speech, format_host_speech_for_prompt
|
||||
FORUM_READER_AVAILABLE = True
|
||||
except ImportError:
|
||||
FORUM_READER_AVAILABLE = False
|
||||
print("警告: 无法导入forum_reader模块,将跳过HOST发言读取功能")
|
||||
|
||||
|
||||
class FirstSummaryNode(StateMutationNode):
|
||||
"""根据搜索结果生成段落首次总结的节点"""
|
||||
@@ -62,9 +73,28 @@ class FirstSummaryNode(StateMutationNode):
|
||||
|
||||
# 准备输入数据
|
||||
if isinstance(input_data, str):
|
||||
message = input_data
|
||||
data = json.loads(input_data)
|
||||
else:
|
||||
message = json.dumps(input_data, ensure_ascii=False)
|
||||
data = input_data.copy() if isinstance(input_data, dict) else input_data
|
||||
|
||||
# 读取最新的HOST发言(如果可用)
|
||||
if FORUM_READER_AVAILABLE:
|
||||
try:
|
||||
host_speech = get_latest_host_speech()
|
||||
if host_speech:
|
||||
# 将HOST发言添加到输入数据中
|
||||
data['host_speech'] = host_speech
|
||||
self.log_info(f"已读取HOST发言,长度: {len(host_speech)}字符")
|
||||
except Exception as e:
|
||||
self.log_info(f"读取HOST发言失败: {str(e)}")
|
||||
|
||||
# 转换为JSON字符串
|
||||
message = json.dumps(data, ensure_ascii=False)
|
||||
|
||||
# 如果有HOST发言,添加到消息前面作为参考
|
||||
if FORUM_READER_AVAILABLE and 'host_speech' in data and data['host_speech']:
|
||||
formatted_host = format_host_speech_for_prompt(data['host_speech'])
|
||||
message = formatted_host + "\n" + message
|
||||
|
||||
self.log_info("正在生成首次段落总结")
|
||||
|
||||
@@ -208,9 +238,28 @@ class ReflectionSummaryNode(StateMutationNode):
|
||||
|
||||
# 准备输入数据
|
||||
if isinstance(input_data, str):
|
||||
message = input_data
|
||||
data = json.loads(input_data)
|
||||
else:
|
||||
message = json.dumps(input_data, ensure_ascii=False)
|
||||
data = input_data.copy() if isinstance(input_data, dict) else input_data
|
||||
|
||||
# 读取最新的HOST发言(如果可用)
|
||||
if FORUM_READER_AVAILABLE:
|
||||
try:
|
||||
host_speech = get_latest_host_speech()
|
||||
if host_speech:
|
||||
# 将HOST发言添加到输入数据中
|
||||
data['host_speech'] = host_speech
|
||||
self.log_info(f"已读取HOST发言,长度: {len(host_speech)}字符")
|
||||
except Exception as e:
|
||||
self.log_info(f"读取HOST发言失败: {str(e)}")
|
||||
|
||||
# 转换为JSON字符串
|
||||
message = json.dumps(data, ensure_ascii=False)
|
||||
|
||||
# 如果有HOST发言,添加到消息前面作为参考
|
||||
if FORUM_READER_AVAILABLE and 'host_speech' in data and data['host_speech']:
|
||||
formatted_host = format_host_speech_for_prompt(data['host_speech'])
|
||||
message = formatted_host + "\n" + message
|
||||
|
||||
self.log_info("正在生成反思总结")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user