perf: skip acp runtime work for no-media and no-command turns

This commit is contained in:
Peter Steinberger
2026-04-05 17:58:23 +01:00
parent 2ce38dfc31
commit adbcfbe2bb
3 changed files with 15 additions and 1 deletions

View File

@@ -106,6 +106,9 @@ async function resolveAcpAttachments(
ctx: FinalizedMsgContext,
cfg: OpenClawConfig,
): Promise<AcpTurnAttachment[]> {
if (!hasInboundMediaForAcp(ctx)) {
return [];
}
const {
MediaAttachmentCache,
isMediaUnderstandingSkipError,

View File

@@ -16,7 +16,9 @@ import { tryDispatchAcpReplyHook } from "./acp-runtime.js";
const event = {
ctx: buildTestCtx({
SessionKey: "agent:test:session",
BodyForAgent: "hello",
CommandBody: "/acp cancel",
BodyForCommands: "/acp cancel",
BodyForAgent: "/acp cancel",
}),
runId: "run-1",
sessionKey: "agent:test:session",

View File

@@ -41,10 +41,19 @@ function loadDispatchAcpRuntime() {
return dispatchAcpRuntimePromise;
}
function hasExplicitCommandCandidate(ctx: PluginHookReplyDispatchEvent["ctx"]): boolean {
return [ctx.CommandBody, ctx.BodyForCommands].some(
(value) => typeof value === "string" && value.trim().length > 0,
);
}
export async function tryDispatchAcpReplyHook(
event: PluginHookReplyDispatchEvent,
ctx: PluginHookReplyDispatchContext,
): Promise<PluginHookReplyDispatchResult | void> {
if (event.sendPolicy === "deny" && !hasExplicitCommandCandidate(event.ctx)) {
return;
}
const runtime = await loadDispatchAcpRuntime();
const bypassForCommand = await runtime.shouldBypassAcpDispatchForCommand(event.ctx, ctx.cfg);