History

Simplify discover/catalog outputs for LLM

Rhys Sullivan committed 9 months ago

Commit d6f7cb81 parent 390357e2 files · +12 −43Browse files

Unified · Split

2 files
  1. executor/packages/convex/runtime/tool_invocation.ts +10 −41
  2. executor/packages/core/src/declaration-generation.ts +2 −2
executor/packages/convex/runtime/tool_invocation.ts+10−41
@@ -76,11 +76,7 @@ export async function invokeTool(ctx: ActionCtx, task: TaskRecord, call: ToolCal · 75 unmodified lines
7676 );
7777 }
7878
79− const payload = (input && typeof input === "object" && !Array.isArray(input))
80− ? (input as Record<string, unknown>)
81− : (typeof input === "string")
82− ? ({ query: input } satisfies Record<string, unknown>)
83− : {};
79+ const payload = input && typeof input === "object" ? (input as Record<string, unknown>) : {};
8480 const isAllowed = (path: string, approval: ToolDefinition["approval"]) =>
8581 getDecisionForContext(
8682 { path, approval, description: "", run: async () => null } as ToolDefinition,
@@ -88,22 +84,9 @@ export async function invokeTool(ctx: ActionCtx, task: TaskRecord, call: ToolCal · 1 unmodified line
8884 typedPolicies,
8985 ) !== "deny";
9086
91− const formatSignature = (inputHint: string | undefined, outputHint: string | undefined) => {
92− const args = (inputHint && inputHint.trim().length > 0) ? inputHint.trim() : "{}";
93− const out = (outputHint && outputHint.trim().length > 0) ? outputHint.trim() : "unknown";
94− return `(input: ${args}): Promise<${out}>`;
95− };
96−
97− const buildExampleCall = (path: string, previewKeys?: string[]) => {
98− const keys = Array.isArray(previewKeys) ? previewKeys : [];
99− if (keys.length === 0) {
100− return `await tools.${path}({});`;
101− }
102− const snippet = keys
103− .slice(0, 5)
104− .map((key) => `${key}: ...`)
105− .join(", ");
106− return `await tools.${path}({ ${snippet} });`;
87+ const normalizeHint = (value: unknown, fallback: string) => {
88+ const str = typeof value === "string" ? value.trim() : "";
89+ return str.length > 0 ? str : fallback;
10790 };
10891
10992 if (toolPath === "catalog.namespaces") {
@@ -145,19 +128,12 @@ export async function invokeTool(ctx: ActionCtx, task: TaskRecord, call: ToolCal · 35 unmodified lines
145128 const preferredPath = entry.preferredPath ?? entry.path;
146129 return {
147130 path: preferredPath,
148− aliases: entry.aliases ?? [],
149131 source: entry.source,
150132 approval: entry.approval,
151133 description: entry.description,
152− signatureInfo: {
153− input: entry.displayInput,
154− output: entry.displayOutput,
155− requiredKeys: entry.requiredInputKeys ?? [],
156− previewKeys: entry.previewInputKeys ?? [],
157− },
158− signatureText: formatSignature(entry.displayInput, entry.displayOutput),
159− canonicalSignature: formatSignature(entry.displayInput, entry.displayOutput),
160− exampleCall: buildExampleCall(preferredPath, entry.previewInputKeys),
134+ input: normalizeHint(entry.displayInput, "{}"),
135+ output: normalizeHint(entry.displayOutput, "unknown"),
136+ requiredKeys: entry.requiredInputKeys ?? [],
161137 };
162138 });
163139
@@ -184,19 +160,12 @@ export async function invokeTool(ctx: ActionCtx, task: TaskRecord, call: ToolCal · 20 unmodified lines
184160 const description = compact ? String(entry.description ?? "").split("\n")[0] : entry.description;
185161 return {
186162 path: preferredPath,
187− aliases: entry.aliases ?? [],
188163 source: entry.source,
189164 approval: entry.approval,
190165 description,
191− signature: formatSignature(entry.displayInput, entry.displayOutput),
192− canonicalSignature: formatSignature(entry.displayInput, entry.displayOutput),
193− signatureInfo: {
194− input: entry.displayInput,
195− output: entry.displayOutput,
196− requiredKeys: entry.requiredInputKeys ?? [],
197− previewKeys: entry.previewInputKeys ?? [],
198− },
199− exampleCall: buildExampleCall(preferredPath, entry.previewInputKeys),
166+ input: normalizeHint(entry.displayInput, "{}"),
167+ output: normalizeHint(entry.displayOutput, "unknown"),
168+ requiredKeys: entry.requiredInputKeys ?? [],
200169 };
201170 });
202171
executor/packages/core/src/declaration-generation.ts+2−2
@@ -30,8 +30,8 @@ export function generateToolInventory(tools: ToolDescriptor[]): string { · 29 unmodified lines
3030 ` ${namespaces.join(", ")}`,
3131 "",
3232 "Prefer one broad lookup over many small ones: use `tools.catalog.namespaces({})` and `tools.catalog.tools({ namespace?, query?, compact: false, depth: 2, limit: 20 })` first.",
33− "Then use `tools.discover({ query, depth?, limit?, compact? })` when you need ranking. It returns `{ bestPath, results, schemas?, total }` (not an array).",
34− "Prefer `bestPath` when present, otherwise copy a `results[i].exampleCall` for invocation shape.",
33+ "Then use `tools.discover({ query, depth?, limit?, compact? })` when you need ranking. It returns `{ bestPath, results, total }` (not an array).",
34+ "Prefer `bestPath` when present; each result includes `{ path, input, output, requiredKeys }` to help you form a correct call.",
3535 "For migration/ETL tasks: discover once, then execute in small batches and return compact summaries (counts, IDs, top-N samples).",
3636 "Never shadow the global `tools` object (do NOT write `const tools = ...`).",
3737 "Then call tools directly using the returned path.",

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t