@stackfactor/agent-utils 1.13.0 → 1.13.1
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 +3 -1
- package/dist/cjs/langChain.d.ts.map +1 -1
- package/dist/cjs/langChain.js +31 -2
- package/dist/esm/langChain.d.ts.map +1 -1
- package/dist/esm/langChain.js +31 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -103,7 +103,9 @@ Constructs a LangChain agent with a model, system prompt, and tools. When `onRep
|
|
|
103
103
|
|
|
104
104
|
### `langChain.runAIAgent(agent, prompt, config, onProgress?)`
|
|
105
105
|
|
|
106
|
-
Executes a LangChain agent with a user prompt. Registers callbacks for `tool_start`, `
|
|
106
|
+
Executes a LangChain agent with a user prompt. Registers callbacks for `tool_start`, `agent_action`, and error events when `onProgress` is provided. Logs execution time on completion.
|
|
107
|
+
|
|
108
|
+
A tool event's `message` is plain language for the progress bar: the web tools read "Searching the web", "Reading web pages", "Listing the pages of a site" and "Reading the pages of a site", and any other tool reads as its name in words (`lookup_record` → "Using lookup record"). It never carries the model's reasoning or the tool's input; the raw name and input stay on the event's `tool` and `input`.
|
|
107
109
|
|
|
108
110
|
| Parameter | Type | Default | Description |
|
|
109
111
|
| ------------ | ------------------ | ------- | -------------------------------- |
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"langChain.d.ts","sourceRoot":"","sources":["../../src/langChain.ts"],"names":[],"mappings":"AAoGA,KAAK,UAAU,GAAG;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IAKtB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IACvC;;;;;OAKG;IACH,gBAAgB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B/C,MAAM,aACD,MAAM,gBACH,MAAM,SACb,GAAG,EAAE,kBACI,GAAG,UACX,GAAG,iBACG,YAAY,GAAG,IAAI,KAChC,GAAG;sBAiEG,GAAG,UACF,MAAM,UACN,GAAG,eACC,QAAQ,GAAG,IAAI,iBACb,YAAY,GAAG,IAAI,aACvB,MAAM,KACf,OAAO,CAAC,GAAG,CAAC;oCAohBF,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,eACT,MAAM,eACN,MAAM,wBACG,OAAO,WACpB,GAAG,cACA,MAAM,UACV,GAAG,EAAE,iBACE,YAAY,GAAG,IAAI,KAChC,OAAO,CAAC,GAAG,CAAC;sDA2sBF,MAAM,UACT,GAAG,UACH,MAAM,YACL,GAAG,iBACE,YAAY,GAAG,IAAI,KAChC,OAAO,CAAC,GAAG,CAAC;sDAmTF,MAAM,UACT,GAAG,UACH,MAAM,YACL,GAAG,iBACE,YAAY,GAAG,IAAI,KAChC,OAAO,CAAC,GAAG,CAAC;0CAz6C8B,GAAG,KAAG,MAAM;uCAt0B9C,YAAY,GAAG,IAAI,GAAG,SAAS,aAC7B,MAAM,YACP,GAAG,WACJ,GAAG,YACF,QAAQ,GAAG,QAAQ,KAC5B,IAAI;kCA5CI,YAAY,GAAG,IAAI,GAAG,SAAS,aAC7B,MAAM,SACV,UAAU,GAAG,IAAI,YACd,GAAG,KACZ,IAAI;+CA0FI,YAAY,GAAG,IAAI,GAAG,SAAS,aAC7B,MAAM,kBACD,MAAM,YACZ,GAAG,KACZ,IAAI;uCAoBI,YAAY,GAAG,IAAI,GAAG,SAAS,aAC7B,MAAM,WACR,MAAM,YACL,GAAG,KACZ,IAAI;mCAuwBU,MAAM,mBACJ,MAAM,EAAE,KACxB,MAAM;;AA48CT,wBAkBE"}
|
package/dist/cjs/langChain.js
CHANGED
|
@@ -765,10 +765,36 @@ const createAgent = (name, modelName, systemPrompt, tools = [], responseFormat,
|
|
|
765
765
|
});
|
|
766
766
|
return agent;
|
|
767
767
|
};
|
|
768
|
+
// What the progress bar says while each tool agent-utils registers (the
|
|
769
|
+
// Tavily tools in tavily.ts) runs. A Map, so a tool named after an
|
|
770
|
+
// Object.prototype key ("constructor") is not mistaken for a label.
|
|
771
|
+
const TOOL_PROGRESS_LABELS = new Map([
|
|
772
|
+
["web_search", "Searching the web"],
|
|
773
|
+
["web_extract", "Reading web pages"],
|
|
774
|
+
["web_map", "Listing the pages of a site"],
|
|
775
|
+
["web_crawl", "Reading the pages of a site"],
|
|
776
|
+
]);
|
|
777
|
+
/**
|
|
778
|
+
* The progress message for a tool call, in words the person watching the run
|
|
779
|
+
* can read. A tool without a label (an agent's own) reads as its name with
|
|
780
|
+
* underscores as spaces: `lookup_record` → "Using lookup record".
|
|
781
|
+
* @param name - The tool's registered name
|
|
782
|
+
* @returns A plain-language message; never the raw name in quotes
|
|
783
|
+
*/
|
|
784
|
+
const toolProgressLabel = (name) => {
|
|
785
|
+
const text = String(name ?? "");
|
|
786
|
+
const label = TOOL_PROGRESS_LABELS.get(text);
|
|
787
|
+
if (label)
|
|
788
|
+
return label;
|
|
789
|
+
const words = text.replace(/_+/g, " ").trim();
|
|
790
|
+
return words ? `Using ${words}` : "Using a tool";
|
|
791
|
+
};
|
|
768
792
|
/**
|
|
769
793
|
* Executes a LangChain agent with a single user prompt and returns the raw agent
|
|
770
794
|
* response. When an `onProgress` callback is provided, LangChain callbacks are
|
|
771
795
|
* registered to forward `tool_start`, `agent_action`, and error events to the caller.
|
|
796
|
+
* A tool event's `message` is plain language (see `toolProgressLabel`); the raw tool
|
|
797
|
+
* name and input stay on its `tool` and `input` fields.
|
|
772
798
|
* Execution time is logged at the info level on completion.
|
|
773
799
|
* @param agent - A LangChain agent instance created by `createAgent`
|
|
774
800
|
* @param prompt - The user message string to send to the agent
|
|
@@ -798,15 +824,18 @@ const runAgent = async (agent, prompt, config, onProgress = null, usageTracker =
|
|
|
798
824
|
if (name)
|
|
799
825
|
onProgress({
|
|
800
826
|
type: "tool_start",
|
|
801
|
-
message:
|
|
827
|
+
message: toolProgressLabel(name),
|
|
802
828
|
tool: name,
|
|
803
829
|
progress,
|
|
804
830
|
});
|
|
805
831
|
},
|
|
832
|
+
// `action.log` is the model's own text (LangChain's default reads
|
|
833
|
+
// "Invoking: `web_extract` with `{...}`", the raw tool input), so it
|
|
834
|
+
// never reaches the progress bar.
|
|
806
835
|
handleAgentAction: (action) => {
|
|
807
836
|
onProgress({
|
|
808
837
|
type: "agent_action",
|
|
809
|
-
message: action.
|
|
838
|
+
message: toolProgressLabel(action.tool),
|
|
810
839
|
tool: action.tool,
|
|
811
840
|
input: action.toolInput,
|
|
812
841
|
progress,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"langChain.d.ts","sourceRoot":"","sources":["../../src/langChain.ts"],"names":[],"mappings":"AAoGA,KAAK,UAAU,GAAG;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IAKtB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IACvC;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACrD;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B,CAAC;AA0iBF;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,eAAO,MAAM,WAAW,GACtB,WAAW,MAAM,EACjB,QAAQ,GAAG,EACX,SAAQ,GAAU,KACjB,GAwHF,CAAC;;
|
|
1
|
+
{"version":3,"file":"langChain.d.ts","sourceRoot":"","sources":["../../src/langChain.ts"],"names":[],"mappings":"AAoGA,KAAK,UAAU,GAAG;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A2sBF,MAAM,UACT,GAAG,UACH,MAAM,YACL,GAAG,iBACE,YAAY,GAAG,IAAI,KAChC,OAAO,CAAC,GAAG,CAAC;sDAmTF,MAAM,UACT,GAAG,UACH,MAAM,YACL,GAAG,iBACE,YAAY,GAAG,IAAI,KAChC,OAAO,CAAC,GAAG,CAAC;0CAz6C8B,GAAG,KAAG,MAAM;uCAt0B9C,YAAY,GAAG,IAAI,GAAG,SAAS,aAC7B,MAAM,YACP,GAAG,WACJ,GAAG,YACF,QAAQ,GAAG,QAAQ,KAC5B,IAAI;kCA5CI,YAAY,GAAG,IAAI,GAAG,SAAS,aAC7B,MAAM,SACV,UAAU,GAAG,IAAI,YACd,GAAG,KACZ,IAAI;+CA0FI,YAAY,GAAG,IAAI,GAAG,SAAS,aAC7B,MAAM,kBACD,MAAM,YACZ,GAAG,KACZ,IAAI;uCAoBI,YAAY,GAAG,IAAI,GAAG,SAAS,aAC7B,MAAM,WACR,MAAM,YACL,GAAG,KACZ,IAAI;mCAuwBU,MAAM,mBACJ,MAAM,EAAE,KACxB,MAAM;;AA48CT,wBAkBE"}
|
package/dist/esm/langChain.js
CHANGED
|
@@ -758,10 +758,36 @@ const createAgent = (name, modelName, systemPrompt, tools = [], responseFormat,
|
|
|
758
758
|
});
|
|
759
759
|
return agent;
|
|
760
760
|
};
|
|
761
|
+
// What the progress bar says while each tool agent-utils registers (the
|
|
762
|
+
// Tavily tools in tavily.ts) runs. A Map, so a tool named after an
|
|
763
|
+
// Object.prototype key ("constructor") is not mistaken for a label.
|
|
764
|
+
const TOOL_PROGRESS_LABELS = new Map([
|
|
765
|
+
["web_search", "Searching the web"],
|
|
766
|
+
["web_extract", "Reading web pages"],
|
|
767
|
+
["web_map", "Listing the pages of a site"],
|
|
768
|
+
["web_crawl", "Reading the pages of a site"],
|
|
769
|
+
]);
|
|
770
|
+
/**
|
|
771
|
+
* The progress message for a tool call, in words the person watching the run
|
|
772
|
+
* can read. A tool without a label (an agent's own) reads as its name with
|
|
773
|
+
* underscores as spaces: `lookup_record` → "Using lookup record".
|
|
774
|
+
* @param name - The tool's registered name
|
|
775
|
+
* @returns A plain-language message; never the raw name in quotes
|
|
776
|
+
*/
|
|
777
|
+
const toolProgressLabel = (name) => {
|
|
778
|
+
const text = String(name ?? "");
|
|
779
|
+
const label = TOOL_PROGRESS_LABELS.get(text);
|
|
780
|
+
if (label)
|
|
781
|
+
return label;
|
|
782
|
+
const words = text.replace(/_+/g, " ").trim();
|
|
783
|
+
return words ? `Using ${words}` : "Using a tool";
|
|
784
|
+
};
|
|
761
785
|
/**
|
|
762
786
|
* Executes a LangChain agent with a single user prompt and returns the raw agent
|
|
763
787
|
* response. When an `onProgress` callback is provided, LangChain callbacks are
|
|
764
788
|
* registered to forward `tool_start`, `agent_action`, and error events to the caller.
|
|
789
|
+
* A tool event's `message` is plain language (see `toolProgressLabel`); the raw tool
|
|
790
|
+
* name and input stay on its `tool` and `input` fields.
|
|
765
791
|
* Execution time is logged at the info level on completion.
|
|
766
792
|
* @param agent - A LangChain agent instance created by `createAgent`
|
|
767
793
|
* @param prompt - The user message string to send to the agent
|
|
@@ -791,15 +817,18 @@ const runAgent = async (agent, prompt, config, onProgress = null, usageTracker =
|
|
|
791
817
|
if (name)
|
|
792
818
|
onProgress({
|
|
793
819
|
type: "tool_start",
|
|
794
|
-
message:
|
|
820
|
+
message: toolProgressLabel(name),
|
|
795
821
|
tool: name,
|
|
796
822
|
progress,
|
|
797
823
|
});
|
|
798
824
|
},
|
|
825
|
+
// `action.log` is the model's own text (LangChain's default reads
|
|
826
|
+
// "Invoking: `web_extract` with `{...}`", the raw tool input), so it
|
|
827
|
+
// never reaches the progress bar.
|
|
799
828
|
handleAgentAction: (action) => {
|
|
800
829
|
onProgress({
|
|
801
830
|
type: "agent_action",
|
|
802
|
-
message: action.
|
|
831
|
+
message: toolProgressLabel(action.tool),
|
|
803
832
|
tool: action.tool,
|
|
804
833
|
input: action.toolInput,
|
|
805
834
|
progress,
|