@peebles-group/agentlib-js 1.0.3 → 1.0.4

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peebles-group/agentlib-js",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "A minimal JavaScript library implementing concurrent async agents for illustrating multi-agent systems and other agentic design patterns including recursive ones purely through function calling loops.",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -20,7 +20,7 @@
20
20
  "js-yaml": "^4.1.0",
21
21
  "mongodb": "^6.20.0",
22
22
  "openai": "^5.16.0",
23
- "agentlib-js": "^1.0.0",
23
+ "@peebles-group/agentlib-js": "^1.0.0",
24
24
  "playwright": "^1.55.0",
25
25
  "prompt-sync": "^4.2.0",
26
26
  "sqlite": "^5.1.1",
package/src/Agent.js CHANGED
@@ -3,7 +3,7 @@ import { defaultModel } from "./config.js";
3
3
  import { MCPManager } from "./mcp/MCPManager.js";
4
4
 
5
5
  export class Agent {
6
- constructor(provider, apiKey, {model = defaultModel, tools = [], inputSchema = null, outputSchema = null, enableMCP = false} = {}) {
6
+ constructor(provider, apiKey, {model = defaultModel, tools = [], inputSchema = null, outputSchema = null, enableMCP = false, ...options} = {}) {
7
7
  this.llmService = new LLMService(provider, apiKey);
8
8
  this.model = model;
9
9
  this.nativeTools = tools;
@@ -11,6 +11,7 @@ export class Agent {
11
11
  this.outputSchema = outputSchema;
12
12
  this.mcpManager = enableMCP ? new MCPManager() : null;
13
13
  this.updateSystemPrompt();
14
+ this.options = options;
14
15
  }
15
16
 
16
17
  async addMCPServer(serverName, config) {
@@ -31,10 +32,6 @@ export class Agent {
31
32
  return result;
32
33
  }
33
34
 
34
- /**
35
- * Add a native tool at runtime
36
- * Expected shape: { name: string, description?: string, func: (args) => Promise<any> | any }
37
- */
38
35
  addTool(tool) {
39
36
  if (!tool || typeof tool !== 'object') {
40
37
  throw new Error("Invalid tool: expected an object");
@@ -95,27 +92,29 @@ export class Agent {
95
92
  */
96
93
  async run() {
97
94
  const allTools = this.getAllTools();
95
+ const executed = []
98
96
 
99
97
  // Step 1: send input to model
100
98
  let response = await this.llmService.chat(this.input, {
101
99
  model: this.model,
102
100
  outputSchema: this.outputSchema,
103
101
  tools: allTools,
102
+ ...this.options,
104
103
  });
105
104
 
106
105
  const { output, rawResponse } = response;
107
106
 
108
107
  // Step 2: Clean and add the response to input history
109
- // Remove parsed_arguments (if it exists) from function calls before adding to history
110
- const cleanedOutput = rawResponse.output.map(item => {
111
- if (item.type === "function_call" && item.parsed_arguments) {
112
- const { parsed_arguments, ...cleanItem } = item;
113
- return cleanItem;
108
+ rawResponse.output.forEach(item => {
109
+ if (item.type === "function_call") {
110
+ // Remove parsed_arguments if it exists
111
+ const { parsed_arguments, ...rest } = item;
112
+ const cleanedItem = { ...rest, arguments: JSON.stringify(item.arguments) };
113
+ this.addInput(cleanedItem);
114
+ } else {
115
+ this.addInput(item);
114
116
  }
115
- return item;
116
117
  });
117
-
118
- this.input = this.input.concat(cleanedOutput);
119
118
 
120
119
  // Step 3: collect all function calls
121
120
  const functionCalls = rawResponse.output.filter(item => item.type === "function_call");
@@ -123,12 +122,9 @@ export class Agent {
123
122
  if (functionCalls.length > 0) {
124
123
  for (const call of functionCalls) {
125
124
  let args;
126
- try {
127
- args = JSON.parse(call.arguments);
128
- } catch (err) {
129
- console.error("Failed to parse function call arguments:", call.arguments);
130
- continue;
131
- }
125
+ args = JSON.parse(call.arguments);
126
+ call.arguments = args
127
+ executed.push(call)
132
128
 
133
129
  const tool = allTools.find(t => t.name === call.name);
134
130
  if (!tool || !tool.func) {
@@ -145,7 +141,7 @@ export class Agent {
145
141
  output: JSON.stringify(result),
146
142
  });
147
143
  }
148
-
144
+
149
145
  // Step 6: send updated input back to model for final response
150
146
  response = await this.llmService.chat(this.input, {
151
147
  tools: allTools,
@@ -153,6 +149,7 @@ export class Agent {
153
149
  outputSchema: this.outputSchema,
154
150
  });
155
151
  }
152
+ response.executed = executed;
156
153
  return response;
157
154
  }
158
155
 
package/src/config.js CHANGED
@@ -1 +1 @@
1
- export const defaultModel = 'gpt-4o-mini';
1
+ export const defaultModel = 'gpt-5';