mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 08:43:02 +08:00
- 发现了agent, websocket, interactionHub之间的循环引用导致IDEA调试出错问题,通过exclude解决 - 实现了CoreModel的execute执行逻辑,并且系统提示词将动态拼接以适应不同模块 - 移动EvaluatedSlice至shared/memory包下,避免层级混淆 - 提取清洗json方法至独立的工具类 - 将agent通过InputReceiver接口暴露至socketServer,而非直接交给其完整实例 - 调整模块加载时机->InteractionHub加载时进行加载 - 调整MemoryGraph中userDialogMap的结构,换用以用户id为主键 - 初步进行测试,记忆更新逻辑暂未实现
80 lines
2.5 KiB
Java
80 lines
2.5 KiB
Java
package work.slhaf.agent;
|
|
|
|
import lombok.Data;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.java_websocket.WebSocket;
|
|
import work.slhaf.agent.common.config.Config;
|
|
import work.slhaf.agent.core.InteractionHub;
|
|
import work.slhaf.agent.core.interaction.InputReceiver;
|
|
import work.slhaf.agent.core.interaction.TaskCallback;
|
|
import work.slhaf.agent.core.interaction.data.InteractionInputData;
|
|
import work.slhaf.agent.core.interaction.data.InteractionOutputData;
|
|
import work.slhaf.agent.gateway.AgentWebSocketServer;
|
|
import work.slhaf.agent.gateway.MessageSender;
|
|
|
|
import java.io.IOException;
|
|
import java.time.LocalDateTime;
|
|
|
|
@Data
|
|
@Slf4j
|
|
public class Agent implements TaskCallback, InputReceiver {
|
|
|
|
private static Agent agent;
|
|
private InteractionHub interactionHub;
|
|
private MessageSender messageSender;
|
|
|
|
public static Agent initialize() throws IOException {
|
|
if (agent == null) {
|
|
//加载配置
|
|
Config config = Config.getConfig();
|
|
agent = new Agent();
|
|
agent.setInteractionHub(InteractionHub.initialize());
|
|
agent.registerTaskCallback();
|
|
AgentWebSocketServer server = new AgentWebSocketServer(config.getWebSocketConfig().getPort(),agent);
|
|
server.start();
|
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
|
try {
|
|
for (WebSocket conn : server.getConnections()) {
|
|
conn.close();
|
|
}
|
|
server.stop();
|
|
log.info("WebSocketServer 已优雅关闭");
|
|
} catch (Exception e) {
|
|
log.error("关闭失败", e);
|
|
}
|
|
}));
|
|
|
|
agent.setMessageSender(server);
|
|
|
|
log.info("Agent 加载完毕..");
|
|
}
|
|
return agent;
|
|
}
|
|
|
|
/**
|
|
* 接收用户输入,包装为标准输入数据类
|
|
*/
|
|
public void receiveInput(InteractionInputData inputData) throws IOException, ClassNotFoundException, InterruptedException {
|
|
inputData.setLocalDateTime(LocalDateTime.now());
|
|
interactionHub.call(inputData);
|
|
}
|
|
|
|
|
|
/**
|
|
* 向用户返回输出内容
|
|
*/
|
|
public void sendToUser(String userInfo,String output){
|
|
System.out.println(output);
|
|
messageSender.sendMessage(new InteractionOutputData(output,userInfo));
|
|
}
|
|
|
|
@Override
|
|
public void onTaskFinished(String userInfo, String output) {
|
|
sendToUser(userInfo,output);
|
|
}
|
|
|
|
private void registerTaskCallback(){
|
|
interactionHub.setCallback(this);
|
|
}
|
|
}
|