praisonai 1.0.17 → 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.
@@ -1,5 +1,6 @@
1
1
  export declare function setTaskMode(enabled: boolean): void;
2
2
  export { Agent, PraisonAIAgents, Task } from './proxy';
3
+ export type { ProxyAgentConfig } from './proxy';
3
4
  export type { AgentConfig } from './types';
4
5
  export type { TaskConfig } from './types';
5
- export type { PraisonAIAgentsConfig } from './simple';
6
+ export type { PraisonAIAgentsConfig, SimpleAgentConfig } from './simple';
@@ -4,6 +4,7 @@ import { Task } from './types';
4
4
  export interface ProxyAgentConfig extends Partial<SimpleAgentConfig>, Partial<TaskAgentConfig> {
5
5
  task?: Task;
6
6
  tools?: any[];
7
+ toolFunctions?: Record<string, Function>;
7
8
  }
8
9
  export declare class Agent {
9
10
  private simpleAgent;
@@ -29,7 +29,8 @@ class Agent {
29
29
  verbose: config.verbose,
30
30
  llm: config.llm,
31
31
  markdown: config.markdown,
32
- tools: config.tools
32
+ tools: config.tools,
33
+ toolFunctions: config.toolFunctions
33
34
  };
34
35
  this.simpleAgent = new simple_1.Agent(simpleConfig);
35
36
  }
@@ -6,7 +6,8 @@ export interface SimpleAgentConfig {
6
6
  llm?: string;
7
7
  markdown?: boolean;
8
8
  stream?: boolean;
9
- tools?: any[];
9
+ tools?: any[] | Function[];
10
+ toolFunctions?: Record<string, Function>;
10
11
  }
11
12
  export declare class Agent {
12
13
  private instructions;
@@ -27,6 +28,18 @@ export declare class Agent {
27
28
  * @param fn Function implementation
28
29
  */
29
30
  registerToolFunction(name: string, fn: Function): void;
31
+ /**
32
+ * Check if a tool definition exists for the given function name
33
+ * @param name Function name
34
+ * @returns True if a tool definition exists
35
+ */
36
+ private hasToolDefinition;
37
+ /**
38
+ * Auto-generate a tool definition based on the function
39
+ * @param name Function name
40
+ * @param func Function implementation
41
+ */
42
+ private addAutoGeneratedToolDefinition;
30
43
  /**
31
44
  * Process tool calls from the model
32
45
  * @param toolCalls Tool calls from the model
@@ -18,6 +18,50 @@ 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
+ }
55
+ // Register directly provided tool functions if any
56
+ if (config.toolFunctions) {
57
+ for (const [name, func] of Object.entries(config.toolFunctions)) {
58
+ this.registerToolFunction(name, func);
59
+ // Auto-generate tool definition if not already provided
60
+ if (!this.hasToolDefinition(name)) {
61
+ this.addAutoGeneratedToolDefinition(name, func);
62
+ }
63
+ }
64
+ }
21
65
  }
22
66
  createSystemPrompt() {
23
67
  let prompt = this.instructions;
@@ -35,6 +79,70 @@ class Agent {
35
79
  this.toolFunctions[name] = fn;
36
80
  logger_1.Logger.debug(`Registered tool function: ${name}`);
37
81
  }
82
+ /**
83
+ * Check if a tool definition exists for the given function name
84
+ * @param name Function name
85
+ * @returns True if a tool definition exists
86
+ */
87
+ hasToolDefinition(name) {
88
+ if (!this.tools)
89
+ return false;
90
+ return this.tools.some(tool => {
91
+ if (tool.type === 'function' && tool.function) {
92
+ return tool.function.name === name;
93
+ }
94
+ return false;
95
+ });
96
+ }
97
+ /**
98
+ * Auto-generate a tool definition based on the function
99
+ * @param name Function name
100
+ * @param func Function implementation
101
+ */
102
+ addAutoGeneratedToolDefinition(name, func) {
103
+ if (!this.tools) {
104
+ this.tools = [];
105
+ }
106
+ // Ensure we have a valid function name
107
+ const functionName = name || func.name || `function_${Math.random().toString(36).substring(2, 9)}`;
108
+ // Extract parameter names from function
109
+ const funcStr = func.toString();
110
+ const paramMatch = funcStr.match(/\(([^)]*)\)/);
111
+ const params = paramMatch ? paramMatch[1].split(',').map(p => p.trim()).filter(p => p) : [];
112
+ // Create a basic tool definition
113
+ const toolDef = {
114
+ type: "function",
115
+ function: {
116
+ name: functionName,
117
+ description: `Auto-generated function for ${functionName}`,
118
+ parameters: {
119
+ type: "object",
120
+ properties: {},
121
+ required: []
122
+ }
123
+ }
124
+ };
125
+ // Add parameters to the definition
126
+ if (params.length > 0) {
127
+ const properties = {};
128
+ const required = [];
129
+ params.forEach(param => {
130
+ // Remove type annotations if present
131
+ const paramName = param.split(':')[0].trim();
132
+ if (paramName) {
133
+ properties[paramName] = {
134
+ type: "string",
135
+ description: `Parameter ${paramName} for function ${name}`
136
+ };
137
+ required.push(paramName);
138
+ }
139
+ });
140
+ toolDef.function.parameters.properties = properties;
141
+ toolDef.function.parameters.required = required;
142
+ }
143
+ this.tools.push(toolDef);
144
+ logger_1.Logger.debug(`Auto-generated tool definition for ${functionName}`);
145
+ }
38
146
  /**
39
147
  * Process tool calls from the model
40
148
  * @param toolCalls 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.17",
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.12"
65
+ "praisonai": "^1.0.18"
66
66
  },
67
67
  "optionalDependencies": {
68
68
  "boxen": "^7.1.1",