MCPcopy Create free account
hub / github.com/MemTensor/MemOS / processAgent

Method processAgent

packages/memos-core/src/viewer/server.ts:4863–4943  ·  view source on GitHub ↗
(agentOwner: string, items: PendingItem[])

Source from the content-addressed store, hash-verified

4861
4862 // Process one agent's sessions sequentially
4863 const processAgent = async (agentOwner: string, items: PendingItem[]) => {
4864 const taskProcessor = new TaskProcessor(this.store, ctx);
4865 let skillEvolver: SkillEvolver | null = null;
4866
4867 if (enableSkills) {
4868 const recallEngine = new RecallEngine(this.store, this.embedder, ctx);
4869 skillEvolver = new SkillEvolver(this.store, recallEngine, ctx);
4870 taskProcessor.onTaskCompleted(async (task) => {
4871 try {
4872 await skillEvolver!.onTaskCompleted(task);
4873 this.ppState.skillsCreated++;
4874 send("skill", { taskId: task.id, title: task.title, agent: agentOwner });
4875 } catch (err) {
4876 this.log.warn(`Postprocess skill evolution error (${agentOwner}): ${err}`);
4877 }
4878 });
4879 }
4880
4881 for (const { sessionKey, action } of items) {
4882 if (this.ppAbort) break;
4883 const idx = incIdx();
4884 this.ppState.processed = globalIdx;
4885
4886 send("item", {
4887 index: idx,
4888 total: pendingItems.length,
4889 session: sessionKey,
4890 agent: agentOwner,
4891 step: "processing",
4892 action,
4893 });
4894
4895 try {
4896 if (action === "full") {
4897 await taskProcessor.onChunksIngested(sessionKey, Date.now());
4898 const activeTask = this.store.getActiveTask(sessionKey);
4899 if (activeTask) {
4900 await taskProcessor.finalizeTask(activeTask);
4901 const finalized = this.store.getTask(activeTask.id);
4902 this.ppState.tasksCreated++;
4903 send("item", {
4904 index: idx, total: pendingItems.length, session: sessionKey, agent: agentOwner,
4905 step: "done", taskTitle: finalized?.title || "", taskStatus: finalized?.status || "",
4906 });
4907 } else {
4908 send("item", {
4909 index: idx, total: pendingItems.length, session: sessionKey, agent: agentOwner,
4910 step: "done", taskTitle: "(no chunks)",
4911 });
4912 }
4913 } else if (action === "skill-only" && skillEvolver) {
4914 const completedTasks = this.store.getCompletedTasksForSession(sessionKey);
4915 let skillGenerated = false;
4916 for (const task of completedTasks) {
4917 if (this.ppAbort) break;
4918 try {
4919 await skillEvolver.onTaskCompleted(task);
4920 this.ppState.skillsCreated++;

Callers

nothing calls this directly

Calls 9

onTaskCompletedMethod · 0.95
onChunksIngestedMethod · 0.95
finalizeTaskMethod · 0.95
sendFunction · 0.85
warnMethod · 0.65
onTaskCompletedMethod · 0.45
getActiveTaskMethod · 0.45
getTaskMethod · 0.45

Tested by

no test coverage detected