diff --git a/src/agents/embedded-agent-runner/run/runtime-context-prompt.test.ts b/src/agents/embedded-agent-runner/run/runtime-context-prompt.test.ts index b80509f9839a..93340e8b10c0 100644 --- a/src/agents/embedded-agent-runner/run/runtime-context-prompt.test.ts +++ b/src/agents/embedded-agent-runner/run/runtime-context-prompt.test.ts @@ -5,7 +5,6 @@ import { buildCurrentInboundPrompt, buildCurrentInboundPromptContextPrefix, buildRuntimeContextCustomMessage, - buildRuntimeContextSystemContext, resolveRuntimeContextPromptParts, } from "./runtime-context-prompt.js"; @@ -352,20 +351,14 @@ describe("runtime context prompt submission", () => { }); }); - it("labels next-turn runtime context only when used as prompt-local system context", () => { - const systemContext = buildRuntimeContextSystemContext("secret runtime context"); + it("labels runtime-only events as system context", () => { + const parts = resolveRuntimeContextPromptParts({ + effectivePrompt: "internal event", + transcriptPrompt: "", + }); - expect(systemContext).toContain( - "OpenClaw runtime context for the immediately preceding user message.", - ); - expect(systemContext).toContain("not user-authored"); - expect(systemContext).toContain("secret runtime context"); - }); - - it("labels runtime-only events as system context", async () => { - const { buildRuntimeEventSystemContext } = await import("./runtime-context-prompt.js"); - - expect(buildRuntimeEventSystemContext("internal event")).toContain("OpenClaw runtime event."); - expect(buildRuntimeEventSystemContext("internal event")).toContain("not user-authored"); + expect(parts.runtimeSystemContext).toContain("OpenClaw runtime event."); + expect(parts.runtimeSystemContext).toContain("not user-authored"); + expect(parts.runtimeSystemContext).toContain("internal event"); }); }); diff --git a/src/agents/embedded-agent-runner/run/runtime-context-prompt.ts b/src/agents/embedded-agent-runner/run/runtime-context-prompt.ts index e534f388d243..a7d239a69be8 100644 --- a/src/agents/embedded-agent-runner/run/runtime-context-prompt.ts +++ b/src/agents/embedded-agent-runner/run/runtime-context-prompt.ts @@ -133,7 +133,10 @@ export function resolveRuntimeContextPromptParts(params: { : {}), runtimeContext, runtimeOnly: true, - runtimeSystemContext: buildRuntimeEventSystemContext(runtimeContext), + runtimeSystemContext: buildRuntimeContextMessageContent({ + runtimeContext, + kind: "runtime-event", + }), } : { prompt: "", @@ -169,16 +172,6 @@ function buildRuntimeContextMessageContent(params: { ].join("\n"); } -/** Builds the hidden next-turn system context payload for model conversion. */ -export function buildRuntimeContextSystemContext(runtimeContext: string): string { - return buildRuntimeContextMessageContent({ runtimeContext, kind: "next-turn" }); -} - -/** Builds the hidden runtime-event system context payload for empty runtime-only turns. */ -export function buildRuntimeEventSystemContext(runtimeContext: string): string { - return buildRuntimeContextMessageContent({ runtimeContext, kind: "runtime-event" }); -} - /** Creates a non-displayed custom transcript message for runtime context, if any exists. */ export function buildRuntimeContextCustomMessage( runtimeContext: string | undefined, @@ -190,7 +183,10 @@ export function buildRuntimeContextCustomMessage( return { role: "custom", customType: OPENCLAW_RUNTIME_CONTEXT_CUSTOM_TYPE, - content: buildRuntimeContextSystemContext(trimmedRuntimeContext), + content: buildRuntimeContextMessageContent({ + runtimeContext: trimmedRuntimeContext, + kind: "next-turn", + }), display: false, details: { source: "openclaw-runtime-context" }, timestamp: Date.now(),