overai 1.4.21 → 1.4.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -117,8 +117,29 @@ class Agent {
117
117
  }
118
118
  }
119
119
  else {
120
- // If it's already a tool definition, add it as is
121
- processedTools.push(tool);
120
+ // Check if it's a tool definition with an execute function
121
+ // Handle both top-level 'name' (simplified) and 'function.name' (OpenAI standard)
122
+ const toolName = tool.function?.name || tool.name;
123
+ const toolExecute = tool.execute;
124
+ if (toolName && typeof toolExecute === 'function') {
125
+ this.registerToolFunction(toolName, toolExecute);
126
+ }
127
+ // Normalize to OpenAI format if needed to ensure name consistency
128
+ if (tool.name && !tool.function) {
129
+ const normalizedTool = {
130
+ type: 'function',
131
+ function: {
132
+ name: tool.name,
133
+ description: tool.description,
134
+ parameters: tool.parameters
135
+ }
136
+ };
137
+ processedTools.push(normalizedTool);
138
+ }
139
+ else {
140
+ // If it's already in OpenAI format (or close enough), add it
141
+ processedTools.push(tool);
142
+ }
122
143
  }
123
144
  }
124
145
  // Add any pre-defined tool definitions
@@ -356,11 +377,43 @@ class Agent {
356
377
  }
357
378
  else {
358
379
  // Non-streaming with AI SDK backend
359
- const result = await backend.generateText({
360
- messages,
361
- temperature: 0.7
362
- });
363
- finalResponse = result.text;
380
+ if (this.tools) {
381
+ // Tool execution loop for AI SDK
382
+ let continueConversation = true;
383
+ let iterations = 0;
384
+ const maxIterations = 5;
385
+ while (continueConversation && iterations < maxIterations) {
386
+ iterations++;
387
+ const result = await backend.generateText({
388
+ messages,
389
+ temperature: 0.7,
390
+ tools: this.tools
391
+ });
392
+ // Add assistant response to messages
393
+ messages.push({
394
+ role: 'assistant',
395
+ content: result.text || '',
396
+ tool_calls: result.toolCalls
397
+ });
398
+ if (result.toolCalls && result.toolCalls.length > 0) {
399
+ const toolResults = await this.processToolCalls(result.toolCalls);
400
+ messages.push(...toolResults);
401
+ continueConversation = true;
402
+ }
403
+ else {
404
+ finalResponse = result.text;
405
+ continueConversation = false;
406
+ }
407
+ }
408
+ }
409
+ else {
410
+ // Simple generation without tools
411
+ const result = await backend.generateText({
412
+ messages,
413
+ temperature: 0.7
414
+ });
415
+ finalResponse = result.text;
416
+ }
364
417
  }
365
418
  }
366
419
  else if (this.stream && !this.tools) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "overai",
3
- "version": "1.4.21",
3
+ "version": "1.4.22",
4
4
  "description": "OverAI TypeScript AI Agents Framework - Build, Deploy, and Monetize AI Agents in Minutes",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",