refactor(memory): decouple memory storage and runtime structures

This commit is contained in:
2026-03-10 19:41:05 +08:00
parent 760ba8300b
commit 5ad80d8b86
32 changed files with 603 additions and 1134 deletions

View File

@@ -2,7 +2,6 @@ package experimental;
import org.junit.jupiter.api.Test;
import work.slhaf.partner.core.memory.MemoryCapability;
import work.slhaf.partner.core.memory.pojo.MemoryResult;
import java.lang.reflect.Proxy;
@@ -15,12 +14,12 @@ public class ReflectionTest {
@Test
public void proxyTest() {
MemoryCapability memory = (MemoryCapability) Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[]{MemoryCapability.class}, (proxy, method, args) -> {
if ("selectMemory".equals(method.getName())) {
if ("getCurrentMemoryId".equals(method.getName())) {
System.out.println(111);
return new MemoryResult();
return "memory-id";
}
return null;
});
memory.selectMemory("111");
memory.getCurrentMemoryId();
}
}

View File

@@ -74,7 +74,7 @@ class ActionExecutorTest {
@BeforeEach
void setUp() {
lenient().when(cognationCapability.getChatMessages()).thenReturn(Collections.emptyList());
lenient().when(memoryCapability.getActivatedSlices(anyString())).thenReturn(Collections.emptyList());
lenient().when(memoryCapability.getActivatedSlices()).thenReturn(Collections.emptyList());
lenient().when(actionCapability.putPhaserRecord(any(Phaser.class), any(ExecutableAction.class)))
.thenAnswer(inv -> new PhaserRecord(inv.getArgument(0), inv.getArgument(1)));
lenient().when(actionCapability.loadMetaActionInfo(anyString())).thenAnswer(inv -> {

View File

@@ -1,17 +1,15 @@
package work.slhaf.partner.module.modules.core;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.jetbrains.annotations.NotNull;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import work.slhaf.partner.api.agent.runtime.interaction.flow.ContextBlock;
import work.slhaf.partner.api.chat.pojo.Message;
import work.slhaf.partner.api.chat.pojo.MetaMessage;
import work.slhaf.partner.core.cognation.CognationCapability;
import work.slhaf.partner.runtime.interaction.data.context.PartnerRunningFlowContext;
@@ -19,13 +17,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.ReentrantLock;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.anyString;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.verify;
@ExtendWith(MockitoExtension.class)
class CommunicationProducerTest {
@@ -100,12 +93,6 @@ class CommunicationProducerTest {
Message lastAssistantMessage = producer.getChatMessages().get(3);
assertEquals("收到", lastAssistantMessage.getContent());
ArgumentCaptor<MetaMessage> metaMessageCaptor = ArgumentCaptor.forClass(MetaMessage.class);
verify(cognationCapability).addMetaMessage(anyString(), metaMessageCaptor.capture());
MetaMessage metaMessage = metaMessageCaptor.getValue();
assertNotNull(metaMessage);
assertTrue(metaMessage.getUserMessage().getContent().startsWith("[USER]: u-1: 你好,介绍一下你现在看到的上下文"));
assertEquals("收到", metaMessage.getAssistantMessage().getContent());
assertEquals("收到", context.getCoreResponse().getString("text"));
}