From d7ea1363841bf8ce4430218f3dc672f7e099e146 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Wed, 22 Apr 2026 14:38:37 +0100 Subject: [PATCH] fix(agent): align pi session tool options --- src/agents/pi-embedded-runner/compact.ts | 12 +++++------- src/agents/pi-embedded-runner/run/attempt-session.ts | 6 ++++-- src/agents/pi-embedded-runner/run/attempt.ts | 11 ++++------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/agents/pi-embedded-runner/compact.ts b/src/agents/pi-embedded-runner/compact.ts index 53118156961..d312a5b343f 100644 --- a/src/agents/pi-embedded-runner/compact.ts +++ b/src/agents/pi-embedded-runner/compact.ts @@ -132,7 +132,7 @@ import { buildEmbeddedSystemPrompt, createSystemPromptOverride, } from "./system-prompt.js"; -import { collectAllowedToolNames, toSessionToolAllowlist } from "./tool-name-allowlist.js"; +import { collectAllowedToolNames } from "./tool-name-allowlist.js"; import { logProviderToolSchemaDiagnostics, normalizeProviderToolSchemas, @@ -839,14 +839,12 @@ export async function compactEmbeddedPiSessionDirect( contextTokenBudget: ctxInfo.tokens, }); - const { customTools } = splitSdkTools({ + const { builtInTools, customTools } = splitSdkTools({ tools: effectiveTools, sandboxEnabled: !!sandbox?.enabled, }); - // Pi treats `tools` as a name allowlist. Compaction uses the same custom - // tool path as normal turns, so pass names here to keep those tools active - // across compaction retries. - const sessionToolAllowlist = toSessionToolAllowlist(allowedToolNames); + // OpenClaw registers filtered tools through `customTools`; keep Pi's + // built-in tool list empty so the SDK does not re-enable defaults. const providerStreamFn = resolveCompactionProviderStream({ effectiveModel, @@ -884,7 +882,7 @@ export async function compactEmbeddedPiSessionDirect( modelRegistry, model: effectiveModel, thinkingLevel: mapThinkingLevel(thinkLevel), - tools: sessionToolAllowlist, + tools: builtInTools, customTools, sessionManager, settingsManager, diff --git a/src/agents/pi-embedded-runner/run/attempt-session.ts b/src/agents/pi-embedded-runner/run/attempt-session.ts index 0a51c79ebf7..fc45c68cf8b 100644 --- a/src/agents/pi-embedded-runner/run/attempt-session.ts +++ b/src/agents/pi-embedded-runner/run/attempt-session.ts @@ -1,3 +1,5 @@ +import type { CreateAgentSessionOptions } from "@mariozechner/pi-coding-agent"; + export type EmbeddedAgentSessionOptions = { cwd: string; agentDir: string; @@ -5,8 +7,8 @@ export type EmbeddedAgentSessionOptions = { modelRegistry: unknown; model: unknown; thinkingLevel: unknown; - tools: readonly string[]; - customTools: readonly unknown[]; + tools: NonNullable; + customTools: NonNullable; sessionManager: unknown; settingsManager: unknown; resourceLoader: unknown; diff --git a/src/agents/pi-embedded-runner/run/attempt.ts b/src/agents/pi-embedded-runner/run/attempt.ts index a0500b238e0..ef2c6b86a27 100644 --- a/src/agents/pi-embedded-runner/run/attempt.ts +++ b/src/agents/pi-embedded-runner/run/attempt.ts @@ -167,7 +167,7 @@ import { createSystemPromptOverride, } from "../system-prompt.js"; import { dropThinkingBlocks } from "../thinking.js"; -import { collectAllowedToolNames, toSessionToolAllowlist } from "../tool-name-allowlist.js"; +import { collectAllowedToolNames } from "../tool-name-allowlist.js"; import { installContextEngineLoopHook, installToolResultContextGuard, @@ -1121,11 +1121,8 @@ export async function runEmbeddedAttempt( : []; const allCustomTools = [...customTools, ...clientToolDefs]; - // Pi's `tools` option is a name allowlist, not the tool definitions. - // OpenClaw registers local tools through `customTools`, so passing the - // same names here keeps custom tools executable instead of silently - // filtering them out with an empty allowlist. - const sessionToolAllowlist = toSessionToolAllowlist(allowedToolNames); + // OpenClaw registers filtered tools through `customTools`; keep Pi's + // built-in tool list empty so the SDK does not re-enable defaults. ({ session } = await createEmbeddedAgentSessionWithResourceLoader({ createAgentSession: async (options) => @@ -1137,7 +1134,7 @@ export async function runEmbeddedAttempt( modelRegistry: params.modelRegistry, model: params.model, thinkingLevel: mapThinkingLevel(params.thinkLevel), - tools: sessionToolAllowlist, + tools: builtInTools, customTools: allCustomTools, sessionManager, settingsManager,