fix(agent): align pi session tool options

This commit is contained in:
Peter Steinberger
2026-04-22 14:38:37 +01:00
parent fef830f4cf
commit d7ea136384
3 changed files with 13 additions and 16 deletions

View File

@@ -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,

View File

@@ -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<CreateAgentSessionOptions["tools"]>;
customTools: NonNullable<CreateAgentSessionOptions["customTools"]>;
sessionManager: unknown;
settingsManager: unknown;
resourceLoader: unknown;

View File

@@ -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,