@stackfactor/agent-utils 1.0.1 → 1.0.3

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/README.md CHANGED
@@ -13,7 +13,12 @@ npm install @stackfactor/agent-utils
13
13
  The package exports four modules:
14
14
 
15
15
  ```typescript
16
- import { langChain, logger, errorHandling, constants } from "@stackfactor/agent-utils";
16
+ import {
17
+ langChain,
18
+ logger,
19
+ errorHandling,
20
+ constants,
21
+ } from "@stackfactor/agent-utils";
17
22
  ```
18
23
 
19
24
  ---
@@ -32,18 +37,18 @@ Sends a prompt to an LLM and returns the response. Supports three execution mode
32
37
 
33
38
  When `expectsJsonResponse` is `true` (the default), JSON escape instructions are injected and the response is parsed. If a Zod `schema` is provided, the parsed result is validated.
34
39
 
35
- | Parameter | Type | Default | Description |
36
- |---|---|---|---|
37
- | `modelName` | `string` | — | Model identifier: `"gpt-4o"`, `"claude-3-5-sonnet"`, `"gemini-1.5-pro"`, etc. |
38
- | `config` | `object` | — | API keys (`openAIAPIKey`, `anthropicAPIKey`, `googleAPIKey`), `temperature`, `agentic`, `recursionLimit` |
39
- | `prompt` | `string \| object[]` | — | Plain string or array of `{ role, content }` message objects |
40
- | `onProgressReport` | `function \| null` | `null` | Async callback receiving `{ message, progress }` updates |
41
- | `minPercent` | `number` | `0` | Lower bound for progress percentage |
42
- | `maxPercent` | `number` | `100` | Upper bound for progress percentage |
43
- | `expectsJsonResponse` | `boolean` | `true` | Parse response as JSON |
44
- | `schema` | `ZodSchema \| null` | `null` | Zod schema for response validation |
45
- | `agentName` | `string` | `"StackFactor"` | Display name for the agent (agentic mode) |
46
- | `tools` | `any[]` | `[]` | LangChain tools available to the agent (agentic mode) |
40
+ | Parameter | Type | Default | Description |
41
+ | --------------------- | -------------------- | --------------- | -------------------------------------------------------------------------------------------------------- |
42
+ | `modelName` | `string` | — | Model identifier: `"gpt-4o"`, `"claude-3-5-sonnet"`, `"gemini-1.5-pro"`, etc. |
43
+ | `config` | `object` | — | API keys (`openAIAPIKey`, `anthropicAPIKey`, `googleAPIKey`), `temperature`, `agentic`, `recursionLimit` |
44
+ | `prompt` | `string \| object[]` | — | Plain string or array of `{ role, content }` message objects |
45
+ | `onProgressReport` | `function \| null` | `null` | Async callback receiving `{ message, progress }` updates |
46
+ | `minPercent` | `number` | `0` | Lower bound for progress percentage |
47
+ | `maxPercent` | `number` | `100` | Upper bound for progress percentage |
48
+ | `expectsJsonResponse` | `boolean` | `true` | Parse response as JSON |
49
+ | `schema` | `ZodSchema \| null` | `null` | Zod schema for response validation |
50
+ | `agentName` | `string` | `"StackFactor"` | Display name for the agent (agentic mode) |
51
+ | `tools` | `any[]` | `[]` | LangChain tools available to the agent (agentic mode) |
47
52
 
48
53
  **Returns:** JSON string (when `expectsJsonResponse` is `true`) or raw content string.
49
54
 
