praisonai 1.0.18 → 1.0.19

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.
@@ -6,7 +6,7 @@ export interface SimpleAgentConfig {
6
6
  llm?: string;
7
7
  markdown?: boolean;
8
8
  stream?: boolean;
9
- tools?: any[];
9
+ tools?: any[] | Function[];
10
10
  toolFunctions?: Record<string, Function>;
11
11
  }
12
12
  export declare class Agent {
@@ -18,6 +18,40 @@ class Agent {
18
18
  // Configure logging
19
19
  logger_1.Logger.setVerbose(this.verbose);
20
20
  logger_1.Logger.setPretty(this.pretty);
21
+ // Process tools array - handle both tool definitions and functions
22
+ if (config.tools && Array.isArray(config.tools)) {
23
+ // Convert tools array to proper format if it contains functions
24
+ const processedTools = [];
25
+ for (let i = 0; i < config.tools.length; i++) {
26
+ const tool = config.tools[i];
27
+ if (typeof tool === 'function') {
28
+ // If it's a function, extract its name and register it
29
+ const funcName = tool.name || `function_${i}`;
30
+ // Skip functions with empty names
31
+ if (funcName && funcName.trim() !== '') {
32
+ this.registerToolFunction(funcName, tool);
33
+ // Auto-generate tool definition
34
+ this.addAutoGeneratedToolDefinition(funcName, tool);
35
+ }
36
+ else {
37
+ // Generate a random name for functions without names
38
+ const randomName = `function_${Math.random().toString(36).substring(2, 9)}`;
39
+ this.registerToolFunction(randomName, tool);
40
+ // Auto-generate tool definition
41
+ this.addAutoGeneratedToolDefinition(randomName, tool);
42
+ }
43
+ }
44
+ else {
45
+ // If it's already a tool definition, add it as is
46
+ processedTools.push(tool);
47
+ }
48
+ }
49
+ // Add any pre-defined tool definitions
50
+ if (processedTools.length > 0) {
51
+ this.tools = this.tools || [];
52
+ this.tools.push(...processedTools);
53
+ }
54
+ }
21
55
  // Register directly provided tool functions if any
22
56
  if (config.toolFunctions) {
23
57
  for (const [name, func] of Object.entries(config.toolFunctions)) {
@@ -69,6 +103,8 @@ class Agent {
69
103
  if (!this.tools) {
70
104
  this.tools = [];
71
105
  }
106
+ // Ensure we have a valid function name
107
+ const functionName = name || func.name || `function_${Math.random().toString(36).substring(2, 9)}`;
72
108
  // Extract parameter names from function
73
109
  const funcStr = func.toString();
74
110
  const paramMatch = funcStr.match(/\(([^)]*)\)/);
@@ -77,8 +113,8 @@ class Agent {
77
113
  const toolDef = {
78
114
  type: "function",
79
115
  function: {
80
- name,
81
- description: `Auto-generated function for ${name}`,
116
+ name: functionName,
117
+ description: `Auto-generated function for ${functionName}`,
82
118
  parameters: {
83
119
  type: "object",
84
120
  properties: {},
@@ -105,7 +141,7 @@ class Agent {
105
141
  toolDef.function.parameters.required = required;
106
142
  }
107
143
  this.tools.push(toolDef);
108
- logger_1.Logger.debug(`Auto-generated tool definition for ${name}`);
144
+ logger_1.Logger.debug(`Auto-generated tool definition for ${functionName}`);
109
145
  }
110
146
  /**
111
147
  * Process tool calls from the model
@@ -40,14 +40,22 @@ function convertToOpenAIMessage(message) {
40
40
  function convertToOpenAITool(tool) {
41
41
  // If it's already in the correct format, return it
42
42
  if (tool.type === 'function' && typeof tool.type === 'string') {
43
+ // Ensure the function name is valid
44
+ if (!tool.function?.name || tool.function.name.trim() === '') {
45
+ tool.function.name = `function_${Math.random().toString(36).substring(2, 9)}`;
46
+ }
43
47
  return tool;
44
48
  }
49
+ // Generate a valid function name if none is provided
50
+ const functionName = tool.function?.name && tool.function.name.trim() !== ''
51
+ ? tool.function.name
52
+ : `function_${Math.random().toString(36).substring(2, 9)}`;
45
53
  // Otherwise, try to convert it
46
54
  return {
47
55
  type: 'function',
48
56
  function: {
49
- name: tool.function?.name || '',
50
- description: tool.function?.description || '',
57
+ name: functionName,
58
+ description: tool.function?.description || `Function ${functionName}`,
51
59
  parameters: tool.function?.parameters || {}
52
60
  }
53
61
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "praisonai",
3
- "version": "1.0.18",
3
+ "version": "1.0.19",
4
4
  "description": "PraisonAI TypeScript AI Agents Framework - Node.js, npm, and Javascript AI Agents Framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -62,7 +62,7 @@
62
62
  "fast-xml-parser": "^4.5.1",
63
63
  "node-fetch": "^2.6.9",
64
64
  "openai": "^4.81.0",
65
- "praisonai": "^1.0.17"
65
+ "praisonai": "^1.0.18"
66
66
  },
67
67
  "optionalDependencies": {
68
68
  "boxen": "^7.1.1",