3838import io .sentrius .sso .core .services .UserService ;
3939import io .sentrius .sso .core .services .agents .AgentClientService ;
4040import io .sentrius .sso .core .services .agents .AgentContextService ;
41+ import io .sentrius .sso .core .services .agents .AgentMemorySearchService ;
4142import io .sentrius .sso .core .services .agents .AgentService ;
4243import io .sentrius .sso .core .services .auditing .AuditService ;
4344import io .sentrius .sso .core .services .security .CryptoService ;
@@ -85,6 +86,7 @@ public class AgentApiController extends BaseController {
8586 final ZeroTrustRequestService ztatRequestService ;
8687 final AgentContextService agentContextService ;
8788 final AgentClientService agentClientService ;
89+ final AgentMemorySearchService agentMemorySearchService ;
8890 final AppConfig appConfig ;
8991
9092 public AgentApiController (
@@ -96,7 +98,8 @@ public AgentApiController(
9698 ATPLPolicyService atplPolicyService ,
9799 ZeroTrustAccessTokenService ztatService , ZeroTrustRequestService ztrService , AgentService agentService ,
98100 ProvenanceKafkaProducer provenanceKafkaProducer , ZeroTrustRequestService ztatRequestService ,
99- AgentContextService agentContextService , AgentClientService agentClientService , AppConfig appConfig
101+ AgentContextService agentContextService , AgentClientService agentClientService ,
102+ AgentMemorySearchService agentMemorySearchService , AppConfig appConfig
100103 ) {
101104 super (userService , systemOptions , errorOutputService );
102105 this .auditService = auditService ;
@@ -111,6 +114,7 @@ public AgentApiController(
111114 this .ztatRequestService = ztatRequestService ;
112115 this .agentContextService = agentContextService ;
113116 this .agentClientService = agentClientService ;
117+ this .agentMemorySearchService = agentMemorySearchService ;
114118 this .appConfig = appConfig ;
115119 }
116120
@@ -826,4 +830,50 @@ public ResponseEntity<AgentContextDTO> createContext(
826830 return ResponseEntity .ok (dto );
827831 }
828832
833+ @ GetMapping ("/memory/search" )
834+ @ LimitAccess (applicationAccess = {ApplicationAccessEnum .CAN_MANAGE_APPLICATION })
835+ public ResponseEntity <?> searchAgentMemory (
836+ @ RequestParam (required = false ) String content ,
837+ @ RequestParam (required = false ) String agent ,
838+ @ RequestParam (required = false ) @ DateTimeFormat (iso = DateTimeFormat .ISO .DATE_TIME ) LocalDateTime startDate ,
839+ @ RequestParam (required = false ) @ DateTimeFormat (iso = DateTimeFormat .ISO .DATE_TIME ) LocalDateTime endDate ,
840+ @ RequestParam (defaultValue = "0" ) int page ,
841+ @ RequestParam (defaultValue = "20" ) int size
842+ ) {
843+ try {
844+ log .info ("Searching agent memory with parameters - content: '{}', agent: '{}', startDate: {}, endDate: {}, page: {}, size: {}" ,
845+ content , agent , startDate , endDate , page , size );
846+
847+ // Determine search type and execute appropriate search
848+ if (content != null && !content .trim ().isEmpty ()) {
849+ if (startDate != null && endDate != null ) {
850+ // Search by content and date range
851+ var results = agentMemorySearchService .searchByContentAndDateRange (
852+ content .trim (), startDate , endDate , page , size );
853+ return ResponseEntity .ok (results );
854+ } else if (agent != null && !agent .trim ().isEmpty ()) {
855+ // Search by specific agent and content
856+ var results = agentMemorySearchService .searchByAgentAndContent (
857+ agent .trim (), content .trim (), page , size );
858+ return ResponseEntity .ok (results );
859+ } else {
860+ // Search by content only
861+ var results = agentMemorySearchService .searchByContent (content .trim (), page , size );
862+ return ResponseEntity .ok (results );
863+ }
864+ } else if (agent != null && !agent .trim ().isEmpty ()) {
865+ // Search by agent only
866+ var results = agentMemorySearchService .searchByAgent (agent .trim (), page , size );
867+ return ResponseEntity .ok (results );
868+ } else {
869+ // Return all memories with pagination
870+ var results = agentMemorySearchService .getAllMemories (page , size );
871+ return ResponseEntity .ok (results );
872+ }
873+ } catch (Exception e ) {
874+ log .error ("Error searching agent memory" , e );
875+ return ResponseEntity .status (500 ).body ("Error searching agent memory: " + e .getMessage ());
876+ }
877+ }
878+
829879}
0 commit comments