MCPcopy Index your code
hub / github.com/kagent-dev/kagent / List

Method List

go/core/internal/httpserver/handlers/memory.go:247–279  ·  view source on GitHub ↗

List handles GET /api/memories and returns all memories for an agent+user, ranked by access frequency

(w ErrorResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

245
246// List handles GET /api/memories and returns all memories for an agent+user, ranked by access frequency
247func (h *MemoryHandler) List(w ErrorResponseWriter, r *http.Request) {
248 log := ctrllog.FromContext(r.Context())
249 agentName := r.URL.Query().Get("agent_name")
250 userID := r.URL.Query().Get("user_id")
251
252 if agentName == "" || userID == "" {
253 RespondWithError(w, http.StatusBadRequest, "Missing required query parameters (agent_name, user_id)")
254 return
255 }
256
257 memories, err := h.DatabaseService.ListAgentMemories(r.Context(), agentName, userID)
258 if err != nil {
259 log.Error(err, "failed to list agent memories")
260 RespondWithError(w, http.StatusInternalServerError, fmt.Sprintf("failed to list memories: %v", err))
261 return
262 }
263
264 response := make([]ListMemoryResponse, 0, len(memories))
265 for _, m := range memories {
266 item := ListMemoryResponse{
267 ID: m.ID,
268 Content: m.Content,
269 AccessCount: int(m.AccessCount),
270 CreatedAt: m.CreatedAt.Format(time.RFC3339),
271 }
272 if m.ExpiresAt != nil {
273 item.ExpiresAt = m.ExpiresAt.Format(time.RFC3339)
274 }
275 response = append(response, item)
276 }
277
278 RespondWithJSON(w, http.StatusOK, response)
279}
280
281// Delete handles DELETE /api/memories
282func (h *MemoryHandler) Delete(w ErrorResponseWriter, r *http.Request) {

Callers 15

TestMemoryHandlerFunction · 0.95
printLogsFunction · 0.45
agentDependencyFinderMethod · 0.45
findModelsUsingSecretMethod · 0.45
GetListFunction · 0.45
listReadyAgentsMethod · 0.45

Calls 6

RespondWithErrorFunction · 0.85
RespondWithJSONFunction · 0.85
QueryMethod · 0.80
GetMethod · 0.65
ListAgentMemoriesMethod · 0.65
ErrorMethod · 0.45

Tested by 2

TestMemoryHandlerFunction · 0.76
printLogsFunction · 0.36