praisonai 1.0.17 → 1.0.18

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
  }
@@ -7,6 +7,7 @@ export interface SimpleAgentConfig {
7
7
  markdown?: boolean;
8
8
  stream?: boolean;
9
9
  tools?: any[];
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,16 @@ class Agent {
18
18
  // Configure logging
19
19
  logger_1.Logger.setVerbose(this.verbose);
20
20
  logger_1.Logger.setPretty(this.pretty);
21
+ // Register directly provided tool functions if any
22
+ if (config.toolFunctions) {
23
+ for (const [name, func] of Object.entries(config.toolFunctions)) {
24
+ this.registerToolFunction(name, func);
25
+ // Auto-generate tool definition if not already provided
26
+ if (!this.hasToolDefinition(name)) {
27
+ this.addAutoGeneratedToolDefinition(name, func);
28
+ }
29
+ }
30
+ }
21
31
  }
22
32
  createSystemPrompt() {
23
33
  let prompt = this.instructions;
@@ -35,6 +45,68 @@ class Agent {
35
45
  this.toolFunctions[name] = fn;
36
46
  logger_1.Logger.debug(`Registered tool function: ${name}`);
37
47
  }
48
+ /**
49
+ * Check if a tool definition exists for the given function name
50
+ * @param name Function name
51
+ * @returns True if a tool definition exists
52
+ */
53
+ hasToolDefinition(name) {
54
+ if (!this.tools)
55
+ return false;
56
+ return this.tools.some(tool => {
57
+ if (tool.type === 'function' && tool.function) {
58
+ return tool.function.name === name;
59
+ }
60
+ return false;
61
+ });
62
+ }
63
+ /**
64
+ * Auto-generate a tool definition based on the function
65
+ * @param name Function name
66
+ * @param func Function implementation
67
+ */
68
+ addAutoGeneratedToolDefinition(name, func) {
69
+ if (!this.tools) {
70
+ this.tools = [];
71
+ }
72
+ // Extract parameter names from function
73
+ const funcStr = func.toString();
74
+ const paramMatch = funcStr.match(/\(([^)]*)\)/);
75
+ const params = paramMatch ? paramMatch[1].split(',').map(p => p.trim()).filter(p => p) : [];
76
+ // Create a basic tool definition
77
+ const toolDef = {
78
+ type: "function",
79
+ function: {
80
+ name,
81
+ description: `Auto-generated function for ${name}`,
82
+ parameters: {
83
+ type: "object",
84
+ properties: {},
85
+ required: []
86
+ }
87
+ }
88
+ };
89
+ // Add parameters to the definition
90
+ if (params.length > 0) {
91
+ const properties = {};
92
+ const required = [];
93
+ params.forEach(param => {
94
+ // Remove type annotations if present
95
+ const paramName = param.split(':')[0].trim();
96
+ if (paramName) {
97
+ properties[paramName] = {
98
+ type: "string",
99
+ description: `Parameter ${paramName} for function ${name}`
100
+ };
101
+ required.push(paramName);
102
+ }
103
+ });
104
+ toolDef.function.parameters.properties = properties;
105
+ toolDef.function.parameters.required = required;
106
+ }
107
+ this.tools.push(toolDef);
108
+ logger_1.Logger.debug(`Auto-generated tool definition for ${name}`);
109
+ }
38
110
  /**
39
111
  * Process tool calls from the model
40
112
  * @param toolCalls Tool calls from the model
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "praisonai",
3
- "version": "1.0.17",
3
+ "version": "1.0.18",
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.17"
66
66
  },
67
67
  "optionalDependencies": {
68
68
  "boxen": "^7.1.1",