Skip to content

Commit a0d66f1

Browse files
Copilotphrocker
andauthored
Add userId to agent memory markings and persist conversation history (#49)
* Initial plan * Fix agent memory markings to include userId for privacy scoping Co-authored-by: phrocker <[email protected]> * Apply same userId marking fix to ChatWSHandler websocket path Co-authored-by: phrocker <[email protected]> * Add persistent memory storage for user messages and agent responses in ChatWSHandler Co-authored-by: phrocker <[email protected]> * Update --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: phrocker <[email protected]> Co-authored-by: Marc Parisi <[email protected]>
1 parent d9a18bd commit a0d66f1

File tree

9 files changed

+141
-318
lines changed

9 files changed

+141
-318
lines changed

api/src/main/java/io/sentrius/sso/controllers/api/agents/AgentMemoryController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public AgentMemoryController(PersistentAgentMemoryStore memoryStore, VectorAgent
6363
public ResponseEntity<List<AgentMemoryDTO>> storeMemories(
6464
@RequestParam(name = "agentId") String agentId,
6565
@RequestBody List<AgentMemoryDTO> memoryDTOs,
66-
@RequestParam(defaultValue = "false") boolean generateEmbedding,
66+
@RequestParam(defaultValue = "true") boolean generateEmbedding,
6767
HttpServletRequest request, HttpServletResponse response) {
6868

6969

core/src/main/java/io/sentrius/sso/core/dto/agents/AgentExecutionContextDTO.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ public void addToPersistentMemory(String key, JsonNode value, String classificat
8686
// Add to data list with persistent flag
8787
longTermMemories.put(key, memoryMeta);
8888

89+
log.info("Added persistent memory meta for {}", key);
90+
91+
} else {
92+
log.warn("AgentContext is null, cannot add to persistent memory");
8993
}
9094
}
9195

@@ -121,10 +125,13 @@ public boolean hasPersistentMemory() {
121125
}
122126

123127
public Map<String, JsonNode> flushPersistentMemory() {
124-
var persistentItems = getPersistentMemoryItems();
128+
// Deep copy each entry to avoid returning references to mutable JsonNodes
129+
Map<String, JsonNode> copy = new HashMap<>();
130+
for (Map.Entry<String, JsonNode> entry : getPersistentMemoryItems().entrySet()) {
131+
copy.put(entry.getKey(), entry.getValue().deepCopy());
132+
}
125133
longTermMemories.clear();
126-
return persistentItems;
127-
134+
return copy;
128135

129136
}
130137

core/src/main/java/io/sentrius/sso/core/services/agents/AgentClientService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import io.sentrius.sso.core.utils.JsonUtil;
2828
import io.sentrius.sso.provenance.ProvenanceEvent;
2929
import lombok.extern.slf4j.Slf4j;
30+
import org.aspectj.weaver.loadtime.Agent;
3031
import org.springframework.beans.factory.annotation.Value;
3132
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
3233
import org.springframework.stereotype.Service;
@@ -320,7 +321,8 @@ public void storeMemory(AgentExecution execution, String agentId, AgentMemoryDTO
320321
String url = "/api/v1/agents/memory/store";
321322
try {
322323
log.info("Storing memory for agentId {}: {}", agentId, memory.getMemoryKey());
323-
zeroTrustClientService.callPostOnApi(execution, url,memory,
324+
List<AgentMemoryDTO> dto = List.of(memory);
325+
zeroTrustClientService.callPostOnApi(execution, url,dto,
324326
Maps.immutableEntry("agentId",List.of(agentId)) );
325327
} catch (ZtatException e) {
326328
log.error("Failed to store memory for key {}", e.getMessage());

dataplane/src/test/java/io/sentrius/sso/core/services/abac/KeycloakAttributeSyncSchedulerTest.java

Lines changed: 0 additions & 301 deletions
This file was deleted.

0 commit comments

Comments
 (0)