惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
G
Google Developers Blog
S
SegmentFault 最新的问题
Microsoft Security Blog
Microsoft Security Blog
J
Java Code Geeks
罗磊的独立博客
H
Hackread – Cybersecurity News, Data Breaches, AI and More
量子位
P
Proofpoint News Feed
博客园 - 【当耐特】
MongoDB | Blog
MongoDB | Blog
L
LangChain Blog
F
Fortinet All Blogs
C
Check Point Blog
博客园_首页
I
InfoQ
Jina AI
Jina AI
Blog — PlanetScale
Blog — PlanetScale
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
酷 壳 – CoolShell
酷 壳 – CoolShell
Engineering at Meta
Engineering at Meta
美团技术团队
Vercel News
Vercel News
Apple Machine Learning Research
Apple Machine Learning Research

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix: lazy-load memory-core runtime surfaces · openclaw/op...
steipete · 2026-05-02 · via Recent Commits to openclaw:main

@@ -1,13 +1,168 @@

1-

import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";

2-

import { registerMemoryCli } from "./src/cli.js";

3-

import { registerDreamingCommand } from "./src/dreaming-command.js";

1+

import {

2+

jsonResult,

3+

resolveMemorySearchConfig,

4+

resolveSessionAgentId,

5+

type MemoryPluginRuntime,

6+

type OpenClawConfig,

7+

} from "openclaw/plugin-sdk/memory-core-host-runtime-core";

8+

import { resolveMemoryBackendConfig } from "openclaw/plugin-sdk/memory-core-host-runtime-files";

9+

import {

10+

definePluginEntry,

11+

type AnyAgentTool,

12+

type OpenClawPluginToolContext,

13+

} from "openclaw/plugin-sdk/plugin-entry";

14+

import { Type } from "typebox";

415

import { registerShortTermPromotionDreaming } from "./src/dreaming.js";

516

import { buildMemoryFlushPlan } from "./src/flush-plan.js";

617

import { registerBuiltInMemoryEmbeddingProviders } from "./src/memory/provider-adapters.js";

718

import { buildPromptSection } from "./src/prompt-section.js";

8-

import { listMemoryCorePublicArtifacts } from "./src/public-artifacts.js";

9-

import { memoryRuntime } from "./src/runtime-provider.js";

10-

import { createMemoryGetTool, createMemorySearchTool } from "./src/tools.js";

19+20+

type MemoryToolsModule = typeof import("./src/tools.js");

21+

type RuntimeProviderModule = typeof import("./src/runtime-provider.js");

22+23+

type MemoryToolOptions = {

24+

config?: OpenClawConfig;

25+

getConfig?: () => OpenClawConfig | undefined;

26+

agentSessionKey?: string;

27+

sandboxed?: boolean;

28+

};

29+30+

let memoryToolsModulePromise: Promise<MemoryToolsModule> | undefined;

31+

let runtimeProviderModulePromise: Promise<RuntimeProviderModule> | undefined;

32+33+

function loadMemoryToolsModule(): Promise<MemoryToolsModule> {

34+

memoryToolsModulePromise ??= import("./src/tools.js");

35+

return memoryToolsModulePromise;

36+

}

37+38+

function loadRuntimeProviderModule(): Promise<RuntimeProviderModule> {

39+

runtimeProviderModulePromise ??= import("./src/runtime-provider.js");

40+

return runtimeProviderModulePromise;

41+

}

42+43+

function getToolConfig(options: MemoryToolOptions): OpenClawConfig | undefined {

44+

return options.getConfig?.() ?? options.config;

45+

}

46+47+

function hasMemoryToolContext(options: MemoryToolOptions): boolean {

48+

const cfg = getToolConfig(options);

49+

if (!cfg) {

50+

return false;

51+

}

52+

const agentId = resolveSessionAgentId({

53+

sessionKey: options.agentSessionKey,

54+

config: cfg,

55+

});

56+

return Boolean(resolveMemorySearchConfig(cfg, agentId));

57+

}

58+59+

const MemorySearchSchema = Type.Object({

60+

query: Type.String(),

61+

maxResults: Type.Optional(Type.Number()),

62+

minScore: Type.Optional(Type.Number()),

63+

corpus: Type.Optional(

64+

Type.Union([

65+

Type.Literal("memory"),

66+

Type.Literal("wiki"),

67+

Type.Literal("all"),

68+

Type.Literal("sessions"),

69+

]),

70+

),

71+

});

72+73+

const MemoryGetSchema = Type.Object({

74+

path: Type.String(),

75+

from: Type.Optional(Type.Number()),

76+

lines: Type.Optional(Type.Number()),

77+

corpus: Type.Optional(

78+

Type.Union([Type.Literal("memory"), Type.Literal("wiki"), Type.Literal("all")]),

79+

),

80+

});

81+82+

function createLazyMemoryTool(params: {

83+

options: MemoryToolOptions;

84+

label: string;

85+

name: "memory_search" | "memory_get";

86+

description: string;

87+

parameters: typeof MemorySearchSchema | typeof MemoryGetSchema;

88+

load: (module: MemoryToolsModule, options: MemoryToolOptions) => AnyAgentTool | null;

89+

}): AnyAgentTool | null {

90+

if (!hasMemoryToolContext(params.options)) {

91+

return null;

92+

}

93+94+

let toolPromise: Promise<AnyAgentTool | null> | undefined;

95+

const loadTool = async () => {

96+

toolPromise ??= loadMemoryToolsModule().then((module) => params.load(module, params.options));

97+

return await toolPromise;

98+

};

99+100+

return {

101+

label: params.label,

102+

name: params.name,

103+

description: params.description,

104+

parameters: params.parameters,

105+

execute: async (toolCallId, toolParams, signal, onUpdate) => {

106+

const tool = await loadTool();

107+

if (!tool) {

108+

return jsonResult({

109+

disabled: true,

110+

unavailable: true,

111+

error: "memory search unavailable",

112+

});

113+

}

114+

return await tool.execute(toolCallId, toolParams, signal, onUpdate);

115+

},

116+

};

117+

}

