langchain 0.1.3 → 0.1.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.
Files changed (33) hide show
  1. package/dist/agents/toolkits/conversational_retrieval/tool.cjs +2 -2
  2. package/dist/agents/toolkits/conversational_retrieval/tool.d.ts +1 -1
  3. package/dist/agents/toolkits/conversational_retrieval/tool.js +1 -1
  4. package/dist/agents/toolkits/openapi/openapi.cjs +2 -2
  5. package/dist/agents/toolkits/openapi/openapi.js +1 -1
  6. package/dist/chains/openai_functions/base.d.ts +1 -1
  7. package/dist/chains/openai_functions/openapi.d.ts +1 -1
  8. package/dist/chains/openai_functions/structured_output.cjs +2 -0
  9. package/dist/chains/openai_functions/structured_output.d.ts +3 -1
  10. package/dist/chains/openai_functions/structured_output.js +2 -0
  11. package/dist/document_transformers/openai_functions.d.ts +1 -1
  12. package/dist/document_transformers/openai_functions.js +1 -1
  13. package/dist/experimental/hubs/makersuite/googlemakersuitehub.d.ts +2 -1
  14. package/dist/experimental/plan_and_execute/agent_executor.d.ts +1 -2
  15. package/dist/experimental/plan_and_execute/prompt.d.ts +1 -2
  16. package/dist/output_parsers/index.cjs +2 -1
  17. package/dist/output_parsers/index.d.ts +1 -1
  18. package/dist/output_parsers/index.js +1 -1
  19. package/dist/output_parsers/openai_functions.d.ts +1 -1
  20. package/dist/output_parsers/openai_tools.cjs +86 -8
  21. package/dist/output_parsers/openai_tools.d.ts +31 -2
  22. package/dist/output_parsers/openai_tools.js +84 -7
  23. package/dist/output_parsers/structured.js +1 -1
  24. package/dist/runnables/remote.cjs +177 -73
  25. package/dist/runnables/remote.d.ts +2 -0
  26. package/dist/runnables/remote.js +178 -74
  27. package/dist/tools/chain.cjs +3 -2
  28. package/dist/tools/chain.d.ts +3 -1
  29. package/dist/tools/chain.js +2 -1
  30. package/dist/tools/retriever.cjs +2 -2
  31. package/dist/tools/retriever.d.ts +1 -1
  32. package/dist/tools/retriever.js +1 -1
  33. package/package.json +5 -5
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createRetrieverTool = void 0;
4
4
  const zod_1 = require("zod");
5
- const dynamic_1 = require("@langchain/community/tools/dynamic");
5
+ const tools_1 = require("@langchain/core/tools");
6
6
  const document_js_1 = require("../../../util/document.cjs");
7
7
  /** @deprecated Use "langchain/tools/retriever" instead. */
8
8
  function createRetrieverTool(retriever, input) {
@@ -15,6 +15,6 @@ function createRetrieverTool(retriever, input) {
15
15
  .string()
16
16
  .describe("Natural language query used as input to the retriever"),
17
17
  });
18
- return new dynamic_1.DynamicStructuredTool({ ...input, func, schema });
18
+ return new tools_1.DynamicStructuredTool({ ...input, func, schema });
19
19
  }
20
20
  exports.createRetrieverTool = createRetrieverTool;
@@ -1,6 +1,6 @@
1
1
  import type { BaseRetrieverInterface } from "@langchain/core/retrievers";
2
2
  import { z } from "zod";
3
- import { DynamicStructuredTool, DynamicStructuredToolInput } from "@langchain/community/tools/dynamic";
3
+ import { DynamicStructuredTool, DynamicStructuredToolInput } from "@langchain/core/tools";
4
4
  /** @deprecated Use "langchain/tools/retriever" instead. */
