- 更新了WebSocket服务器的启动逻辑

- 发现了agent, websocket, interactionHub之间的循环引用导致IDEA调试出错问题,通过exclude解决
- 实现了CoreModel的execute执行逻辑,并且系统提示词将动态拼接以适应不同模块
- 移动EvaluatedSlice至shared/memory包下,避免层级混淆
- 提取清洗json方法至独立的工具类
- 将agent通过InputReceiver接口暴露至socketServer,而非直接交给其完整实例
- 调整模块加载时机->InteractionHub加载时进行加载
- 调整MemoryGraph中userDialogMap的结构,换用以用户id为主键
- 初步进行测试,记忆更新逻辑暂未实现
This commit is contained in:
2025-04-25 23:08:01 +08:00
parent 4e28adbc52
commit a83cf26f40
26 changed files with 328 additions and 82 deletions

View File

@@ -1,12 +1,16 @@
package memory;
import cn.hutool.json.JSONUtil;
import org.junit.jupiter.api.Test;
import work.slhaf.agent.common.chat.ChatClient;
import work.slhaf.agent.common.chat.constant.ChatConstant;
import work.slhaf.agent.common.chat.pojo.Message;
import work.slhaf.agent.common.model.ModelConstant;
import work.slhaf.agent.modules.memory.MemorySelector;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class AITest {
@@ -94,6 +98,44 @@ public class AITest {
run(input,ModelConstant.SLICE_EVALUATOR_PROMPT);
}
@Test
public void coreModelTest(){
String input = """
{
"text": "",
"datetime": "2024-03-22T09:00",
"character": "你是一个智能助手,专注于科技领域",
"memory_slices": [
{
"chatMessages": [
{"role": "user", "content": "量子计算近期的进展怎么样?"},
{"role": "assistant", "content": "量子计算在硬件和算法上都取得了突破IBM发布了433量子位处理器Google也在量子优越性上取得了进展。"}
],
"date": "2024-03-20",
"summary": "量子计算最新突破IBM发布433量子位处理器Google在量子优越性上取得进展。"
}
],
"static_memory": "用户对量子计算技术非常感兴趣。",
"dialog_map": {
"2024-03-20T10:30": "与用户讨论了量子计算的最新进展"
},
"user_dialog_map": {
"2024-03-20T10:30": "与用户讨论了量子计算的最新进展"
}
}
""";
run(input,ModelConstant.CORE_MODEL_PROMPT + "\r\n" + MemorySelector.modulePrompt);
}
@Test
public void map2jsonTest(){
HashMap<LocalDate,String> map = new HashMap<>();
map.put(LocalDate.now(),"hello");
map.put(LocalDate.now().plusDays(1),"world");
System.out.println(JSONUtil.toJsonPrettyStr(map));
}
private void run(String input, String prompt) {
ChatClient client = new ChatClient("https://open.bigmodel.cn/api/paas/v4/chat/completions", "3db444552530b7742b0c53425fb93dcc.LcVwYjByht9AC3N9", "glm-4-flash-250414");
List<Message> messages = new ArrayList<>();

View File

@@ -3,9 +3,9 @@ package memory;
import org.junit.Before;
import org.junit.Test;
import work.slhaf.agent.core.memory.MemoryGraph;
import work.slhaf.agent.core.memory.pojo.MemorySlice;
import work.slhaf.agent.core.memory.node.MemoryNode;
import work.slhaf.agent.core.memory.node.TopicNode;
import work.slhaf.agent.core.memory.pojo.MemorySlice;
import java.io.IOException;
import java.time.LocalDate;

View File

@@ -1,12 +1,10 @@
package memory;
import cn.hutool.core.date.LocalDateTimeUtil;
import org.junit.jupiter.api.Test;
import work.slhaf.agent.core.memory.MemoryGraph;
import work.slhaf.agent.core.memory.node.TopicNode;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
@@ -50,7 +48,7 @@ public void test1() {
// 输出
graph.setTopicNodes(topicMap);
graph.printTopicTree();
System.out.println(graph.getTopicTree());
}

View File

@@ -3,18 +3,17 @@ package memory;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import work.slhaf.agent.core.memory.MemoryGraph;
import work.slhaf.agent.core.memory.pojo.MemorySlice;
import work.slhaf.agent.core.memory.exception.UnExistedTopicException;
import work.slhaf.agent.core.memory.node.MemoryNode;
import work.slhaf.agent.core.memory.node.TopicNode;
import work.slhaf.agent.core.memory.pojo.MemoryResult;
import work.slhaf.agent.core.memory.pojo.MemorySlice;
import java.io.IOException;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertThrows;
class SearchTest {
private MemoryGraph memoryGraph;