118+119+

function createLazyMemorySearchTool(options: MemoryToolOptions): AnyAgentTool | null {

120+

return createLazyMemoryTool({

121+

options,

122+

label: "Memory Search",

123+

name: "memory_search",

124+

description:

125+

"Mandatory recall step: semantically search MEMORY.md + memory/*.md (and optional session transcripts) before answering questions about prior work, decisions, dates, people, preferences, or todos. Optional `corpus=wiki` or `corpus=all` also searches registered compiled-wiki supplements. `corpus=memory` restricts hits to indexed memory files (excludes session transcript chunks from ranking). `corpus=sessions` restricts hits to indexed session transcripts (same visibility rules as session history tools). If response has disabled=true, memory retrieval is unavailable and should be surfaced to the user.",

126+

parameters: MemorySearchSchema,

127+

load: (module, loadOptions) => module.createMemorySearchTool(loadOptions),

128+

});

129+

}

130+131+

function createLazyMemoryGetTool(options: MemoryToolOptions): AnyAgentTool | null {

132+

return createLazyMemoryTool({

133+

options,

134+

label: "Memory Get",

135+

name: "memory_get",

136+

description:

137+

"Safe exact excerpt read from MEMORY.md or memory/*.md. Defaults to a bounded excerpt when lines are omitted, includes truncation/continuation info when more content exists, and `corpus=wiki` reads from registered compiled-wiki supplements.",

138+

parameters: MemoryGetSchema,

139+

load: (module, loadOptions) => module.createMemoryGetTool(loadOptions),

140+

});

141+

}

142+143+

function resolveMemoryToolOptions(ctx: OpenClawPluginToolContext): MemoryToolOptions {

144+

const getConfig = () => ctx.getRuntimeConfig?.() ?? ctx.runtimeConfig ?? ctx.config;

145+

return {

146+

config: getConfig(),

147+

getConfig,

148+

agentSessionKey: ctx.sessionKey,

149+

sandboxed: ctx.sandboxed,

150+

};

151+

}

152+153+

const memoryRuntime: MemoryPluginRuntime = {

154+

async getMemorySearchManager(params) {

155+

const { memoryRuntime: runtime } = await loadRuntimeProviderModule();

156+

return await runtime.getMemorySearchManager(params);

157+

},

158+

resolveMemoryBackendConfig(params) {

159+

return resolveMemoryBackendConfig(params);

160+

},

161+

async closeAllMemorySearchManagers() {

162+

const { memoryRuntime: runtime } = await loadRuntimeProviderModule();

163+

await runtime.closeAllMemorySearchManagers?.();

164+

},

165+

};

11166

export default definePluginEntry({

12167

id: "memory-core",

13168

name: "Memory (Core)",

@@ -16,43 +171,39 @@ export default definePluginEntry({

16171

register(api) {

17172

registerBuiltInMemoryEmbeddingProviders(api);

18173

registerShortTermPromotionDreaming(api);

19-

registerDreamingCommand(api);

20174

api.registerMemoryCapability({

21175

promptBuilder: buildPromptSection,

22176

flushPlanResolver: buildMemoryFlushPlan,

23177

runtime: memoryRuntime,

24178

publicArtifacts: {

25-

listArtifacts: listMemoryCorePublicArtifacts,

179+

async listArtifacts(params) {

180+

const { listMemoryCorePublicArtifacts } = await import("./src/public-artifacts.js");

181+

return await listMemoryCorePublicArtifacts(params);

182+

},

26183

},

27184

});

2818529-

api.registerTool(

30-

(ctx) => {

31-

const getConfig = () => ctx.getRuntimeConfig?.() ?? ctx.runtimeConfig ?? ctx.config;

32-

return createMemorySearchTool({

33-

config: getConfig(),

34-

getConfig,

35-

agentSessionKey: ctx.sessionKey,

36-

sandboxed: ctx.sandboxed,

37-

});

38-

},

39-

{ names: ["memory_search"] },

40-

);

186+

api.registerTool((ctx) => createLazyMemorySearchTool(resolveMemoryToolOptions(ctx)), {

187+

names: ["memory_search"],

188+

});

4118942-

api.registerTool(

43-

(ctx) => {

44-

const getConfig = () => ctx.getRuntimeConfig?.() ?? ctx.runtimeConfig ?? ctx.config;

45-

return createMemoryGetTool({

46-

config: getConfig(),

47-

getConfig,

48-

agentSessionKey: ctx.sessionKey,

49-

});

190+

api.registerTool((ctx) => createLazyMemoryGetTool(resolveMemoryToolOptions(ctx)), {

191+

names: ["memory_get"],

192+

});

193+194+

api.registerCommand({

195+

name: "dreaming",

196+

description: "Enable or disable memory dreaming.",

197+

acceptsArgs: true,

198+

handler: async (ctx) => {

199+

const { handleDreamingCommand } = await import("./src/dreaming-command.js");

200+

return await handleDreamingCommand(api, ctx);

50201

},

51-

{ names: ["memory_get"] },

52-

);

202+

});

5320354204

api.registerCli(

55-

({ program }) => {

205+

async ({ program }) => {

206+

const { registerMemoryCli } = await import("./src/cli.js");

56207

registerMemoryCli(program);

57208

},

58209

{