5
5
  export declare function createRetrieverTool(retriever: BaseRetrieverInterface, input: Omit<DynamicStructuredToolInput, "func" | "schema">): DynamicStructuredTool<z.ZodObject<{
6
6
  input: z.ZodString;
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { DynamicStructuredTool, } from "@langchain/community/tools/dynamic";
2
+ import { DynamicStructuredTool, } from "@langchain/core/tools";
3
3
  import { formatDocumentsAsString } from "../../../util/document.js";
4
4
  /** @deprecated Use "langchain/tools/retriever" instead. */
5
5
  export function createRetrieverTool(retriever, input) {
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createOpenApiAgent = exports.OpenApiToolkit = exports.RequestsToolkit = void 0;
4
- const dynamic_1 = require("@langchain/community/tools/dynamic");
4
+ const tools_1 = require("@langchain/core/tools");
5
5
  const base_1 = require("@langchain/community/agents/toolkits/base");
6
6
  const executor_js_1 = require("../../executor.cjs");
7
7
  const prompt_js_1 = require("./prompt.cjs");
@@ -56,7 +56,7 @@ class OpenApiToolkit extends RequestsToolkit {
56
56
  const jsonAgent = (0, json_js_1.createJsonAgent)(llm, new json_js_1.JsonToolkit(jsonSpec));
57
57
  this.tools = [
58
58
  ...this.tools,
59
- new dynamic_1.DynamicTool({
59
+ new tools_1.DynamicTool({
60
60
  name: "json_explorer",
61
61
  func: async (input) => {
62
62
  const result = await jsonAgent.call({ input });
@@ -1,4 +1,4 @@
1
- import { DynamicTool } from "@langchain/community/tools/dynamic";
1
+ import { DynamicTool } from "@langchain/core/tools";
2
2
  import { Toolkit } from "@langchain/community/agents/toolkits/base";
3
3
  import { AgentExecutor } from "../../executor.js";
4
4
  import { OPENAPI_PREFIX, OPENAPI_SUFFIX, JSON_EXPLORER_DESCRIPTION, } from "./prompt.js";
@@ -1,5 +1,5 @@
1
1
  import type { z } from "zod";
2
- import { JsonSchema7Type } from "zod-to-json-schema/src/parseDef.js";
2
+ import { JsonSchema7Type } from "zod-to-json-schema";
3
3
  import type { BaseOutputParser } from "@langchain/core/output_parsers";
4
4
  import type { BasePromptTemplate } from "@langchain/core/prompts";
5
5
  import type { RunnableInterface } from "@langchain/core/runnables";
@@ -1,4 +1,4 @@
1
- import { JsonSchema7Type } from "zod-to-json-schema/src/parseDef.js";
1
+ import { JsonSchema7Type } from "zod-to-json-schema";
2
2
  import type { OpenAPIV3_1 } from "openapi-types";
3
3
  import { BaseChatModel } from "@langchain/core/language_models/chat_models";
4
4
  import { BaseFunctionCallOptions } from "@langchain/core/language_models/base";
@@ -102,6 +102,7 @@ class FunctionCallStructuredOutputParser extends output_parsers_1.BaseLLMOutputP
102
102
  }
103
103
  exports.FunctionCallStructuredOutputParser = FunctionCallStructuredOutputParser;
104
104
  /**
105
+ * @deprecated Use {@link https://api.js.langchain.com/functions/langchain_chains_openai_functions.createStructuredOutputRunnable.html | createStructuredOutputRunnable} instead
105
106
  * Create a chain that returns output matching a JSON Schema.
106
107
  * @param input Object that includes all LLMChainInput fields except "outputParser"
107
108
  * as well as an additional required "outputSchema" JSON Schema object.
@@ -137,6 +138,7 @@ function createStructuredOutputChain(input) {
137
138
  });
138
139
  }
139
140
  exports.createStructuredOutputChain = createStructuredOutputChain;
141
+ /** @deprecated Use {@link https://api.js.langchain.com/functions/langchain_chains_openai_functions.createStructuredOutputRunnable.html | createStructuredOutputRunnable} instead */
140
142
  function createStructuredOutputChainFromZod(zodSchema, input) {
141
143
  return createStructuredOutputChain({
142
144
  ...input,
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { JsonSchema7Type } from "zod-to-json-schema/src/parseDef.js";
2
+ import { JsonSchema7Type } from "zod-to-json-schema";
3
3
  import { Validator } from "@langchain/core/utils/json_schema";
4
4
  import { ChatOpenAI } from "@langchain/openai";
5
5
  import { BasePromptTemplate } from "@langchain/core/prompts";
@@ -49,10 +49,12 @@ export declare class FunctionCallStructuredOutputParser<T extends z.AnyZodObject
49
49
  parseResult(generations: ChatGeneration[]): Promise<any>;
50
50
  }
51
51
  /**
52
+ * @deprecated Use {@link https://api.js.langchain.com/functions/langchain_chains_openai_functions.createStructuredOutputRunnable.html | createStructuredOutputRunnable} instead
52
53
  * Create a chain that returns output matching a JSON Schema.
53
54
  * @param input Object that includes all LLMChainInput fields except "outputParser"
54
55
  * as well as an additional required "outputSchema" JSON Schema object.
55
56
  * @returns OpenAPIChain
56
57
  */
57
58
  export declare function createStructuredOutputChain<T extends z.AnyZodObject = z.AnyZodObject>(input: StructuredOutputChainInput<T>): LLMChain<any, BaseChatModel<BaseFunctionCallOptions> | ChatOpenAI<BaseFunctionCallOptions>>;
59
+ /** @deprecated Use {@link https://api.js.langchain.com/functions/langchain_chains_openai_functions.createStructuredOutputRunnable.html | createStructuredOutputRunnable} instead */
58
60
  export declare function createStructuredOutputChainFromZod<T extends z.AnyZodObject>(zodSchema: T, input: Omit<StructuredOutputChainInput<T>, "outputSchema">): LLMChain<any, BaseChatModel<BaseFunctionCallOptions> | ChatOpenAI<BaseFunctionCallOptions>>;
@@ -98,6 +98,7 @@ export class FunctionCallStructuredOutputParser extends BaseLLMOutputParser {
98
98
  }
99
99
  }
100
100
  /**
101
+ * @deprecated Use {@link https://api.js.langchain.com/functions/langchain_chains_openai_functions.createStructuredOutputRunnable.html | createStructuredOutputRunnable} instead
101
102
  * Create a chain that returns output matching a JSON Schema.
102
103
  * @param input Object that includes all LLMChainInput fields except "outputParser"
103
104
  * as well as an additional required "outputSchema" JSON Schema object.
@@ -132,6 +133,7 @@ export function createStructuredOutputChain(input) {
132
133
  ...rest,
133
134
  });
134
135
  }
136
+ /** @deprecated Use {@link https://api.js.langchain.com/functions/langchain_chains_openai_functions.createStructuredOutputRunnable.html | createStructuredOutputRunnable} instead */
135
137
  export function createStructuredOutputChainFromZod(zodSchema, input) {
136
138
  return createStructuredOutputChain({
137
139
  ...input,
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import type { JsonSchema7ObjectType } from "zod-to-json-schema/src/parsers/object.js";
2
+ import { type JsonSchema7ObjectType } from "zod-to-json-schema";
3
3
  import { Document, MappingDocumentTransformer } from "@langchain/core/documents";
4
4
  import { ChatOpenAI } from "@langchain/openai";
5
5
  import { BaseChain } from "../chains/base.js";
@@ -1,4 +1,4 @@
1
- import { zodToJsonSchema } from "zod-to-json-schema";
1
+ import { zodToJsonSchema, } from "zod-to-json-schema";
2
2
  import { Document, MappingDocumentTransformer, } from "@langchain/core/documents";
3
3
  import { ChatOpenAI } from "@langchain/openai";
4
4
  import { createTaggingChain, } from "../chains/openai_functions/index.js";
@@ -2,6 +2,7 @@ import type { protos } from "@google-ai/generativelanguage";
2
2
  import type { google } from "@google-ai/generativelanguage/build/protos/protos.js";
3
3
  import { GoogleAuthOptions } from "google-auth-library";
4
4
  import type { BaseLanguageModel } from "@langchain/core/language_models/base";
5
+ import { Runnable } from "@langchain/core/runnables";
5
6
  import { PromptTemplate } from "@langchain/core/prompts";
6
7
  import { AsyncCaller, AsyncCallerCallOptions } from "@langchain/core/utils/async_caller";
7
8
  import { GoogleAbstractedClientOpsMethod, GoogleResponse, GoogleVertexAIConnectionParams } from "../../../types/googlevertexai-types.js";
@@ -118,7 +119,7 @@ export declare class MakerSuitePrompt {
118
119
  * will have the parameters (model name, temperature, etc) from those in
119
120
  * MakerSuite.
120
121
  */
121
- toChain(): import("@langchain/core/runnables").RunnableSequence<any, any>;
122
+ toChain(): Runnable<any, any, import("@langchain/core/runnables").RunnableConfig>;
122
123
  }
123
124
  interface DriveFileReadParams extends GoogleVertexAIConnectionParams<GoogleAuthOptions> {
124
125
  fileId: string;
@@ -1,8 +1,7 @@
1
1
  import type { BaseLanguageModelInterface } from "@langchain/core/language_models/base";
2
2
  import { ChainValues } from "@langchain/core/utils/types";
3
- import { Tool } from "@langchain/core/tools";
3
+ import { Tool, DynamicStructuredTool } from "@langchain/core/tools";
4
4
  import { CallbackManagerForChainRun } from "@langchain/core/callbacks/manager";
5
- import { DynamicStructuredTool } from "@langchain/community/tools/dynamic";
6
5
  import { BaseChain, ChainInputs } from "../../chains/base.js";
7
6
  import { BasePlanner, BaseStepContainer, BaseStepExecutor, LLMPlanner, ChainStepExecutor } from "./base.js";
8
7
  import { SerializedLLMChain } from "../../chains/serde.js";
@@ -1,6 +1,5 @@
1
1
  import { ChatPromptTemplate } from "@langchain/core/prompts";
2
- import { Tool } from "@langchain/core/tools";
3
- import { DynamicStructuredTool } from "@langchain/community/tools/dynamic";
2
+ import { Tool, DynamicStructuredTool } from "@langchain/core/tools";
4
3
  export declare const PLANNER_SYSTEM_PROMPT_MESSAGE_TEMPLATE: string;
5
4
  export declare const DEFAULT_STEP_EXECUTOR_HUMAN_CHAT_MESSAGE_TEMPLATE = "Previous steps: {previous_steps}\n\nCurrent objective: {current_step}\n\n{agent_scratchpad}\n\nYou may extract and combine relevant data from your previous steps when responding to me.";
6
5
  /**
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DatetimeOutputParser = exports.HttpResponseOutputParser = exports.JsonOutputToolsParser = exports.JsonKeyOutputFunctionsParser = exports.JsonOutputFunctionsParser = exports.OutputFunctionsParser = exports.CustomListOutputParser = exports.RouterOutputParser = exports.CombiningOutputParser = exports.OutputFixingParser = exports.JsonMarkdownStructuredOutputParser = exports.AsymmetricStructuredOutputParser = exports.StructuredOutputParser = exports.RegexParser = exports.CommaSeparatedListOutputParser = exports.ListOutputParser = void 0;
3
+ exports.DatetimeOutputParser = exports.HttpResponseOutputParser = exports.JsonOutputKeyToolsParser = exports.JsonOutputToolsParser = exports.JsonKeyOutputFunctionsParser = exports.JsonOutputFunctionsParser = exports.OutputFunctionsParser = exports.CustomListOutputParser = exports.RouterOutputParser = exports.CombiningOutputParser = exports.OutputFixingParser = exports.JsonMarkdownStructuredOutputParser = exports.AsymmetricStructuredOutputParser = exports.StructuredOutputParser = exports.RegexParser = exports.CommaSeparatedListOutputParser = exports.ListOutputParser = void 0;
4
4
  var list_js_1 = require("./list.cjs");
5
5
  Object.defineProperty(exports, "ListOutputParser", { enumerable: true, get: function () { return list_js_1.ListOutputParser; } });
6
6
  Object.defineProperty(exports, "CommaSeparatedListOutputParser", { enumerable: true, get: function () { return list_js_1.CommaSeparatedListOutputParser; } });
@@ -24,6 +24,7 @@ Object.defineProperty(exports, "JsonOutputFunctionsParser", { enumerable: true,
24
24
  Object.defineProperty(exports, "JsonKeyOutputFunctionsParser", { enumerable: true, get: function () { return openai_functions_js_1.JsonKeyOutputFunctionsParser; } });
25
25
  var openai_tools_js_1 = require("../output_parsers/openai_tools.cjs");
26
26
  Object.defineProperty(exports, "JsonOutputToolsParser", { enumerable: true, get: function () { return openai_tools_js_1.JsonOutputToolsParser; } });
27
+ Object.defineProperty(exports, "JsonOutputKeyToolsParser", { enumerable: true, get: function () { return openai_tools_js_1.JsonOutputKeyToolsParser; } });
27
28
  var http_response_js_1 = require("./http_response.cjs");
28
29
  Object.defineProperty(exports, "HttpResponseOutputParser", { enumerable: true, get: function () { return http_response_js_1.HttpResponseOutputParser; } });
29
30
  var datetime_js_1 = require("./datetime.cjs");
@@ -6,6 +6,6 @@ export { CombiningOutputParser } from "./combining.js";
6
6
  export { RouterOutputParser, type RouterOutputParserInput } from "./router.js";
7
7
  export { CustomListOutputParser } from "./list.js";
8
8
  export { type FunctionParameters, OutputFunctionsParser, JsonOutputFunctionsParser, JsonKeyOutputFunctionsParser, } from "../output_parsers/openai_functions.js";
9
- export { type ParsedToolCall, JsonOutputToolsParser, } from "../output_parsers/openai_tools.js";
9
+ export { type ParsedToolCall, JsonOutputToolsParser, type JsonOutputToolsParserParams, JsonOutputKeyToolsParser, type JsonOutputKeyToolsParserParams, } from "../output_parsers/openai_tools.js";
10
10
  export { HttpResponseOutputParser, type HttpResponseOutputParserInput, } from "./http_response.js";
11
11
  export { DatetimeOutputParser } from "./datetime.js";
@@ -6,6 +6,6 @@ export { CombiningOutputParser } from "./combining.js";
6
6
  export { RouterOutputParser } from "./router.js";
7
7
  export { CustomListOutputParser } from "./list.js";
8
8
  export { OutputFunctionsParser, JsonOutputFunctionsParser, JsonKeyOutputFunctionsParser, } from "../output_parsers/openai_functions.js";
9
- export { JsonOutputToolsParser, } from "../output_parsers/openai_tools.js";
9
+ export { JsonOutputToolsParser, JsonOutputKeyToolsParser, } from "../output_parsers/openai_tools.js";
10
10
  export { HttpResponseOutputParser, } from "./http_response.js";
11
11
  export { DatetimeOutputParser } from "./datetime.js";
@@ -1,4 +1,4 @@
1
- import { JsonSchema7ObjectType } from "zod-to-json-schema/src/parsers/object.js";
1
+ import { JsonSchema7ObjectType } from "zod-to-json-schema";
2
2
  import { type Operation as JSONPatchOperation } from "@langchain/core/utils/json_patch";
3
3
  import { ChatGeneration, Generation } from "@langchain/core/outputs";
4
4
  import { BaseCumulativeTransformOutputParser, type BaseCumulativeTransformOutputParserInput, BaseLLMOutputParser } from "@langchain/core/output_parsers";
@@ -1,14 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.JsonOutputToolsParser = void 0;
3
+ exports.JsonOutputKeyToolsParser = exports.JsonOutputToolsParser = void 0;
4
4
  const output_parsers_1 = require("@langchain/core/output_parsers");
5
5
  /**
6
- * Class for parsing the output of an LLM into a JSON object. Uses an
7
- * instance of `OutputToolsParser` to parse the output.
6
+ * Class for parsing the output of a tool-calling LLM into a JSON object.
8
7
  */
9
8
  class JsonOutputToolsParser extends output_parsers_1.BaseLLMOutputParser {
10
- constructor() {
11
- super(...arguments);
9
+ static lc_name() {
10
+ return "JsonOutputToolsParser";
11
+ }
12
+ constructor(fields) {
13
+ super(fields);
14
+ Object.defineProperty(this, "returnId", {
15
+ enumerable: true,
16
+ configurable: true,
17
+ writable: true,
18
+ value: false
19
+ });
12
20
  Object.defineProperty(this, "lc_namespace", {
13
21
  enumerable: true,
14
22
  configurable: true,
@@ -21,9 +29,7 @@ class JsonOutputToolsParser extends output_parsers_1.BaseLLMOutputParser {
21
29
  writable: true,
22
30
  value: true
23
31
  });
24
- }
25
- static lc_name() {
26
- return "JsonOutputToolsParser";
32
+ this.returnId = fields?.returnId ?? this.returnId;
27
33
  }
28
34
  /**
29
35
  * Parses the output and returns a JSON object. If `argsOnly` is true,
@@ -45,6 +51,9 @@ class JsonOutputToolsParser extends output_parsers_1.BaseLLMOutputParser {
45
51
  type: toolCall.function.name,
46
52
  args: JSON.parse(toolCall.function.arguments),
47
53
  };
54
+ if (this.returnId) {
55
+ parsedToolCall.id = toolCall.id;
56
+ }
48
57
  // backward-compatibility with previous
49
58
  // versions of Langchain JS, which uses `name` and `arguments`
50
59
  Object.defineProperty(parsedToolCall, "name", {
@@ -64,3 +73,72 @@ class JsonOutputToolsParser extends output_parsers_1.BaseLLMOutputParser {
64
73
  }
65
74
  }
66
75
  exports.JsonOutputToolsParser = JsonOutputToolsParser;
76
+ /**
77
+ * Class for parsing the output of a tool-calling LLM into a JSON object if you are
78
+ * expecting only a single tool to be called.
79
+ */
80
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
81
+ class JsonOutputKeyToolsParser extends output_parsers_1.BaseLLMOutputParser {
82
+ static lc_name() {
83
+ return "JsonOutputKeyToolsParser";
84
+ }
85
+ constructor(params) {
86
+ super(params);
87
+ Object.defineProperty(this, "lc_namespace", {
88
+ enumerable: true,
89
+ configurable: true,
90
+ writable: true,
91
+ value: ["langchain", "output_parsers", "openai_tools"]
92
+ });
93
+ Object.defineProperty(this, "lc_serializable", {
94
+ enumerable: true,
95
+ configurable: true,
96
+ writable: true,
97
+ value: true
98
+ });
99
+ Object.defineProperty(this, "returnId", {
100
+ enumerable: true,
101
+ configurable: true,
102
+ writable: true,
103
+ value: false
104
+ });
105
+ /** The type of tool calls to return. */
106
+ Object.defineProperty(this, "keyName", {
107
+ enumerable: true,
108
+ configurable: true,
109
+ writable: true,
110
+ value: void 0
111
+ });
112
+ /** Whether to return only the first tool call. */
113
+ Object.defineProperty(this, "returnSingle", {
114
+ enumerable: true,
115
+ configurable: true,
116
+ writable: true,
117
+ value: false
118
+ });
119
+ Object.defineProperty(this, "initialParser", {
120
+ enumerable: true,
121
+ configurable: true,
122
+ writable: true,
123
+ value: void 0
124
+ });
125
+ this.keyName = params.keyName;
126
+ this.returnSingle = params.returnSingle ?? this.returnSingle;
127
+ this.initialParser = new JsonOutputToolsParser(params);
128
+ }
129
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
130
+ async parseResult(generations) {
131
+ const results = await this.initialParser.parseResult(generations);
132
+ const matchingResults = results.filter((result) => result.type === this.keyName);
133
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
134
+ let returnedValues = matchingResults;
135
+ if (!this.returnId) {
136
+ returnedValues = matchingResults.map((result) => result.args);
137
+ }
138
+ if (this.returnSingle) {
139
+ return returnedValues[0];
140
+ }
141
+ return returnedValues;
142
+ }
143
+ }
144
+ exports.JsonOutputKeyToolsParser = JsonOutputKeyToolsParser;
@@ -1,6 +1,7 @@
1
1
  import { BaseLLMOutputParser } from "@langchain/core/output_parsers";
2
2
  import type { ChatGeneration } from "@langchain/core/outputs";
3
3
  export type ParsedToolCall = {
4
+ id?: string;
4
5
  type: string;
5
6
  args: Record<string, any>;
6
7
  /** @deprecated Use `type` instead. Will be removed in 0.2.0. */
@@ -8,14 +9,19 @@ export type ParsedToolCall = {
8
9
  /** @deprecated Use `args` instead. Will be removed in 0.2.0. */
9
10
  arguments: Record<string, any>;
10
11
  };
12
+ export type JsonOutputToolsParserParams = {
13
+ /** Whether to return the tool call id. */
14
+ returnId?: boolean;
15
+ };
11
16
  /**
12
- * Class for parsing the output of an LLM into a JSON object. Uses an
13
- * instance of `OutputToolsParser` to parse the output.
17
+ * Class for parsing the output of a tool-calling LLM into a JSON object.
14
18
  */
15
19
  export declare class JsonOutputToolsParser extends BaseLLMOutputParser<ParsedToolCall[]> {
16
20
  static lc_name(): string;
21
+ returnId: boolean;
17
22
  lc_namespace: string[];
18
23
  lc_serializable: boolean;
24
+ constructor(fields?: JsonOutputToolsParserParams);
19
25
  /**
20
26
  * Parses the output and returns a JSON object. If `argsOnly` is true,
21
27
  * only the arguments of the function call are returned.
@@ -24,3 +30,26 @@ export declare class JsonOutputToolsParser extends BaseLLMOutputParser<ParsedToo
24
30
  */
25
31
  parseResult(generations: ChatGeneration[]): Promise<ParsedToolCall[]>;
26
32
  }
33
+ export type JsonOutputKeyToolsParserParams = {
34
+ keyName: string;
35
+ returnSingle?: boolean;
36
+ /** Whether to return the tool call id. */
37
+ returnId?: boolean;
38
+ };
39
+ /**
40
+ * Class for parsing the output of a tool-calling LLM into a JSON object if you are
41
+ * expecting only a single tool to be called.
42
+ */
43
+ export declare class JsonOutputKeyToolsParser extends BaseLLMOutputParser<any> {
44
+ static lc_name(): string;
45
+ lc_namespace: string[];
46
+ lc_serializable: boolean;
47
+ returnId: boolean;
48
+ /** The type of tool calls to return. */
49
+ keyName: string;
50
+ /** Whether to return only the first tool call. */
51
+ returnSingle: boolean;
52
+ initialParser: JsonOutputToolsParser;
53
+ constructor(params: JsonOutputKeyToolsParserParams);
54
+ parseResult(generations: ChatGeneration[]): Promise<any>;
55
+ }
@@ -1,11 +1,19 @@
1
1
  import { BaseLLMOutputParser } from "@langchain/core/output_parsers";
2
2
  /**
3
- * Class for parsing the output of an LLM into a JSON object. Uses an
4
- * instance of `OutputToolsParser` to parse the output.
3
+ * Class for parsing the output of a tool-calling LLM into a JSON object.
5
4
  */
6
5
  export class JsonOutputToolsParser extends BaseLLMOutputParser {
7
- constructor() {
8
- super(...arguments);
6
+ static lc_name() {
7
+ return "JsonOutputToolsParser";
8
+ }
9
+ constructor(fields) {
10
+ super(fields);
11
+ Object.defineProperty(this, "returnId", {
12
+ enumerable: true,
13
+ configurable: true,
14
+ writable: true,
15
+ value: false
16
+ });
9
17
  Object.defineProperty(this, "lc_namespace", {
10
18
  enumerable: true,
11
19
  configurable: true,
@@ -18,9 +26,7 @@ export class JsonOutputToolsParser extends BaseLLMOutputParser {
18
26
  writable: true,
19
27
  value: true
20
28
  });
21
- }
22
- static lc_name() {
23
- return "JsonOutputToolsParser";
29
+ this.returnId = fields?.returnId ?? this.returnId;
24
30
  }
25
31
  /**
26
32
  * Parses the output and returns a JSON object. If `argsOnly` is true,
@@ -42,6 +48,9 @@ export class JsonOutputToolsParser extends BaseLLMOutputParser {
42
48
  type: toolCall.function.name,
43
49
  args: JSON.parse(toolCall.function.arguments),
44
50
  };
51
+ if (this.returnId) {
52
+ parsedToolCall.id = toolCall.id;
53
+ }
45
54
  // backward-compatibility with previous
46
55
  // versions of Langchain JS, which uses `name` and `arguments`
47
56
  Object.defineProperty(parsedToolCall, "name", {
@@ -60,3 +69,71 @@ export class JsonOutputToolsParser extends BaseLLMOutputParser {
60
69
  return parsedToolCalls;
61
70
  }
62
71
  }
72
+ /**
73
+ * Class for parsing the output of a tool-calling LLM into a JSON object if you are
74
+ * expecting only a single tool to be called.
75
+ */
76
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
77
+ export class JsonOutputKeyToolsParser extends BaseLLMOutputParser {
78
+ static lc_name() {
79
+ return "JsonOutputKeyToolsParser";
80
+ }
81
+ constructor(params) {
82
+ super(params);
83
+ Object.defineProperty(this, "lc_namespace", {
84
+ enumerable: true,
85
+ configurable: true,
86
+ writable: true,
87
+ value: ["langchain", "output_parsers", "openai_tools"]
88
+ });
89
+ Object.defineProperty(this, "lc_serializable", {
90
+ enumerable: true,
91
+ configurable: true,
92
+ writable: true,
93
+ value: true
94
+ });
95
+ Object.defineProperty(this, "returnId", {
96
+ enumerable: true,
97
+ configurable: true,
98
+ writable: true,
99
+ value: false
100
+ });
101
+ /** The type of tool calls to return. */
102
+ Object.defineProperty(this, "keyName", {
103
+ enumerable: true,
104
+ configurable: true,
105
+ writable: true,
106
+ value: void 0
107
+ });
108
+ /** Whether to return only the first tool call. */
109
+ Object.defineProperty(this, "returnSingle", {
110
+ enumerable: true,
111
+ configurable: true,
112
+ writable: true,
113
+ value: false
114
+ });
115
+ Object.defineProperty(this, "initialParser", {
116
+ enumerable: true,
117
+ configurable: true,
118
+ writable: true,
119
+ value: void 0
120
+ });
121
+ this.keyName = params.keyName;
122
+ this.returnSingle = params.returnSingle ?? this.returnSingle;
123
+ this.initialParser = new JsonOutputToolsParser(params);
124
+ }
125
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
126
+ async parseResult(generations) {
127
+ const results = await this.initialParser.parseResult(generations);
128
+ const matchingResults = results.filter((result) => result.type === this.keyName);
129
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
130
+ let returnedValues = matchingResults;
131
+ if (!this.returnId) {
132
+ returnedValues = matchingResults.map((result) => result.args);
133
+ }
134
+ if (this.returnSingle) {
135
+ return returnedValues[0];
136
+ }
137
+ return returnedValues;
138
+ }
139
+ }
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { zodToJsonSchema } from "zod-to-json-schema";
2
+ import { zodToJsonSchema, } from "zod-to-json-schema";
3
3
  import { BaseOutputParser, OutputParserException, } from "@langchain/core/output_parsers";
4
4
  export class StructuredOutputParser extends BaseOutputParser {
5
5
  static lc_name() {
@@ -4,7 +4,9 @@ exports.RemoteRunnable = void 0;
4
4
  const runnables_1 = require("@langchain/core/runnables");
5
5
  const documents_1 = require("@langchain/core/documents");
6
6
  const prompt_values_1 = require("@langchain/core/prompt_values");
7
+ const log_stream_1 = require("@langchain/core/tracers/log_stream");
7
8
  const messages_1 = require("@langchain/core/messages");
9
+ const outputs_1 = require("@langchain/core/outputs");
8
10
  const event_source_parse_1 = require("@langchain/community/utils/event_source_parse");
9
11
  const stream_1 = require("@langchain/core/utils/stream");
10
12
  function isSuperset(set, subset) {
@@ -20,94 +22,153 @@ function revive(obj) {
20
22
  if (Array.isArray(obj))
21
23
  return obj.map(revive);
22
24
  if (typeof obj === "object") {
25
+ // eslint-disable-next-line no-instanceof/no-instanceof
26
+ if (!obj || obj instanceof Date) {
27
+ return obj;
28
+ }
23
29
  const keysArr = Object.keys(obj);
24
30
  const keys = new Set(keysArr);
25
- if (isSuperset(keys, new Set(["page_content", "metadata"])))
31
+ if (isSuperset(keys, new Set(["page_content", "metadata"]))) {
26
32
  return new documents_1.Document({
27
33
  pageContent: obj.page_content,
28
34
  metadata: obj.metadata,
29
35
  });
30
- if (isSuperset(keys, new Set(["content", "type", "is_chunk"]))) {
31
- if (!obj.is_chunk) {
32
- if (obj.type === "human") {
33
- return new messages_1.HumanMessage({
34
- content: obj.content,
35
- });
36
- }
37
- if (obj.type === "system") {
38
- return new messages_1.SystemMessage({
39
- content: obj.content,
40
- });
41
- }
42
- if (obj.type === "chat") {
43
- return new messages_1.ChatMessage({
44
- content: obj.content,
45
- role: obj.role,
46
- });
47
- }
48
- if (obj.type === "function") {
49
- return new messages_1.FunctionMessage({
50
- content: obj.content,
51
- name: obj.name,
52
- });
53
- }
54
- if (obj.type === "tool") {
55
- return new messages_1.ToolMessage({
56
- content: obj.content,
57
- tool_call_id: obj.tool_call_id,
58
- });
59
- }
60
- if (obj.type === "ai") {
61
- return new messages_1.AIMessage({
62
- content: obj.content,
63
- });
64
- }
65
- }
66
- else {
67
- if (obj.type === "human") {
68
- return new messages_1.HumanMessageChunk({
69
- content: obj.content,
70
- });
71
- }
72
- if (obj.type === "system") {
73
- return new messages_1.SystemMessageChunk({
74
- content: obj.content,
75
- });
76
- }
77
- if (obj.type === "chat") {
78
- return new messages_1.ChatMessageChunk({
79
- content: obj.content,
80
- role: obj.role,
81
- });
82
- }
83
- if (obj.type === "function") {
84
- return new messages_1.FunctionMessageChunk({
85
- content: obj.content,
86
- name: obj.name,
87
- });
88
- }
89
- if (obj.type === "tool") {
90
- return new messages_1.ToolMessageChunk({
91
- content: obj.content,
92
- tool_call_id: obj.tool_call_id,
93
- });
94
- }
95
- if (obj.type === "ai") {
96
- return new messages_1.AIMessageChunk({
97
- content: obj.content,
98
- });
99
- }
36
+ }
37
+ if (isSuperset(keys, new Set(["content", "type", "additional_kwargs"]))) {
38
+ if (obj.type === "HumanMessage" || obj.type === "human") {
39
+ return new messages_1.HumanMessage({
40
+ content: obj.content,
41
+ });
42
+ }
43
+ if (obj.type === "SystemMessage" || obj.type === "system") {
44
+ return new messages_1.SystemMessage({
45
+ content: obj.content,
46
+ });
47
+ }
48
+ if (obj.type === "ChatMessage" || obj.type === "chat") {
49
+ return new messages_1.ChatMessage({
50
+ content: obj.content,
51
+ role: obj.role,
52
+ });
53
+ }
54
+ if (obj.type === "FunctionMessage" || obj.type === "function") {
55
+ return new messages_1.FunctionMessage({
56
+ content: obj.content,
57
+ name: obj.name,
58
+ });
59
+ }
60
+ if (obj.type === "ToolMessage" || obj.type === "tool") {
61
+ return new messages_1.ToolMessage({
62
+ content: obj.content,
63
+ tool_call_id: obj.tool_call_id,
64
+ });
65
+ }
66
+ if (obj.type === "AIMessage" || obj.type === "ai") {
67
+ return new messages_1.AIMessage({
68
+ content: obj.content,
69
+ });
70
+ }
71
+ if (obj.type === "HumanMessageChunk") {
72
+ return new messages_1.HumanMessageChunk({
73
+ content: obj.content,
74
+ });
75
+ }
76
+ if (obj.type === "SystemMessageChunk") {
77
+ return new messages_1.SystemMessageChunk({
78
+ content: obj.content,
79
+ });
80
+ }
81
+ if (obj.type === "ChatMessageChunk") {
82
+ return new messages_1.ChatMessageChunk({
83
+ content: obj.content,
84
+ role: obj.role,
85
+ });
86
+ }
87
+ if (obj.type === "FunctionMessageChunk") {
88
+ return new messages_1.FunctionMessageChunk({
89
+ content: obj.content,
90
+ name: obj.name,
91
+ });
92
+ }
93
+ if (obj.type === "ToolMessageChunk") {
94
+ return new messages_1.ToolMessageChunk({
95
+ content: obj.content,
96
+ tool_call_id: obj.tool_call_id,
97
+ });
98
+ }
99
+ if (obj.type === "AIMessageChunk") {
100
+ return new messages_1.AIMessageChunk({
101
+ content: obj.content,
102
+ });
100
103
  }
101
104
  }
102
- if (isSuperset(keys, new Set(["text"]))) {
103
- return new prompt_values_1.StringPromptValue(obj.text);
105
+ if (isSuperset(keys, new Set(["text", "generation_info", "type"]))) {
106
+ if (obj.type === "ChatGenerationChunk") {
107
+ return new outputs_1.ChatGenerationChunk({
108
+ message: revive(obj.message),
109
+ text: obj.text,
110
+ generationInfo: obj.generation_info,
111
+ });
112
+ }
113
+ else if (obj.type === "ChatGeneration") {
114
+ return {
115
+ message: revive(obj.message),
116
+ text: obj.text,
117
+ generationInfo: obj.generation_info,
118
+ };
119
+ }
120
+ else if (obj.type === "GenerationChunk") {
121
+ return new outputs_1.GenerationChunk({
122
+ text: obj.text,
123
+ generationInfo: obj.generation_info,
124
+ });
125
+ }
126
+ else if (obj.type === "Generation") {
127
+ return {
128
+ text: obj.text,
129
+ generationInfo: obj.generation_info,
130
+ };
131
+ }
132
+ }
133
+ if (isSuperset(keys, new Set(["tool", "tool_input", "log", "type"]))) {
134
+ if (obj.type === "AgentAction") {
135
+ return {
136
+ tool: obj.tool,
137
+ toolInput: obj.tool_input,
138
+ log: obj.log,
139
+ };
140
+ }
141
+ }
142
+ if (isSuperset(keys, new Set(["return_values", "log", "type"]))) {
143
+ if (obj.type === "AgentFinish") {
144
+ return {
145
+ returnValues: obj.return_values,
146
+ log: obj.log,
147
+ };
148
+ }
149
+ }
150
+ if (isSuperset(keys, new Set(["generations", "run", "type"]))) {
151
+ if (obj.type === "LLMResult") {
152
+ return {
153
+ generations: revive(obj.generations),
154
+ llmOutput: obj.llm_output,
155
+ [outputs_1.RUN_KEY]: obj.run,
156
+ };
157
+ }
104
158
  }
105
159
  if (isSuperset(keys, new Set(["messages"]))) {
160
+ // TODO: Start checking for type: ChatPromptValue and ChatPromptValueConcrete
161
+ // when LangServe bug is fixed
106
162
  return new prompt_values_1.ChatPromptValue({
107
163
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
108
164
  messages: obj.messages.map((msg) => revive(msg)),
109
165
  });
110
166
  }
167
+ if (isSuperset(keys, new Set(["text"]))) {
168
+ // TODO: Start checking for type: StringPromptValue
169
+ // when LangServe bug is fixed
170
+ return new prompt_values_1.StringPromptValue(obj.text);
171
+ }
111
172
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
112
173
  const innerRevive = (key) => [
113
174
  key,
@@ -232,5 +293,48 @@ class RemoteRunnable extends runnables_1.Runnable {
232
293
  });
233
294
  return stream_1.IterableReadableStream.fromReadableStream(stream);
234
295
  }
296
+ async *streamLog(input, options, streamOptions) {
297
+ const [config, kwargs] = this._separateRunnableConfigFromCallOptions(options);
298
+ const stream = new log_stream_1.LogStreamCallbackHandler({
299
+ ...streamOptions,
300
+ autoClose: false,
301
+ });
302
+ const { callbacks } = config;
303
+ if (callbacks === undefined) {
304
+ config.callbacks = [stream];
305
+ }
306
+ else if (Array.isArray(callbacks)) {
307
+ config.callbacks = callbacks.concat([stream]);
308
+ }
309
+ else {
310
+ const copiedCallbacks = callbacks.copy();
311
+ copiedCallbacks.inheritableHandlers.push(stream);
312
+ config.callbacks = copiedCallbacks;
313
+ }
314
+ // The type is in camelCase but the API only accepts snake_case.
315
+ const camelCaseStreamOptions = {
316
+ include_names: streamOptions?.includeNames,
317
+ include_types: streamOptions?.includeTypes,
318
+ include_tags: streamOptions?.includeTags,
319
+ exclude_names: streamOptions?.excludeNames,
320
+ exclude_types: streamOptions?.excludeTypes,
321
+ exclude_tags: streamOptions?.excludeTags,
322
+ };
323
+ const response = await this.post("/stream_log", {
324
+ input,
325
+ config,
326
+ kwargs,
327
+ ...camelCaseStreamOptions,
328
+ diff: false,
329
+ });
330
+ const { body } = response;
331
+ if (!body) {
332
+ throw new Error("Could not begin remote stream log. Please check the given URL and try again.");
333
+ }
334
+ const runnableStream = (0, event_source_parse_1.convertEventStreamToIterableReadableDataStream)(body);
335
+ for await (const log of runnableStream) {
336
+ yield revive(JSON.parse(log));
337
+ }
338
+ }
235
339
  }
236
340
  exports.RemoteRunnable = RemoteRunnable;
@@ -1,5 +1,6 @@
1
1
  import { Runnable, RunnableBatchOptions, RunnableConfig } from "@langchain/core/runnables";
2
2
  import { CallbackManagerForChainRun } from "@langchain/core/callbacks/manager";
3
+ import { type LogStreamCallbackHandlerInput, type RunLogPatch } from "@langchain/core/tracers/log_stream";
3
4
  import { IterableReadableStream } from "@langchain/core/utils/stream";
4
5
  type RemoteRunnableOptions = {
5
6
  timeout?: number;
@@ -23,5 +24,6 @@ export declare class RemoteRunnable<RunInput, RunOutput, CallOptions extends Run
23
24
  }): Promise<(RunOutput | Error)[]>;
24
25
  batch(inputs: RunInput[], options?: Partial<CallOptions> | Partial<CallOptions>[], batchOptions?: RunnableBatchOptions): Promise<(RunOutput | Error)[]>;
25
26
  stream(input: RunInput, options?: Partial<CallOptions>): Promise<IterableReadableStream<RunOutput>>;
27
+ streamLog(input: RunInput, options?: Partial<CallOptions>, streamOptions?: Omit<LogStreamCallbackHandlerInput, "autoClose">): AsyncGenerator<RunLogPatch>;
26
28
  }
27
29
  export {};
@@ -1,8 +1,10 @@
1
1
  import { Runnable, } from "@langchain/core/runnables";
2
2
  import { Document } from "@langchain/core/documents";
3
3
  import { ChatPromptValue, StringPromptValue, } from "@langchain/core/prompt_values";
4
+ import { LogStreamCallbackHandler, } from "@langchain/core/tracers/log_stream";
4
5
  import { AIMessage, AIMessageChunk, ChatMessage, ChatMessageChunk, FunctionMessage, FunctionMessageChunk, HumanMessage, HumanMessageChunk, SystemMessage, SystemMessageChunk, ToolMessage, ToolMessageChunk, } from "@langchain/core/messages";
5
- import { getBytes, getLines, getMessages, } from "@langchain/community/utils/event_source_parse";
6
+ import { GenerationChunk, ChatGenerationChunk, RUN_KEY, } from "@langchain/core/outputs";
7
+ import { getBytes, getLines, getMessages, convertEventStreamToIterableReadableDataStream, } from "@langchain/community/utils/event_source_parse";
6
8
  import { IterableReadableStream } from "@langchain/core/utils/stream";
7
9
  function isSuperset(set, subset) {
8
10
  for (const elem of subset) {
@@ -17,94 +19,153 @@ function revive(obj) {
17
19
  if (Array.isArray(obj))
18
20
  return obj.map(revive);
19
21
  if (typeof obj === "object") {
22
+ // eslint-disable-next-line no-instanceof/no-instanceof
23
+ if (!obj || obj instanceof Date) {
24
+ return obj;
25
+ }
20
26
  const keysArr = Object.keys(obj);
21
27
  const keys = new Set(keysArr);
22
- if (isSuperset(keys, new Set(["page_content", "metadata"])))
28
+ if (isSuperset(keys, new Set(["page_content", "metadata"]))) {
23
29
  return new Document({
24
30
  pageContent: obj.page_content,
25
31
  metadata: obj.metadata,
26
32
  });
27
- if (isSuperset(keys, new Set(["content", "type", "is_chunk"]))) {
28
- if (!obj.is_chunk) {
29
- if (obj.type === "human") {
30
- return new HumanMessage({
31
- content: obj.content,
32
- });
33
- }
34
- if (obj.type === "system") {
35
- return new SystemMessage({
36
- content: obj.content,
37
- });
38
- }
39
- if (obj.type === "chat") {
40
- return new ChatMessage({
41
- content: obj.content,
42
- role: obj.role,
43
- });
44
- }
45
- if (obj.type === "function") {
46
- return new FunctionMessage({
47
- content: obj.content,
48
- name: obj.name,
49
- });
50
- }
51
- if (obj.type === "tool") {
52
- return new ToolMessage({
53
- content: obj.content,
54
- tool_call_id: obj.tool_call_id,
55
- });
56
- }
57
- if (obj.type === "ai") {
58
- return new AIMessage({
59
- content: obj.content,
60
- });
61
- }
62
- }
63
- else {
64
- if (obj.type === "human") {
65
- return new HumanMessageChunk({
66
- content: obj.content,
67
- });
68
- }
69
- if (obj.type === "system") {
70
- return new SystemMessageChunk({
71
- content: obj.content,
72
- });
73
- }
74
- if (obj.type === "chat") {
75
- return new ChatMessageChunk({
76
- content: obj.content,
77
- role: obj.role,
78
- });
79
- }
80
- if (obj.type === "function") {
81
- return new FunctionMessageChunk({
82
- content: obj.content,
83
- name: obj.name,
84
- });
85
- }
86
- if (obj.type === "tool") {
87
- return new ToolMessageChunk({
88
- content: obj.content,
89
- tool_call_id: obj.tool_call_id,
90
- });
91
- }
92
- if (obj.type === "ai") {
93
- return new AIMessageChunk({
94
- content: obj.content,
95
- });
96
- }
33
+ }
34
+ if (isSuperset(keys, new Set(["content", "type", "additional_kwargs"]))) {
35
+ if (obj.type === "HumanMessage" || obj.type === "human") {
36
+ return new HumanMessage({
37
+ content: obj.content,
38
+ });
39
+ }
40
+ if (obj.type === "SystemMessage" || obj.type === "system") {
41
+ return new SystemMessage({
42
+ content: obj.content,
43
+ });
44
+ }
45
+ if (obj.type === "ChatMessage" || obj.type === "chat") {
46
+ return new ChatMessage({
47
+ content: obj.content,
48
+ role: obj.role,
49
+ });
50
+ }
51
+ if (obj.type === "FunctionMessage" || obj.type === "function") {
52
+ return new FunctionMessage({
53
+ content: obj.content,
54
+ name: obj.name,
55
+ });
56
+ }
57
+ if (obj.type === "ToolMessage" || obj.type === "tool") {
58
+ return new ToolMessage({
59
+ content: obj.content,
60
+ tool_call_id: obj.tool_call_id,
61
+ });
62
+ }
63
+ if (obj.type === "AIMessage" || obj.type === "ai") {
64
+ return new AIMessage({
65
+ content: obj.content,
66
+ });
67
+ }
68
+ if (obj.type === "HumanMessageChunk") {
69
+ return new HumanMessageChunk({
70
+ content: obj.content,
71
+ });
72
+ }
73
+ if (obj.type === "SystemMessageChunk") {
74
+ return new SystemMessageChunk({
75
+ content: obj.content,
76
+ });
77
+ }
78
+ if (obj.type === "ChatMessageChunk") {
79
+ return new ChatMessageChunk({
80
+ content: obj.content,
81
+ role: obj.role,
82
+ });
83
+ }
84
+ if (obj.type === "FunctionMessageChunk") {
85
+ return new FunctionMessageChunk({
86
+ content: obj.content,
87
+ name: obj.name,
88
+ });
89
+ }
90
+ if (obj.type === "ToolMessageChunk") {
91
+ return new ToolMessageChunk({
92
+ content: obj.content,
93
+ tool_call_id: obj.tool_call_id,
94
+ });
95
+ }
96
+ if (obj.type === "AIMessageChunk") {
97
+ return new AIMessageChunk({
98
+ content: obj.content,
99
+ });
97
100
  }
98
101
  }
99
- if (isSuperset(keys, new Set(["text"]))) {
100
- return new StringPromptValue(obj.text);
102
+ if (isSuperset(keys, new Set(["text", "generation_info", "type"]))) {
103
+ if (obj.type === "ChatGenerationChunk") {
104
+ return new ChatGenerationChunk({
105
+ message: revive(obj.message),
106
+ text: obj.text,
107
+ generationInfo: obj.generation_info,
108
+ });
109
+ }
110
+ else if (obj.type === "ChatGeneration") {
111
+ return {
112
+ message: revive(obj.message),
113
+ text: obj.text,
114
+ generationInfo: obj.generation_info,
115
+ };
116
+ }
117
+ else if (obj.type === "GenerationChunk") {
118
+ return new GenerationChunk({
119
+ text: obj.text,
120
+ generationInfo: obj.generation_info,
121
+ });
122
+ }
123
+ else if (obj.type === "Generation") {
124
+ return {
125
+ text: obj.text,
126
+ generationInfo: obj.generation_info,
127
+ };
128
+ }
129
+ }
130
+ if (isSuperset(keys, new Set(["tool", "tool_input", "log", "type"]))) {
131
+ if (obj.type === "AgentAction") {
132
+ return {
133
+ tool: obj.tool,
134
+ toolInput: obj.tool_input,
135
+ log: obj.log,
136
+ };
137
+ }
138
+ }
139
+ if (isSuperset(keys, new Set(["return_values", "log", "type"]))) {
140
+ if (obj.type === "AgentFinish") {
141
+ return {
142
+ returnValues: obj.return_values,
143
+ log: obj.log,
144
+ };
145
+ }
146
+ }
147
+ if (isSuperset(keys, new Set(["generations", "run", "type"]))) {
148
+ if (obj.type === "LLMResult") {
149
+ return {
150
+ generations: revive(obj.generations),
151
+ llmOutput: obj.llm_output,
152
+ [RUN_KEY]: obj.run,
153
+ };
154
+ }
101
155
  }
102
156
  if (isSuperset(keys, new Set(["messages"]))) {
157
+ // TODO: Start checking for type: ChatPromptValue and ChatPromptValueConcrete
158
+ // when LangServe bug is fixed
103
159
  return new ChatPromptValue({
104
160
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
105
161
  messages: obj.messages.map((msg) => revive(msg)),
106
162
  });
107
163
  }
164
+ if (isSuperset(keys, new Set(["text"]))) {
165
+ // TODO: Start checking for type: StringPromptValue
166
+ // when LangServe bug is fixed
167
+ return new StringPromptValue(obj.text);
168
+ }
108
169
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
109
170
  const innerRevive = (key) => [
110
171
  key,
@@ -229,4 +290,47 @@ export class RemoteRunnable extends Runnable {
229
290
  });
230
291
  return IterableReadableStream.fromReadableStream(stream);
231
292
  }
293
+ async *streamLog(input, options, streamOptions) {
294
+ const [config, kwargs] = this._separateRunnableConfigFromCallOptions(options);
295
+ const stream = new LogStreamCallbackHandler({
296
+ ...streamOptions,
297
+ autoClose: false,
298
+ });
299
+ const { callbacks } = config;
300
+ if (callbacks === undefined) {
301
+ config.callbacks = [stream];
302
+ }
303
+ else if (Array.isArray(callbacks)) {
304
+ config.callbacks = callbacks.concat([stream]);
305
+ }
306
+ else {
307
+ const copiedCallbacks = callbacks.copy();
308
+ copiedCallbacks.inheritableHandlers.push(stream);
309
+ config.callbacks = copiedCallbacks;
310
+ }
311
+ // The type is in camelCase but the API only accepts snake_case.
312
+ const camelCaseStreamOptions = {
313
+ include_names: streamOptions?.includeNames,
314
+ include_types: streamOptions?.includeTypes,
315
+ include_tags: streamOptions?.includeTags,
316
+ exclude_names: streamOptions?.excludeNames,
317
+ exclude_types: streamOptions?.excludeTypes,
318
+ exclude_tags: streamOptions?.excludeTags,
319
+ };
320
+ const response = await this.post("/stream_log", {
321
+ input,
322
+ config,
323
+ kwargs,
324
+ ...camelCaseStreamOptions,
325
+ diff: false,
326
+ });
327
+ const { body } = response;
328
+ if (!body) {
329
+ throw new Error("Could not begin remote stream log. Please check the given URL and try again.");
330
+ }
331
+ const runnableStream = convertEventStreamToIterableReadableDataStream(body);
332
+ for await (const log of runnableStream) {
333
+ yield revive(JSON.parse(log));
334
+ }
335
+ }
232
336
  }
@@ -1,14 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ChainTool = void 0;
4
- const dynamic_1 = require("@langchain/community/tools/dynamic");
4
+ const tools_1 = require("@langchain/core/tools");
5
5
  /**
6
+ * @deprecated Wrap in a DynamicTool instead.
6
7
  * Class that extends DynamicTool for creating tools that can run chains.
7
8
  * Takes an instance of a class that extends BaseChain as a parameter in
8
9
  * its constructor and uses it to run the chain when its 'func' method is
9
10
  * called.
10
11
  */
11
- class ChainTool extends dynamic_1.DynamicTool {
12
+ class ChainTool extends tools_1.DynamicTool {
12
13
  static lc_name() {
13
14
  return "ChainTool";
14
15
  }
@@ -1,6 +1,7 @@
1
- import { DynamicTool, DynamicToolInput } from "@langchain/community/tools/dynamic";
1
+ import { DynamicTool, DynamicToolInput } from "@langchain/core/tools";
2
2
  import { BaseChain } from "../chains/base.js";
3
3
  /**
4
+ * @deprecated Wrap in a DynamicTool instead.
4
5
  * Interface for the input parameters of the ChainTool constructor.
5
6
  * Extends the DynamicToolInput interface, replacing the 'func' property
6
7
  * with a 'chain' property.
@@ -9,6 +10,7 @@ export interface ChainToolInput extends Omit<DynamicToolInput, "func"> {
9
10
  chain: BaseChain;
10
11
  }
11
12
  /**
13
+ * @deprecated Wrap in a DynamicTool instead.
12
14
  * Class that extends DynamicTool for creating tools that can run chains.
13
15
  * Takes an instance of a class that extends BaseChain as a parameter in
14
16
  * its constructor and uses it to run the chain when its 'func' method is
@@ -1,5 +1,6 @@
1
- import { DynamicTool, } from "@langchain/community/tools/dynamic";
1
+ import { DynamicTool } from "@langchain/core/tools";
2
2
  /**
3
+ * @deprecated Wrap in a DynamicTool instead.
3
4
  * Class that extends DynamicTool for creating tools that can run chains.
4
5
  * Takes an instance of a class that extends BaseChain as a parameter in
5
6
  * its constructor and uses it to run the chain when its 'func' method is
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createRetrieverTool = void 0;
4
4
  const zod_1 = require("zod");
5
- const dynamic_1 = require("@langchain/community/tools/dynamic");
5
+ const tools_1 = require("@langchain/core/tools");
6
6
  const document_js_1 = require("../util/document.cjs");
7
7
  function createRetrieverTool(retriever, input) {
8
8
  const func = async ({ query }, runManager) => {
@@ -12,6 +12,6 @@ function createRetrieverTool(retriever, input) {
12
12
  const schema = zod_1.z.object({
13
13
  query: zod_1.z.string().describe("query to look up in retriever"),
14
14
  });
15
- return new dynamic_1.DynamicStructuredTool({ ...input, func, schema });
15
+ return new tools_1.DynamicStructuredTool({ ...input, func, schema });
16
16
  }
17
17
  exports.createRetrieverTool = createRetrieverTool;
@@ -1,6 +1,6 @@
1
1
  import type { BaseRetrieverInterface } from "@langchain/core/retrievers";
2
2
  import { z } from "zod";
3
- import { DynamicStructuredTool, type DynamicStructuredToolInput } from "@langchain/community/tools/dynamic";
3
+ import { DynamicStructuredTool, type DynamicStructuredToolInput } from "@langchain/core/tools";
4
4
  export declare function createRetrieverTool(retriever: BaseRetrieverInterface, input: Omit<DynamicStructuredToolInput, "func" | "schema">): DynamicStructuredTool<z.ZodObject<{
5
5
  query: z.ZodString;
6
6
  }, "strip", z.ZodTypeAny, {
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { DynamicStructuredTool, } from "@langchain/community/tools/dynamic";
2
+ import { DynamicStructuredTool, } from "@langchain/core/tools";
3
3
  import { formatDocumentsAsString } from "../util/document.js";
4
4
  export function createRetrieverTool(retriever, input) {
5
5
  const func = async ({ query }, runManager) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langchain",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Typescript bindings for langchain",
5
5
  "type": "module",
6
6
  "engines": {
@@ -886,7 +886,7 @@
886
886
  "build:cjs": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist-cjs/ -p tsconfig.cjs.json && node scripts/move-cjs-to-dist.js && rimraf dist-cjs",
887
887
  "build:watch": "node scripts/create-entrypoints.js && tsc --outDir dist/ --watch",
888
888
  "build:scripts": "node scripts/create-entrypoints.js && node scripts/check-tree-shaking.js",
889
- "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint src",
889
+ "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/",
890
890
  "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts",
891
891
  "lint": "yarn lint:eslint && yarn lint:dpdm",
892
892
  "lint:fix": "yarn lint:eslint --fix && yarn lint:dpdm",
@@ -1203,7 +1203,7 @@
1203
1203
  "dependencies": {
1204
1204
  "@anthropic-ai/sdk": "^0.9.1",
1205
1205
  "@langchain/community": "~0.0.17",
1206
- "@langchain/core": "~0.1.13",
1206
+ "@langchain/core": "~0.1.16",
1207
1207
  "@langchain/openai": "~0.0.12",
1208
1208
  "binary-extensions": "^2.2.0",
1209
1209
  "expr-eval": "^2.0.2",
@@ -1217,8 +1217,8 @@
1217
1217
  "p-retry": "4",
1218
1218
  "uuid": "^9.0.0",
1219
1219
  "yaml": "^2.2.1",
1220
- "zod": "^3.22.3",
1221
- "zod-to-json-schema": "3.20.3"
1220
+ "zod": "^3.22.4",
1221
+ "zod-to-json-schema": "^3.22.3"
1222
1222
  },
1223
1223
  "publishConfig": {
1224
1224
  "access": "public"