fix: wire before_tool_call hook into tool execution (#6570) (thanks @ryancnelson) (#6660)

This commit is contained in:
Peter Steinberger
2026-02-01 14:52:11 -08:00
committed by GitHub
parent 6c6f1e9660
commit 8eb11bd304
9 changed files with 317 additions and 491 deletions
+9 -2
View File
@@ -23,6 +23,7 @@ import {
import { listChannelAgentTools } from "./channel-tools.js";
import { createOpenClawTools } from "./openclaw-tools.js";
import { wrapToolWithAbortSignal } from "./pi-tools.abort.js";
import { wrapToolWithBeforeToolCallHook } from "./pi-tools.before-tool-call.js";
import {
filterToolsByPolicy,
isToolAllowedByPolicies,
@@ -423,9 +424,15 @@ export function createOpenClawCodingTools(options?: {
// Always normalize tool JSON Schemas before handing them to pi-agent/pi-ai.
// Without this, some providers (notably OpenAI) will reject root-level union schemas.
const normalized = subagentFiltered.map(normalizeToolParameters);
const withHooks = normalized.map((tool) =>
wrapToolWithBeforeToolCallHook(tool, {
agentId,
sessionKey: options?.sessionKey,
}),
);
const withAbort = options?.abortSignal
? normalized.map((tool) => wrapToolWithAbortSignal(tool, options.abortSignal))
: normalized;
? withHooks.map((tool) => wrapToolWithAbortSignal(tool, options.abortSignal))
: withHooks;
// NOTE: Keep canonical (lowercase) tool names here.
// pi-ai's Anthropic OAuth transport remaps tool names to Claude Code-style names