Skip to content

Commit f96938e

Browse files
committed
Improved AI agents tools and logs. fixed unique name for tools
1 parent 813b429 commit f96938e

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/lib/server/ai/agent.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,14 +453,18 @@ export class AiAgent {
453453
}
454454

455455
try {
456+
console.log('[AiAgent] Making LLM call to:', endpoint);
457+
console.log('[AiAgent] Provider:', provider, 'Model:', modelName);
456458
const res = await fetch(endpoint, {
457459
method: 'POST',
458460
headers,
459461
body: JSON.stringify(body)
460462
});
461463

464+
console.log('[AiAgent] Response status:', res.status);
462465
if (!res.ok) {
463466
const errorData = await res.json();
467+
console.log('[AiAgent] Error data from provider:', errorData);
464468
throw new Error(errorData.error?.message || errorData.error || 'API Request failed');
465469
}
466470

src/lib/server/ai/toolbox.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,21 @@ export class AiToolbox {
4848
continue;
4949
}
5050

51-
const aiToolsModule = await loader();
51+
const aiToolsModule = await loader() as { getAiTools?: (userId: string) => Promise<ToolDefinition[]> | ToolDefinition[] };
5252
console.log(
5353
`[AiToolbox] Import successful for ${module.id}, has getAiTools:`,
5454
!!aiToolsModule.getAiTools
5555
);
5656
if (aiToolsModule.getAiTools) {
5757
console.log(`[AiToolbox] Loading AI tools for module: ${module.name}`);
5858
const moduleTools = await aiToolsModule.getAiTools(userId);
59-
console.log(`[AiToolbox] Module ${module.id} provided ${moduleTools.length} tools`);
60-
tools = [...tools, ...moduleTools];
59+
// Prefix tool names with module ID to avoid duplicates
60+
const prefixedTools = moduleTools.map(tool => ({
61+
...tool,
62+
name: `${module.id}_${tool.name}`
63+
}));
64+
console.log(`[AiToolbox] Module ${module.id} provided ${prefixedTools.length} tools`);
65+
tools = [...tools, ...prefixedTools];
6166
} else {
6267
console.log(`[AiToolbox] Module ${module.id} has no getAiTools function`);
6368
}

0 commit comments

Comments
 (0)