-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(openclaw-plugin): add captureMinLength config to reduce unnecessary VLM token consumption #665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -354,7 +354,16 @@ const memoryPlugin = { | |
| ); | ||
|
|
||
| if (cfg.autoRecall || cfg.ingestReplyAssist) { | ||
| api.on("before_agent_start", async (event: { messages?: unknown[]; prompt: string }) => { | ||
| api.on("before_agent_start", async (event: { messages?: unknown[]; prompt: string }, ctx?: { agentId?: string }) => { | ||
| // Dynamically switch agent identity for multi-agent memory isolation. | ||
| // In multi-agent gateway deployments, the hook context carries the current | ||
| // agent's ID so we route memory operations to the correct agent_space. | ||
| const hookAgentId = ctx?.agentId; | ||
| if (hookAgentId) { | ||
| const client = await getClient(); | ||
| client.setAgentId(hookAgentId); | ||
| api.logger.info?.(`memory-openviking: switched to agentId=${hookAgentId} for recall`); | ||
| } | ||
| const queryText = extractLatestUserText(event.messages) || event.prompt.trim(); | ||
| if (!queryText) { | ||
| return; | ||
|
|
@@ -474,7 +483,14 @@ const memoryPlugin = { | |
| if (cfg.autoCapture) { | ||
| let lastProcessedMsgCount = 0; | ||
|
|
||
| api.on("agent_end", async (event: { success?: boolean; messages?: unknown[] }) => { | ||
| api.on("agent_end", async (event: { success?: boolean; messages?: unknown[] }, ctx?: { agentId?: string }) => { | ||
| // Dynamically switch agent identity for multi-agent memory isolation | ||
| const hookAgentId = ctx?.agentId; | ||
| if (hookAgentId) { | ||
| const client = await getClient(); | ||
| client.setAgentId(hookAgentId); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Bug] Consider using a const lastProcessedMsgCountByAgent = new Map<string, number>();
// in handler:
const agentKey = hookAgentId ?? cfg.agentId;
const lastCount = lastProcessedMsgCountByAgent.get(agentKey) ?? 0;
// ... after processing:
lastProcessedMsgCountByAgent.set(agentKey, messages.length); |
||
| api.logger.info?.(`memory-openviking: switched to agentId=${hookAgentId} for capture`); | ||
| } | ||
| if (!event.success || !event.messages || event.messages.length === 0) { | ||
| api.logger.info( | ||
| `memory-openviking: auto-capture skipped (success=${String(event.success)}, messages=${event.messages?.length ?? 0})`, | ||
|
|
@@ -495,7 +511,7 @@ const memoryPlugin = { | |
| const turnText = newTexts.join("\n"); | ||
|
|
||
| // 对合并文本做 capture decision(主要检查长度和命令过滤) | ||
| const decision = getCaptureDecision(turnText, cfg.captureMode, cfg.captureMaxLength); | ||
| const decision = getCaptureDecision(turnText, cfg.captureMode, cfg.captureMinLength, cfg.captureMaxLength); | ||
| const preview = turnText.length > 80 ? `${turnText.slice(0, 80)}...` : turnText; | ||
| api.logger.info( | ||
| `memory-openviking: capture-check shouldCapture=${String(decision.shouldCapture)} reason=${decision.reason} newMsgCount=${newCount} text="${preview}"`, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Bug]
setAgentId()mutates sharedOpenVikingClientstate (agentId,resolvedSpaceByScope,runtimeIdentity). In concurrent multi-agent scenarios, async handlers interleave atawaitpoints (e.g.,client.find()→normalizeTargetUri→resolveScopeSpace). For example:setAgentId("A"), thenawait client.find()(HTTP in-flight)setAgentId("B"), clearing cachedresolvedSpaceByScopefind()resumes —resolveScopeSpacenow usesthis.agentId = "B", deriving the wrongagent_spaceThis causes memories to be stored in / retrieved from the wrong agent's space. The same issue exists in the
agent_endhandler below (line 491).Consider either:
agentIdas a parameter throughfind()/request()so each call is self-contained