Skip to content

Commit ba445e0

Browse files
committed
docs: document tool search surfaces
1 parent f1ec260 commit ba445e0

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

src/agents/tool-search.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import type { ToolDefinition } from "./sessions/index.js";
1919
import { asToolParamsRecord, jsonResult, ToolInputError } from "./tools/common.js";
2020
import type { AnyAgentTool } from "./tools/common.js";
2121

22+
// Tool Search compacts large tool catalogs behind a small search/describe/call
23+
// surface, with an optional isolated code runner for multi-step catalog use.
2224
export const TOOL_SEARCH_CODE_MODE_TOOL_NAME = "tool_search_code";
2325
export const TOOL_SEARCH_RAW_TOOL_NAME = "tool_search";
2426
export const TOOL_DESCRIBE_RAW_TOOL_NAME = "tool_describe";
@@ -58,6 +60,7 @@ export type ToolSearchCatalogToolExecutor = (params: {
5860
onUpdate?: AgentToolUpdateCallback;
5961
}) => Promise<AgentToolResult<unknown>>;
6062

63+
/** Transcript projection for target tool calls made through Tool Search. */
6164
export type ToolSearchTargetTranscriptProjection = {
6265
parentToolCallId?: string;
6366
toolCallId: string;
@@ -68,6 +71,7 @@ export type ToolSearchTargetTranscriptProjection = {
6871
timestamp?: number;
6972
};
7073

74+
/** Resolved Tool Search config after defaults, limits, and runtime support checks. */
7175
export type ToolSearchConfig = {
7276
enabled: boolean;
7377
mode: ToolSearchMode;
@@ -76,6 +80,7 @@ export type ToolSearchConfig = {
7680
maxSearchLimit: number;
7781
};
7882

83+
/** Per-run/session context used by Tool Search control tools. */
7984
export type ToolSearchToolContext = {
8085
config?: OpenClawConfig;
8186
runtimeConfig?: OpenClawConfig;
@@ -88,6 +93,7 @@ export type ToolSearchToolContext = {
8893
executeTool?: ToolSearchCatalogToolExecutor;
8994
};
9095

96+
/** Catalog entry retained behind compacted Tool Search control tools. */
9197
export type ToolSearchCatalogEntry = {
9298
id: string;
9399
source: CatalogSource;
@@ -217,6 +223,8 @@ function buildModelScriptSource(code) {
217223
}
218224
219225
function buildControllerSource() {
226+
// The controller returns promise-like bridge handles. The model code can await
227+
// them naturally, while the parent process serializes real tool calls.
220228
return (
221229
'"use strict";\n' +
222230
"(() => {\n" +
@@ -521,6 +529,8 @@ function catalogToolIdentity(tool: CatalogTool): number {
521529
}
522530

523531
function catalogEntriesFingerprint(entries: readonly ToolSearchCatalogEntry[]): string {
532+
// Fingerprints include object identity for executable tools because function
533+
// bodies are not JSON-stable but catalog reuse must not bind stale executors.
524534
return entries
525535
.map((entry) =>
526536
[
@@ -827,10 +837,12 @@ export function projectToolSearchTargetTranscriptMessages(
827837
return projected;
828838
}
829839

840+
/** Create an explicit catalog holder for callers that cannot rely on session keys. */
830841
export function createToolSearchCatalogRef(): ToolSearchCatalogRef {
831842
return {};
832843
}
833844

845+
/** Replace visible tools with Tool Search controls and register hidden catalog entries. */
834846
export function applyToolSearchCatalog(params: {
835847
tools: AnyAgentTool[];
836848
config?: OpenClawConfig;
@@ -857,6 +869,7 @@ export function applyToolSearchCatalog(params: {
857869
});
858870
}
859871

872+
/** Move client-provided tools into an existing Tool Search catalog. */
860873
export function addClientToolsToToolSearchCatalog(params: {
861874
tools: ToolDefinition[];
862875
config?: OpenClawConfig;
@@ -872,6 +885,7 @@ export function addClientToolsToToolSearchCatalog(params: {
872885
});
873886
}
874887

888+
/** Register catalog entries under run/session keys and optional direct refs. */
875889
export function registerToolSearchCatalog(params: {
876890
sessionId?: string;
877891
sessionKey?: string;
@@ -913,6 +927,7 @@ export function registerToolSearchCatalog(params: {
913927
return next;
914928
}
915929

930+
/** Clear Tool Search catalog state for a run/session/ref. */
916931
export function clearToolSearchCatalog(params: {
917932
sessionId?: string;
918933
sessionKey?: string;
@@ -1225,6 +1240,7 @@ export class ToolSearchRuntime {
12251240
}
12261241
}
12271242

1243+
/** Compact a native tool list into visible control tools plus hidden catalog entries. */
12281244
export function applyToolCatalogCompaction(params: {
12291245
tools: AnyAgentTool[];
12301246
enabled: boolean;
@@ -1348,6 +1364,7 @@ export function applyToolCatalogCompaction(params: {
13481364
};
13491365
}
13501366

1367+
/** Append client-side tool definitions to an already registered catalog. */
13511368
export function addClientToolsToToolCatalog(params: {
13521369
tools: ToolDefinition[];
13531370
enabled: boolean;
@@ -1562,6 +1579,8 @@ function runCodeModeChild(params: {
15621579
);
15631580
};
15641581
if (code === 0 && signal === null) {
1582+
// A clean exit can race the final IPC result. Wait briefly before
1583+
// treating it as failure so flushed bridge/result messages can arrive.
15651584
exitRejectionTimer = setTimeout(rejectOnExit, 250);
15661585
return;
15671586
}
@@ -1645,6 +1664,7 @@ function readCode(args: unknown): string {
16451664
return code;
16461665
}
16471666

1667+
/** Create Tool Search control tools for the current run/session context. */
16481668
export function createToolSearchTools(ctx: ToolSearchToolContext): AnyAgentTool[] {
16491669
const config = resolveToolSearchConfig(ctx.runtimeConfig ?? ctx.config);
16501670
const runtime = new ToolSearchRuntime(ctx, config);

src/agents/tools/skill-workshop-tool.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ import {
2828
type AnyAgentTool,
2929
} from "./common.js";
3030

31+
// Agent tool wrapper around Skill Workshop proposal lifecycle. The service owns
32+
// storage and scan semantics; this file handles schema, parameter coercion, and
33+
// compact model-facing output.
3134
const SKILL_WORKSHOP_ACTIONS = [
3235
"create",
3336
"update",
@@ -126,6 +129,7 @@ export type SkillWorkshopToolOptions = {
126129
origin?: SkillProposalOrigin;
127130
};
128131

132+
/** Create the Skill Workshop tool for proposal discovery and lifecycle actions. */
129133
export function createSkillWorkshopTool(options: SkillWorkshopToolOptions): AnyAgentTool {
130134
return {
131135
label: "Skill Workshop",
@@ -373,6 +377,8 @@ function listProposalEntries(params: {
373377
const query = params.query?.trim().toLowerCase();
374378
const normalizedQuery = query ? normalizeProposalSearchText(query) : undefined;
375379
const limit = Math.min(Math.max(params.limit, 1), 50);
380+
// Pending proposals sort first so the model sees actionable work before
381+
// historical applied/rejected records.
376382
return params.proposals
377383
.filter((proposal) => !params.status || proposal.status === params.status)
378384
.filter((proposal) => {

src/agents/tools/transcripts-tool.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import { TranscriptsStore, type TranscriptsSessionEntry } from "../../transcript
2121
import { summarizeTranscripts } from "../../transcripts/summary.js";
2222
import type { AnyAgentTool } from "./common.js";
2323

24+
// Transcript tool runtime for live capture, manual import, summarization, and
25+
// auto-started meeting sources. Active sessions are process-local live handles.
2426
type TranscriptsLogger = {
2527
warn: (message: string) => void;
2628
};
@@ -132,6 +134,8 @@ async function waitForPendingAutoStartsToSettle(
132134
}
133135
}
134136

137+
// Provider routing comes from tool params so manual imports and live providers
138+
// share one persisted source descriptor.
135139
function sourceFromParams(params: Record<string, unknown>): TranscriptSourceLocator {
136140
const providerId = readStringParam(params, "providerId", { trim: true }) ?? "manual-transcript";
137141
return {
@@ -156,6 +160,8 @@ function toolText(text: string, details?: Record<string, unknown>) {
156160
};
157161
}
158162

163+
// Summaries are persisted beside the session so stop/import/summarize actions
164+
// return both model-readable details and a durable artifact path.
159165
async function summarizeAndPersist(params: {
160166
config: ReturnType<typeof resolveTranscriptsConfig>;
161167
store: TranscriptsStore;
@@ -393,6 +399,7 @@ async function statusTranscripts(ctx: TranscriptsRuntimeContext) {
393399
);
394400
}
395401

402+
/** Create the agent-facing transcripts tool. */
396403
export function createTranscriptsTool(options?: {
397404
config?: OpenClawConfig;
398405
stateDir?: string;
@@ -435,6 +442,7 @@ export function createTranscriptsTool(options?: {
435442
};
436443
}
437444

445+
/** Create the process lifecycle service that starts configured transcript captures. */
438446
export function createTranscriptsAutoStartService(ctx: TranscriptsRuntimeContext): {
439447
start: () => void;
440448
stop: () => Promise<void>;
@@ -445,6 +453,8 @@ export function createTranscriptsAutoStartService(ctx: TranscriptsRuntimeContext
445453
const pendingStartControllers = new Set<AbortController>();
446454
const pendingStarts = new Set<Promise<void>>();
447455

456+
// Auto-start is retrying and stoppable; each scheduled timer is tracked so a
457+
// gateway shutdown can cancel retries before stopping any started sessions.
448458
const schedule = (run: () => void, delayMs: number) => {
449459
const timer = setTimeout(() => {
450460
timers.delete(timer);

0 commit comments

Comments
 (0)