惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 司徒正美
T
The Blog of Author Tim Ferriss
F
Fortinet All Blogs
Martin Fowler
Martin Fowler
罗磊的独立博客
The GitHub Blog
The GitHub Blog
L
LangChain Blog
A
About on SuperTechFans
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
D
DataBreaches.Net
宝玉的分享
宝玉的分享
U
Unit 42
阮一峰的网络日志
阮一峰的网络日志
Last Week in AI
Last Week in AI
N
Netflix TechBlog - Medium
The Cloudflare Blog
Microsoft Azure Blog
Microsoft Azure Blog
H
Help Net Security
美团技术团队
大猫的无限游戏
大猫的无限游戏
雷峰网
雷峰网
爱范儿
爱范儿
酷 壳 – CoolShell
酷 壳 – CoolShell
MongoDB | Blog
MongoDB | Blog

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
Project Tool Search target calls in transcripts (#80164) ...
scoootscooob · 2026-05-10 · via Recent Commits to openclaw:main

@@ -1,6 +1,10 @@

11

import { spawn } from "node:child_process";

22

import os from "node:os";

3-

import type { AgentToolResult, AgentToolUpdateCallback } from "@mariozechner/pi-agent-core";

3+

import type {

4+

AgentMessage,

5+

AgentToolResult,

6+

AgentToolUpdateCallback,

7+

} from "@mariozechner/pi-agent-core";

48

import type { ToolDefinition } from "@mariozechner/pi-coding-agent";

59

import { Type } from "typebox";

610

import type { OpenClawConfig } from "../config/types.openclaw.js";

@@ -37,11 +41,22 @@ export type ToolSearchCatalogToolExecutor = (params: {

3741

tool: CatalogTool;

3842

toolName: string;

3943

toolCallId: string;

44+

parentToolCallId?: string;

4045

input: unknown;

4146

signal?: AbortSignal;

4247

onUpdate?: AgentToolUpdateCallback<unknown>;

4348

}) => Promise<AgentToolResult<unknown>>;

444950+

export type ToolSearchTargetTranscriptProjection = {

51+

parentToolCallId?: string;

52+

toolCallId: string;

53+

toolName: string;

54+

input: unknown;

55+

result?: unknown;

56+

isError?: boolean;

57+

timestamp?: number;

58+

};

59+4560

export type ToolSearchConfig = {

4661

enabled: boolean;

4762

mode: ToolSearchMode;

@@ -518,6 +533,149 @@ function dropToolSearchControlTools(tools: AnyAgentTool[]): AnyAgentTool[] {

518533

return tools.filter((tool) => !TOOL_SEARCH_CONTROL_TOOL_NAMES.has(tool.name));

519534

}

520535536+

function readMessageToolResultId(message: AgentMessage): string | undefined {

537+

const record = message as unknown as Record<string, unknown>;

538+

const role = typeof record.role === "string" ? record.role : "";

539+

const canUseDirectId = role === "toolResult" || role === "tool";

540+

const direct = record.toolCallId ?? record.toolUseId ?? record.tool_use_id;

541+

if (canUseDirectId && typeof direct === "string" && direct.trim()) {

542+

return direct;

543+

}

544+

const content = record.content;

545+

if (!Array.isArray(content)) {

546+

return undefined;

547+

}

548+

for (const block of content) {

549+

if (!isRecord(block)) {

550+

continue;

551+

}

552+

if (block.type !== "toolResult") {

553+

continue;

554+

}

555+

const nested = block.toolCallId ?? block.toolUseId ?? block.tool_use_id ?? block.id;

556+

if (typeof nested === "string" && nested.trim()) {

557+

return nested;

558+

}

559+

}

560+

return undefined;

561+

}

562+563+

function textFromToolSearchProjectionResult(result: unknown, isError: boolean): string {

564+

if (isRecord(result)) {

565+

const details = isRecord(result.details) ? result.details : undefined;

566+

const detailError = details?.error;

567+

if (typeof detailError === "string" && detailError.trim()) {

568+

return detailError;

569+

}

570+

const content = result.content;

571+

if (Array.isArray(content)) {

572+

const text = content

573+

.map((item) => (isRecord(item) && typeof item.text === "string" ? item.text : ""))

574+

.filter(Boolean)

575+

.join("\n");

576+

if (text.trim()) {

577+

return text;

578+

}

579+

}

580+

}

581+

const safe = toJsonSafe(result);

582+

if (typeof safe === "string") {

583+

return safe;

584+

}

585+

const encoded = JSON.stringify(safe);

586+

if (typeof encoded === "string") {

587+

return encoded;

588+

}

589+

return isError ? "Tool Search target tool failed." : "Tool Search target tool completed.";

590+

}

591+592+

function buildToolSearchTargetTranscriptMessages(

593+

projection: ToolSearchTargetTranscriptProjection,

594+

): AgentMessage[] {

595+

const input = toJsonSafe(projection.input);

596+

const timestamp = projection.timestamp ?? Date.now();

597+

const resultRecord = isRecord(projection.result) ? projection.result : undefined;

598+

const resultContent =

599+

Array.isArray(resultRecord?.content) && resultRecord.content.length > 0

600+

? toJsonSafe(resultRecord.content)

601+

: [

602+

{

603+

type: "text",

604+

text: textFromToolSearchProjectionResult(

605+

projection.result,

606+

projection.isError === true,

607+

),

608+

},

609+

];

610+

return [

611+

{

612+

role: "assistant",

613+

content: [

614+

{

615+

type: "toolCall",

616+

id: projection.toolCallId,

617+

name: projection.toolName,

618+

arguments: input,

619+

input,

620+

},

621+

],

622+

stopReason: "toolUse",

623+

timestamp,

624+

} as unknown as AgentMessage,

625+

{

626+

role: "toolResult",

627+

toolCallId: projection.toolCallId,

628+

toolName: projection.toolName,

629+

isError: projection.isError === true,

630+

content: resultContent,

631+

timestamp,

632+

} as unknown as AgentMessage,

633+

];

634+

}

635+636+

export function projectToolSearchTargetTranscriptMessages(

637+

messages: AgentMessage[],

638+

projections: readonly ToolSearchTargetTranscriptProjection[],

639+

): AgentMessage[] {

640+

if (projections.length === 0) {

641+

return messages;

642+

}

643+

const byParent = new Map<string, ToolSearchTargetTranscriptProjection[]>();

644+

const unmatched: ToolSearchTargetTranscriptProjection[] = [];

645+

for (const projection of projections) {

646+

const parent = projection.parentToolCallId?.trim();

647+

if (!parent) {

648+

unmatched.push(projection);

649+

continue;

650+

}

651+

const group = byParent.get(parent) ?? [];

652+

group.push(projection);

653+

byParent.set(parent, group);

654+

}

655+

const inserted = new Set<ToolSearchTargetTranscriptProjection>();

656+

const projected: AgentMessage[] = [];

657+

for (const message of messages) {

658+

projected.push(message);

659+

const toolResultId = readMessageToolResultId(message);

660+

const group = toolResultId ? byParent.get(toolResultId) : undefined;

661+

if (!group) {

662+

continue;

663+

}

664+

for (const projection of group) {

665+

projected.push(...buildToolSearchTargetTranscriptMessages(projection));

666+

inserted.add(projection);

667+

}

668+

}

669+

for (const projection of [...unmatched, ...projections]) {

670+

if (inserted.has(projection)) {

671+

continue;

672+

}

673+

projected.push(...buildToolSearchTargetTranscriptMessages(projection));

674+

inserted.add(projection);

675+

}

676+

return projected;

677+

}

678+521679

export function createToolSearchCatalogRef(): ToolSearchCatalogRef {

522680

return {};

523681

}

@@ -888,6 +1046,7 @@ class ToolSearchRuntime {

8881046

tool: entry.tool,

8891047

toolName: entry.name,

8901048

toolCallId,

1049+

parentToolCallId: options?.parentToolCallId,

8911050

input: input ?? {},

8921051

signal: options?.signal ?? this.ctx.abortSignal,

8931052

onUpdate: options?.onUpdate,