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
76 );76 );
77 }77 }
78 78
79 const payload = (input && typeof input === "object" && !Array.isArray(input))79 const payload = input && typeof input === "object" ? (input as Record<string, unknown>) : {};
80 ? (input as Record<string, unknown>)
81 : (typeof input === "string")
82 ? ({ query: input } satisfies Record<string, unknown>)
83 : {};
84 const isAllowed = (path: string, approval: ToolDefinition["approval"]) =>80 const isAllowed = (path: string, approval: ToolDefinition["approval"]) =>
85 getDecisionForContext(81 getDecisionForContext(
86 { path, approval, description: "", run: async () => null } as ToolDefinition,82 { 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
88 typedPolicies,84 typedPolicies,
89 ) !== "deny";85 ) !== "deny";
90 86
91 const formatSignature = (inputHint: string | undefined, outputHint: string | undefined) => {87 const normalizeHint = (value: unknown, fallback: string) => {
92 const args = (inputHint && inputHint.trim().length > 0) ? inputHint.trim() : "{}";88 const str = typeof value === "string" ? value.trim() : "";
93 const out = (outputHint && outputHint.trim().length > 0) ? outputHint.trim() : "unknown";89 return str.length > 0 ? str : fallback;
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} });`;
107 };90 };
108 91
109 if (toolPath === "catalog.namespaces") {92 if (toolPath === "catalog.namespaces") {
@@ -145,19 +128,12 @@ export async function invokeTool(ctx: ActionCtx, task: TaskRecord, call: ToolCal · 35 unmodified lines
145 const preferredPath = entry.preferredPath ?? entry.path;128 const preferredPath = entry.preferredPath ?? entry.path;
146 return {129 return {
147 path: preferredPath,130 path: preferredPath,
148 aliases: entry.aliases ?? [],
149 source: entry.source,131 source: entry.source,
150 approval: entry.approval,132 approval: entry.approval,
151 description: entry.description,133 description: entry.description,
152 signatureInfo: {134 input: normalizeHint(entry.displayInput, "{}"),
153 input: entry.displayInput,135 output: normalizeHint(entry.displayOutput, "unknown"),
154 output: entry.displayOutput,136 requiredKeys: entry.requiredInputKeys ?? [],
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),
161 };137 };
162 });138 });
163 139
@@ -184,19 +160,12 @@ export async function invokeTool(ctx: ActionCtx, task: TaskRecord, call: ToolCal · 20 unmodified lines
184 const description = compact ? String(entry.description ?? "").split("\n")[0] : entry.description;160 const description = compact ? String(entry.description ?? "").split("\n")[0] : entry.description;
185 return {161 return {
186 path: preferredPath,162 path: preferredPath,
187 aliases: entry.aliases ?? [],
188 source: entry.source,163 source: entry.source,
189 approval: entry.approval,164 approval: entry.approval,
190 description,165 description,
191 signature: formatSignature(entry.displayInput, entry.displayOutput),166 input: normalizeHint(entry.displayInput, "{}"),
192 canonicalSignature: formatSignature(entry.displayInput, entry.displayOutput),167 output: normalizeHint(entry.displayOutput, "unknown"),
193 signatureInfo: {168 requiredKeys: entry.requiredInputKeys ?? [],
194 input: entry.displayInput,
195 output: entry.displayOutput,
196 requiredKeys: entry.requiredInputKeys ?? [],
197 previewKeys: entry.previewInputKeys ?? [],
198 },
199 exampleCall: buildExampleCall(preferredPath, entry.previewInputKeys),
200 };169 };
201 });170 });
202 171
executor/packages/core/src/declaration-generation.ts+2−2
@@ -30,8 +30,8 @@ export function generateToolInventory(tools: ToolDescriptor[]): string { · 29 unmodified lines
30 ` ${namespaces.join(", ")}`,30 ` ${namespaces.join(", ")}`,
31 "",31 "",
32 "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.",32 "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).",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, otherwise copy a `results[i].exampleCall` for invocation shape.",34 "Prefer `bestPath` when present; each result includes `{ path, input, output, requiredKeys }` to help you form a correct call.",
35 "For migration/ETL tasks: discover once, then execute in small batches and return compact summaries (counts, IDs, top-N samples).",35 "For migration/ETL tasks: discover once, then execute in small batches and return compact summaries (counts, IDs, top-N samples).",
36 "Never shadow the global `tools` object (do NOT write `const tools = ...`).",36 "Never shadow the global `tools` object (do NOT write `const tools = ...`).",
37 "Then call tools directly using the returned path.",37 "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