@@ -61,12 +66,12 @@ const result = await langChain.runPromptWithModel(
61
66
 
62
67
  Sends a conversational chat prompt to an LLM and returns a plain HTML response. Built for the StackFactor Mentor chat feature — system messages are wrapped with topic-constraint instructions that decline off-topic questions.
63
68
 
64
- | Parameter | Type | Default | Description |
65
- |---|---|---|---|
66
- | `modelName` | `string` | — | Model identifier |
67
- | `config` | `object` | — | API keys and optional `temperature` |
68
- | `prompt` | `string \| object[]` | — | Plain string or array of `{ role, content }` messages |
69
- | `onProgressReport` | `function \| null` | `null` | Streaming progress callback |
69
+ | Parameter | Type | Default | Description |
70
+ | ------------------ | -------------------- | ------- | ----------------------------------------------------- |
71
+ | `modelName` | `string` | — | Model identifier |
72
+ | `config` | `object` | — | API keys and optional `temperature` |
73
+ | `prompt` | `string \| object[]` | — | Plain string or array of `{ role, content }` messages |
74
+ | `onProgressReport` | `function \| null` | `null` | Streaming progress callback |
70
75
 
71
76
  **Returns:** Raw HTML string.
72
77
 
@@ -87,17 +92,17 @@ const html = await langChain.runChatPromptWithModel(
87
92
 
88
93
  Constructs a LangChain agent with a model, system prompt, and tools. When `onReportProgress` is provided, a `report_progress` tool is automatically added.
89
94
 
90
- | Parameter | Type | Default | Description |
91
- |---|---|---|---|
92
- | `name` | `string` | — | Display name for the agent |
93
- | `modelName` | `string` | — | LLM identifier |
94
- | `systemPrompt` | `string` | — | System prompt describing agent behaviour |
95
- | `tools` | `any[]` | `[]` | LangChain tool instances |
96
- | `responseFormat` | `any` | — | Structured response format descriptor |
97
- | `config` | `object` | — | API keys, temperature, etc. |
98
- | `onReportProgress` | `Function \| null` | `null` | Progress callback |
99
- | `minPercent` | `number` | `0` | Minimum reportable progress |
100
- | `maxPercent` | `number` | `100` | Maximum reportable progress |
95
+ | Parameter | Type | Default | Description |
96
+ | ------------------ | ------------------ | ------- | ---------------------------------------- |
97
+ | `name` | `string` | — | Display name for the agent |
98
+ | `modelName` | `string` | — | LLM identifier |
99
+ | `systemPrompt` | `string` | — | System prompt describing agent behaviour |
100
+ | `tools` | `any[]` | `[]` | LangChain tool instances |
101
+ | `responseFormat` | `any` | — | Structured response format descriptor |
102
+ | `config` | `object` | — | API keys, temperature, etc. |
103
+ | `onReportProgress` | `Function \| null` | `null` | Progress callback |
104
+ | `minPercent` | `number` | `0` | Minimum reportable progress |
105
+ | `maxPercent` | `number` | `100` | Maximum reportable progress |
101
106
 
102
107
  **Returns:** A configured LangChain agent instance.
103
108
 
@@ -107,12 +112,12 @@ Constructs a LangChain agent with a model, system prompt, and tools. When `onRep
107
112
 
108
113
  Executes a LangChain agent with a user prompt. Registers callbacks for `tool_start`, `tool_end`, `agent_action`, and error events when `onProgress` is provided. Logs execution time on completion.
109
114
 
110
- | Parameter | Type | Default | Description |
111
- |---|---|---|---|
112
- | `agent` | `any` | — | Agent created by `createAIAgent` |
113
- | `prompt` | `string` | — | User message to send |
114
- | `config` | `object` | — | `recursionLimit` (default: `25`) |
115
- | `onProgress` | `Function \| null` | `null` | Progress event callback |
115
+ | Parameter | Type | Default | Description |
116
+ | ------------ | ------------------ | ------- | -------------------------------- |
117
+ | `agent` | `any` | — | Agent created by `createAIAgent` |
118
+ | `prompt` | `string` | — | User message to send |
119
+ | `config` | `object` | — | `recursionLimit` (default: `25`) |
120
+ | `onProgress` | `Function \| null` | `null` | Progress event callback |
116
121
 
117
122
  **Returns:** Raw response from the agent's `invoke` method.
118
123
 
@@ -126,7 +131,11 @@ const agent = langChain.createAIAgent(
126
131
  { openAIAPIKey: "sk-..." },
127
132
  );
128
133
 
129
- const response = await langChain.runAIAgent(agent, "Summarize this text...", {});
134
+ const response = await langChain.runAIAgent(
135
+ agent,
136
+ "Summarize this text...",
137
+ {},
138
+ );
130
139
  ```
131
140
 
132
141
  ---
@@ -135,12 +144,12 @@ const response = await langChain.runAIAgent(agent, "Summarize this text...", {})
135
144
 
136
145
  Generates an image using OpenAI or Google AI models.
137
146
 
138
- | Parameter | Type | Default | Description |
139
- |---|---|---|---|
140
- | `modelName` | `string` | — | Image model: `"dall-e-3"`, `"gpt-image-1.5"`, `"imagen-4.0-generate-001"`, `"gemini-3.0-pro-image"`, etc. |
141
- | `config` | `object` | — | `openAIAPIKey` or `googleAPIKey` |
142
- | `prompt` | `string` | — | Text prompt describing the image |
143
- | `options` | `object` | `{}` | Provider-specific options (see below) |
147
+ | Parameter | Type | Default | Description |
148
+ | ----------- | -------- | ------- | --------------------------------------------------------------------------------------------------------- |
149
+ | `modelName` | `string` | — | Image model: `"dall-e-3"`, `"gpt-image-1.5"`, `"imagen-4.0-generate-001"`, `"gemini-3.0-pro-image"`, etc. |
150
+ | `config` | `object` | — | `openAIAPIKey` or `googleAPIKey` |
151
+ | `prompt` | `string` | — | Text prompt describing the image |
152
+ | `options` | `object` | `{}` | Provider-specific options (see below) |
144
153
 
145
154
  **OpenAI options:** `size` (`"1024x1024"`, `"1792x1024"`, etc.), `style` (`"vivid"` or `"natural"`), `responseFormat` (`"url"` or `"b64_json"`), `n` (number of images).
146
155
 
@@ -163,8 +172,8 @@ const image = await langChain.runPromptWithModelForImageGeneration(
163
172
 
164
173
  Guards that a response is a non-empty string. Throws an `INTERNAL_SERVER_ERROR` if not.
165
174
 
166
- | Parameter | Type | Description |
167
- |---|---|---|
175
+ | Parameter | Type | Description |
176
+ | ---------- | ----- | ----------------- |
168
177
  | `response` | `any` | Value to validate |
169
178
 
170
179
  **Returns:** The response string if valid.
@@ -179,12 +188,12 @@ GCP-compatible structured logging via Winston with OpenTelemetry trace enrichmen
179
188
 
180
189
  Writes a structured log entry. Automatically enriches with OpenTelemetry `traceId` and `spanId` when an active span exists. Prepends the user's email from the request object when available.
181
190
 
182
- | Parameter | Type | Default | Description |
183
- |---|---|---|---|
184
- | `request` | `any` | — | HTTP request object (reads `request.user.email`), or `null` |
185
- | `level` | `LogLevel` | — | `"error"`, `"warn"`, `"info"`, `"http"`, `"verbose"`, `"debug"`, `"silly"` |
186
- | `message` | `string` | — | Log message |
187
- | `options` | `object` | `{}` | Additional structured fields (`service`, `requestId`, etc.) |
191
+ | Parameter | Type | Default | Description |
192
+ | --------- | ---------- | ------- | -------------------------------------------------------------------------- |
193
+ | `request` | `any` | — | HTTP request object (reads `request.user.email`), or `null` |
194
+ | `level` | `LogLevel` | — | `"error"`, `"warn"`, `"info"`, `"http"`, `"verbose"`, `"debug"`, `"silly"` |
195
+ | `message` | `string` | — | Log message |
196
+ | `options` | `object` | `{}` | Additional structured fields (`service`, `requestId`, etc.) |
188
197
 
189
198
  ```typescript
190
199
  logger.log(req, logger.levels.info, "User signed in", { service: "auth" });
@@ -196,13 +205,13 @@ logger.log(null, logger.levels.error, "Connection failed");
196
205
  Enum-like object mapping level names to their string values:
197
206
 
198
207
  ```typescript
199
- logger.levels.error // "error"
200
- logger.levels.warn // "warn"
201
- logger.levels.info // "info"
202
- logger.levels.http // "http"
203
- logger.levels.verbose // "verbose"
204
- logger.levels.debug // "debug"
205
- logger.levels.silly // "silly"
208
+ logger.levels.error; // "error"
209
+ logger.levels.warn; // "warn"
210
+ logger.levels.info; // "info"
211
+ logger.levels.http; // "http"
212
+ logger.levels.verbose; // "verbose"
213
+ logger.levels.debug; // "debug"
214
+ logger.levels.silly; // "silly"
206
215
  ```
207
216
 
208
217
  ---
@@ -215,11 +224,11 @@ Factory for consistently shaped error payloads.
215
224
 
216
225
  Creates a structured error object with a stack trace.
217
226
 
218
- | Parameter | Type | Default | Description |
219
- |---|---|---|---|
220
- | `errorCode` | `number` | — | HTTP status code or application error code |
221
- | `errorMessage` | `string` | — | Human-readable error description |
222
- | `details` | `any` | `null` | Optional supplementary information |
227
+ | Parameter | Type | Default | Description |
228
+ | -------------- | -------- | ------- | ------------------------------------------ |
229
+ | `errorCode` | `number` | — | HTTP status code or application error code |
230
+ | `errorMessage` | `string` | — | Human-readable error description |
231
+ | `details` | `any` | `null` | Optional supplementary information |
223
232
 
224
233
  **Returns:** `{ code, message, details, stack }`
225
234
 
@@ -236,20 +245,20 @@ Shared constants used across the package.
236
245
 
237
246
  ### `constants.HTTP_CODES`
238
247
 
239
- | Constant | Value |
240
- |---|---|
241
- | `BAD_REQUEST` | `400` |
242
- | `UNPROCESSABLE_ENTITY` | `422` |
248
+ | Constant | Value |
249
+ | ----------------------- | ----- |
250
+ | `BAD_REQUEST` | `400` |
251
+ | `UNPROCESSABLE_ENTITY` | `422` |
243
252
  | `INTERNAL_SERVER_ERROR` | `500` |
244
- | `BAD_GATEWAY` | `502` |
253
+ | `BAD_GATEWAY` | `502` |
245
254
 
246
255
  ### `constants.ERROR`
247
256
 
248
- | Constant | Value |
249
- |---|---|
250
- | `UNABLE_TO_GENERATE_CONTENT` | `"Unable to generate content"` |
251
- | `UNEXPECTED_ERROR` | `"An unexpected error occured..."` |
252
- | `UNSUPPORTED_MODEL` | `"The specified model is not supported"` |
257
+ | Constant | Value |
258
+ | ---------------------------- | ---------------------------------------- |
259
+ | `UNABLE_TO_GENERATE_CONTENT` | `"Unable to generate content"` |
260
+ | `UNEXPECTED_ERROR` | `"An unexpected error occured..."` |
261
+ | `UNSUPPORTED_MODEL` | `"The specified model is not supported"` |
253
262
 
254
263
  ---
255
264
 
@@ -257,18 +266,18 @@ Shared constants used across the package.
257
266
 
258
267
  ### Text / Chat
259
268
 
260
- | Provider | Model Prefix | Example |
261
- |---|---|---|
262
- | OpenAI | `gpt-` | `gpt-4o`, `gpt-4o-mini` |
263
- | Anthropic | `claude-` | `claude-3-5-sonnet`, `claude-3-opus` |
264
- | Google | `gemini-` | `gemini-1.5-pro`, `gemini-2.0-flash` |
269
+ | Provider | Model Prefix | Example |
270
+ | --------- | ------------ | ------------------------------------ |
271
+ | OpenAI | `gpt-` | `gpt-4o`, `gpt-4o-mini` |
272
+ | Anthropic | `claude-` | `claude-3-5-sonnet`, `claude-3-opus` |
273
+ | Google | `gemini-` | `gemini-1.5-pro`, `gemini-2.0-flash` |
265
274
 
266
275
  ### Image Generation
267
276
 
268
- | Provider | Model Prefix | Example |
269
- |---|---|---|
270
- | OpenAI | `dall-e-`, `gpt-image-` | `dall-e-3`, `gpt-image-1.5` |
271
- | Google | `imagen-`, `gemini-` | `imagen-4.0-generate-001`, `gemini-3.0-pro-image` |
277
+ | Provider | Model Prefix | Example |
278
+ | -------- | ----------------------- | ------------------------------------------------- |
279
+ | OpenAI | `dall-e-`, `gpt-image-` | `dall-e-3`, `gpt-image-1.5` |
280
+ | Google | `imagen-`, `gemini-` | `imagen-4.0-generate-001`, `gemini-3.0-pro-image` |
272
281
 
273
282
  ---
274
283
 
@@ -276,15 +285,15 @@ Shared constants used across the package.
276
285
 
277
286
  The `config` object accepted by LangChain methods supports the following keys:
278
287
 
279
- | Key | Type | Description |
280
- |---|---|---|
281
- | `openAIAPIKey` | `string` | OpenAI API key |
282
- | `anthropicAPIKey` | `string` | Anthropic API key |
283
- | `googleAPIKey` | `string` | Google AI API key |
284
- | `temperature` | `number` | Sampling temperature |
285
- | `maxTokens` | `number` | Maximum output tokens (default: `200000`) |
286
- | `agentic` | `boolean` | Enable agentic mode in `runPromptWithModel` |
287
- | `recursionLimit` | `number` | Max agent steps (default: `25`) |
288
+ | Key | Type | Description |
289
+ | ----------------- | --------- | ------------------------------------------- |
290
+ | `openAIAPIKey` | `string` | OpenAI API key |
291
+ | `anthropicAPIKey` | `string` | Anthropic API key |
292
+ | `googleAPIKey` | `string` | Google AI API key |
293
+ | `temperature` | `number` | Sampling temperature |
294
+ | `maxTokens` | `number` | Maximum output tokens (default: `200000`) |
295
+ | `agentic` | `boolean` | Enable agentic mode in `runPromptWithModel` |
296
+ | `recursionLimit` | `number` | Max agent steps (default: `25`) |
288
297
 
289
298
  ---
290
299
 
@@ -1,6 +1,6 @@
1
1
  declare const _default: {
2
- createAIAgent: (name: string, modelName: string, systemPrompt: string, tools: any[], responseFormat: any, config: any, onReportProgress?: Function | null, minPercent?: number, maxPercent?: number) => any;
3
- runAIAgent: (agent: any, prompt: string, config: any, onProgress?: Function | null) => Promise<any>;
2
+ createAgent: (name: string, modelName: string, systemPrompt: string, tools: any[], responseFormat: any, config: any, onReportProgress?: Function | null, minPercent?: number, maxPercent?: number) => any;
3
+ runAgent: (agent: any, prompt: string, config: any, onProgress?: Function | null) => Promise<any>;
4
4
  runChatPromptWithModel: (modelName: string, config: any, prompt: any, onProgressReport: any) => any;
5
5
  runPromptWithModel: (modelName: string, config: any, prompt: any, onProgressReport: any, minPercent?: number, maxPercent?: number, expectsJsonResponse?: boolean, schema?: any, agentName?: string, tools?: any[]) => Promise<any>;
6
6
  runPromptWithModelForImageGeneration: (modelName: string, config: any, prompt: string, options?: any) => Promise<any>;
@@ -1 +1 @@
1
- {"version":3,"file":"langChain.d.ts","sourceRoot":"","sources":["../../src/langChain.ts"],"names":[],"mappings":";0BAoaQ,MAAM,aACD,MAAM,gBACH,MAAM,SACb,GAAG,EAAE,kBACI,GAAG,UACX,GAAG,qBACO,QAAQ,GAAG,IAAI,eACrB,MAAM,eACN,MAAM,KACjB,GAAG;wBAyCG,GAAG,UACF,MAAM,UACN,GAAG,eACC,QAAQ,GAAG,IAAI,KAC1B,OAAO,CAAC,GAAG,CAAC;wCAioBF,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,KACpB,GAAG;oCApfO,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,eACT,MAAM,eACN,MAAM,wBACG,OAAO,WACpB,GAAG,cACA,MAAM,UACV,GAAG,EAAE,KACX,OAAO,CAAC,GAAG,CAAC;sDAyyBF,MAAM,UACT,GAAG,UACH,MAAM,YACL,GAAG,KACX,OAAO,CAAC,GAAG,CAAC;0CAz2B8B,GAAG,KAAG,MAAM;;AAo6BzD,wBAOE"}
1
+ {"version":3,"file":"langChain.d.ts","sourceRoot":"","sources":["../../src/langChain.ts"],"names":[],"mappings":";wBAoaQ,MAAM,aACD,MAAM,gBACH,MAAM,SACb,GAAG,EAAE,kBACI,GAAG,UACX,GAAG,qBACO,QAAQ,GAAG,IAAI,eACrB,MAAM,eACN,MAAM,KACjB,GAAG;sBAyCG,GAAG,UACF,MAAM,UACN,GAAG,eACC,QAAQ,GAAG,IAAI,KAC1B,OAAO,CAAC,GAAG,CAAC;wCAioBF,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,KACpB,GAAG;oCApfO,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,eACT,MAAM,eACN,MAAM,wBACG,OAAO,WACpB,GAAG,cACA,MAAM,UACV,GAAG,EAAE,KACX,OAAO,CAAC,GAAG,CAAC;sDAyyBF,MAAM,UACT,GAAG,UACH,MAAM,YACL,GAAG,KACX,OAAO,CAAC,GAAG,CAAC;0CAz2B8B,GAAG,KAAG,MAAM;;AAo6BzD,wBAOE"}
@@ -9,7 +9,7 @@ const google_genai_1 = require("@langchain/google-genai");
9
9
  const openai_2 = require("openai");
10
10
  const genai_1 = require("@google/genai");
11
11
  const const_js_1 = __importDefault(require("./const.js"));
12
- const langchain_1 = require("langchain");
12
+ const langchain_1 = __importDefault(require("langchain"));
13
13
  const errorHandling_js_1 = __importDefault(require("./errorHandling.js"));
14
14
  const logger_js_1 = __importDefault(require("./logger.js"));
15
15
  const zod_1 = require("zod");
@@ -264,7 +264,7 @@ const safeJsonParse = (line) => {
264
264
  * report; defaults to `100`
265
265
  * @returns A LangChain tool instance configured with a Zod schema for `{ stage, message, percent }`
266
266
  */
267
- const getAIProgressTool = (onProgress, minPercent = 0, maxPercent = 100) => langchain_1.tool(async ({ stage, message, percent }) => {
267
+ const getAIProgressTool = (onProgress, minPercent = 0, maxPercent = 100) => langchain_1.default.tool(async ({ stage, message, percent }) => {
268
268
  try {
269
269
  // Clamp percent to be within minPercent and maxPercent bounds
270
270
  const rawPct = typeof percent === "number" ? percent : 0;
@@ -387,7 +387,7 @@ const getLLMModel = (modelName, config, schema = null) => {
387
387
  * defaults to `100`
388
388
  * @returns A configured LangChain agent instance ready to be run with `runAIAgent`
389
389
  */
390
- const createAIAgent = (name, modelName, systemPrompt, tools = [], responseFormat, config, onReportProgress = null, minPercent = 0, maxPercent = 100) => {
390
+ const createAgent = (name, modelName, systemPrompt, tools = [], responseFormat, config, onReportProgress = null, minPercent = 0, maxPercent = 100) => {
391
391
  //Prepare the complete system prompt with progress reporting instructions if needed
392
392
  const completeSystemPrompt = `
393
393
  ${systemPrompt}
@@ -396,7 +396,7 @@ const createAIAgent = (name, modelName, systemPrompt, tools = [], responseFormat
396
396
  : ""}
397
397
  `.trim();
398
398
  // Create the agent with the specified model, system prompt, tools, and response format
399
- const agent = (0, langchain_1.createAgent)({
399
+ const agent = langchain_1.default.createAgent({
400
400
  name: name,
401
401
  model: getLLMModel(modelName, config),
402
402
  systemPrompt: completeSystemPrompt,
@@ -421,7 +421,7 @@ const createAIAgent = (name, modelName, systemPrompt, tools = [], responseFormat
421
421
  * agent execution
422
422
  * @returns The raw response object returned by the agent's `invoke` method
423
423
  */
424
- const runAIAgent = async (agent, prompt, config, onProgress = null) => {
424
+ const runAgent = async (agent, prompt, config, onProgress = null) => {
425
425
  const startTime = Date.now();
426
426
  // Build callbacks for progress reporting if onProgress is provided
427
427
  // const agentDisplayName = `${agent.options?.name} AI Agent`;
@@ -592,14 +592,14 @@ const runPromptWithModel = async (modelName, config, prompt, onProgressReport, m
592
592
  agentTools.push(getAIProgressTool(trackingProgressCallback, minPercent, maxPercent));
593
593
  }
594
594
  // Create the agent with tools
595
- const agent = createAIAgent(agentName, modelName, systemPrompt, agentTools, null, // responseFormat
595
+ const agent = createAgent(agentName, modelName, systemPrompt, agentTools, null, // responseFormat
596
596
  config, null, // onReportProgress handled via tools array
597
597
  minPercent, maxPercent);
598
598
  // Run the agent with callback that includes current progress
599
599
  const callbackWithProgress = onProgressReport
600
600
  ? (data) => onProgressReport({ ...data, progress: progressTracker.current })
601
601
  : null;
602
- const response = await runAIAgent(agent, userPrompt, config, callbackWithProgress);
602
+ const response = await runAgent(agent, userPrompt, config, callbackWithProgress);
603
603
  // Extract content from agent response
604
604
  const messages = response?.messages || [];
605
605
  if (messages.length === 0) {
@@ -1232,8 +1232,8 @@ const runPromptWithModelForImageGeneration = async (modelName, config, prompt, o
1232
1232
  }
1233
1233
  };
1234
1234
  exports.default = {
1235
- createAIAgent,
1236
- runAIAgent,
1235
+ createAgent,
1236
+ runAgent,
1237
1237
  runChatPromptWithModel,
1238
1238
  runPromptWithModel,
1239
1239
  runPromptWithModelForImageGeneration,
@@ -1,6 +1,6 @@
1
1
  declare const _default: {
2
- createAIAgent: (name: string, modelName: string, systemPrompt: string, tools: any[], responseFormat: any, config: any, onReportProgress?: Function | null, minPercent?: number, maxPercent?: number) => any;
3
- runAIAgent: (agent: any, prompt: string, config: any, onProgress?: Function | null) => Promise<any>;
2
+ createAgent: (name: string, modelName: string, systemPrompt: string, tools: any[], responseFormat: any, config: any, onReportProgress?: Function | null, minPercent?: number, maxPercent?: number) => any;
3
+ runAgent: (agent: any, prompt: string, config: any, onProgress?: Function | null) => Promise<any>;
4
4
  runChatPromptWithModel: (modelName: string, config: any, prompt: any, onProgressReport: any) => any;
5
5
  runPromptWithModel: (modelName: string, config: any, prompt: any, onProgressReport: any, minPercent?: number, maxPercent?: number, expectsJsonResponse?: boolean, schema?: any, agentName?: string, tools?: any[]) => Promise<any>;
6
6
  runPromptWithModelForImageGeneration: (modelName: string, config: any, prompt: string, options?: any) => Promise<any>;
@@ -1 +1 @@
1
- {"version":3,"file":"langChain.d.ts","sourceRoot":"","sources":["../../src/langChain.ts"],"names":[],"mappings":";0BAoaQ,MAAM,aACD,MAAM,gBACH,MAAM,SACb,GAAG,EAAE,kBACI,GAAG,UACX,GAAG,qBACO,QAAQ,GAAG,IAAI,eACrB,MAAM,eACN,MAAM,KACjB,GAAG;wBAyCG,GAAG,UACF,MAAM,UACN,GAAG,eACC,QAAQ,GAAG,IAAI,KAC1B,OAAO,CAAC,GAAG,CAAC;wCAioBF,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,KACpB,GAAG;oCApfO,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,eACT,MAAM,eACN,MAAM,wBACG,OAAO,WACpB,GAAG,cACA,MAAM,UACV,GAAG,EAAE,KACX,OAAO,CAAC,GAAG,CAAC;sDAyyBF,MAAM,UACT,GAAG,UACH,MAAM,YACL,GAAG,KACX,OAAO,CAAC,GAAG,CAAC;0CAz2B8B,GAAG,KAAG,MAAM;;AAo6BzD,wBAOE"}
1
+ {"version":3,"file":"langChain.d.ts","sourceRoot":"","sources":["../../src/langChain.ts"],"names":[],"mappings":";wBAoaQ,MAAM,aACD,MAAM,gBACH,MAAM,SACb,GAAG,EAAE,kBACI,GAAG,UACX,GAAG,qBACO,QAAQ,GAAG,IAAI,eACrB,MAAM,eACN,MAAM,KACjB,GAAG;sBAyCG,GAAG,UACF,MAAM,UACN,GAAG,eACC,QAAQ,GAAG,IAAI,KAC1B,OAAO,CAAC,GAAG,CAAC;wCAioBF,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,KACpB,GAAG;oCApfO,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,eACT,MAAM,eACN,MAAM,wBACG,OAAO,WACpB,GAAG,cACA,MAAM,UACV,GAAG,EAAE,KACX,OAAO,CAAC,GAAG,CAAC;sDAyyBF,MAAM,UACT,GAAG,UACH,MAAM,YACL,GAAG,KACX,OAAO,CAAC,GAAG,CAAC;0CAz2B8B,GAAG,KAAG,MAAM;;AAo6BzD,wBAOE"}
@@ -4,7 +4,7 @@ import { ChatGoogleGenerativeAI } from "@langchain/google-genai";
4
4
  import { OpenAI } from "openai";
5
5
  import { GoogleGenAI } from "@google/genai";
6
6
  import constants from "./const.js";
7
- import { createAgent, tool } from "langchain";
7
+ import langChain from "langchain";
8
8
  import errorHandlingHelper from "./errorHandling.js";
9
9
  import logger from "./logger.js";
10
10
  import { z } from "zod";
@@ -259,7 +259,7 @@ const safeJsonParse = (line) => {
259
259
  * report; defaults to `100`
260
260
  * @returns A LangChain tool instance configured with a Zod schema for `{ stage, message, percent }`
261
261
  */
262
- const getAIProgressTool = (onProgress, minPercent = 0, maxPercent = 100) => tool(async ({ stage, message, percent }) => {
262
+ const getAIProgressTool = (onProgress, minPercent = 0, maxPercent = 100) => langChain.tool(async ({ stage, message, percent }) => {
263
263
  try {
264
264
  // Clamp percent to be within minPercent and maxPercent bounds
265
265
  const rawPct = typeof percent === "number" ? percent : 0;
@@ -382,7 +382,7 @@ const getLLMModel = (modelName, config, schema = null) => {
382
382
  * defaults to `100`
383
383
  * @returns A configured LangChain agent instance ready to be run with `runAIAgent`
384
384
  */
385
- const createAIAgent = (name, modelName, systemPrompt, tools = [], responseFormat, config, onReportProgress = null, minPercent = 0, maxPercent = 100) => {
385
+ const createAgent = (name, modelName, systemPrompt, tools = [], responseFormat, config, onReportProgress = null, minPercent = 0, maxPercent = 100) => {
386
386
  //Prepare the complete system prompt with progress reporting instructions if needed
387
387
  const completeSystemPrompt = `
388
388
  ${systemPrompt}
@@ -391,7 +391,7 @@ const createAIAgent = (name, modelName, systemPrompt, tools = [], responseFormat
391
391
  : ""}
392
392
  `.trim();
393
393
  // Create the agent with the specified model, system prompt, tools, and response format
394
- const agent = createAgent({
394
+ const agent = langChain.createAgent({
395
395
  name: name,
396
396
  model: getLLMModel(modelName, config),
397
397
  systemPrompt: completeSystemPrompt,
@@ -416,7 +416,7 @@ const createAIAgent = (name, modelName, systemPrompt, tools = [], responseFormat
416
416
  * agent execution
417
417
  * @returns The raw response object returned by the agent's `invoke` method
418
418
  */
419
- const runAIAgent = async (agent, prompt, config, onProgress = null) => {
419
+ const runAgent = async (agent, prompt, config, onProgress = null) => {
420
420
  const startTime = Date.now();
421
421
  // Build callbacks for progress reporting if onProgress is provided
422
422
  // const agentDisplayName = `${agent.options?.name} AI Agent`;
@@ -587,14 +587,14 @@ const runPromptWithModel = async (modelName, config, prompt, onProgressReport, m
587
587
  agentTools.push(getAIProgressTool(trackingProgressCallback, minPercent, maxPercent));
588
588
  }
589
589
  // Create the agent with tools
590
- const agent = createAIAgent(agentName, modelName, systemPrompt, agentTools, null, // responseFormat
590
+ const agent = createAgent(agentName, modelName, systemPrompt, agentTools, null, // responseFormat
591
591
  config, null, // onReportProgress handled via tools array
592
592
  minPercent, maxPercent);
593
593
  // Run the agent with callback that includes current progress
594
594
  const callbackWithProgress = onProgressReport
595
595
  ? (data) => onProgressReport({ ...data, progress: progressTracker.current })
596
596
  : null;
597
- const response = await runAIAgent(agent, userPrompt, config, callbackWithProgress);
597
+ const response = await runAgent(agent, userPrompt, config, callbackWithProgress);
598
598
  // Extract content from agent response
599
599
  const messages = response?.messages || [];
600
600
  if (messages.length === 0) {
@@ -1227,8 +1227,8 @@ const runPromptWithModelForImageGeneration = async (modelName, config, prompt, o
1227
1227
  }
1228
1228
  };
1229
1229
  export default {
1230
- createAIAgent,
1231
- runAIAgent,
1230
+ createAgent,
1231
+ runAgent,
1232
1232
  runChatPromptWithModel,
1233
1233
  runPromptWithModel,
1234
1234
  runPromptWithModelForImageGeneration,
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "restricted"
5
5
  },
6
- "version": "1.0.1",
6
+ "version": "1.0.3",
7
7
  "description": "",
8
8
  "main": "dist/cjs/index.js",
9
9
  "module": "dist/esm/index.js",