langchain 0.1.26 → 0.1.28

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 (34) hide show
  1. package/dist/agents/agent.cjs +137 -10
  2. package/dist/agents/agent.d.ts +37 -5
  3. package/dist/agents/agent.js +133 -9
  4. package/dist/agents/executor.cjs +4 -1
  5. package/dist/agents/executor.js +5 -2
  6. package/dist/agents/openai_functions/index.cjs +6 -2
  7. package/dist/agents/openai_functions/index.d.ts +7 -5
  8. package/dist/agents/openai_functions/index.js +7 -3
  9. package/dist/agents/openai_tools/index.cjs +7 -2
  10. package/dist/agents/openai_tools/index.d.ts +7 -4
  11. package/dist/agents/openai_tools/index.js +7 -2
  12. package/dist/agents/react/index.cjs +7 -2
  13. package/dist/agents/react/index.d.ts +7 -5
  14. package/dist/agents/react/index.js +7 -2
  15. package/dist/agents/structured_chat/index.cjs +6 -2
  16. package/dist/agents/structured_chat/index.d.ts +7 -5
  17. package/dist/agents/structured_chat/index.js +7 -3
  18. package/dist/agents/types.d.ts +21 -3
  19. package/dist/agents/xml/index.cjs +6 -2
  20. package/dist/agents/xml/index.d.ts +7 -5
  21. package/dist/agents/xml/index.js +7 -3
  22. package/dist/document_loaders/fs/unstructured.cjs +40 -0
  23. package/dist/document_loaders/fs/unstructured.d.ts +8 -0
  24. package/dist/document_loaders/fs/unstructured.js +40 -0
  25. package/dist/document_loaders/web/gitbook.cjs +11 -3
  26. package/dist/document_loaders/web/gitbook.d.ts +1 -0
  27. package/dist/document_loaders/web/gitbook.js +11 -3
  28. package/dist/output_parsers/fix.cjs +16 -4
  29. package/dist/output_parsers/fix.d.ts +10 -3
  30. package/dist/output_parsers/fix.js +16 -4
  31. package/dist/retrievers/parent_document.cjs +3 -2
  32. package/dist/retrievers/parent_document.d.ts +3 -1
  33. package/dist/retrievers/parent_document.js +3 -2
  34. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Agent = exports.LLMSingleActionAgent = exports.RunnableAgent = exports.BaseMultiActionAgent = exports.BaseSingleActionAgent = exports.BaseAgent = void 0;
3
+ exports.Agent = exports.LLMSingleActionAgent = exports.RunnableAgent = exports.RunnableMultiActionAgent = exports.RunnableSingleActionAgent = exports.isRunnableAgent = exports.BaseMultiActionAgent = exports.BaseSingleActionAgent = exports.BaseAgent = void 0;
4
4
  const serializable_1 = require("@langchain/core/load/serializable");
5
5
  const runnables_1 = require("@langchain/core/runnables");
6
6
  /**
@@ -81,23 +81,106 @@ exports.BaseMultiActionAgent = BaseMultiActionAgent;
81
81
  function isAgentAction(input) {
82
82
  return !Array.isArray(input) && input?.tool !== undefined;
83
83
  }
84
+ function isRunnableAgent(x) {
85
+ return (x.runnable !==
86
+ undefined);
87
+ }
88
+ exports.isRunnableAgent = isRunnableAgent;
84
89
  /**
85
- * Class representing a single action agent which accepts runnables.
86
- * Extends the BaseMultiActionAgent class and provides methods for
90
+ * Class representing a single-action agent powered by runnables.
91
+ * Extends the BaseSingleActionAgent class and provides methods for
87
92
  * planning agent actions with runnables.
88
93
  */
89
- class RunnableAgent extends BaseMultiActionAgent {
94
+ class RunnableSingleActionAgent extends BaseSingleActionAgent {
90
95
  get inputKeys() {
91
96
  return [];
92
97
  }
93
98
  constructor(fields) {
94
- super();
95
- Object.defineProperty(this, "lc_runnable", {
99
+ super(fields);
100
+ Object.defineProperty(this, "lc_namespace", {
101
+ enumerable: true,
102
+ configurable: true,
103
+ writable: true,
104
+ value: ["langchain", "agents", "runnable"]
105
+ });
106
+ Object.defineProperty(this, "runnable", {
107
+ enumerable: true,
108
+ configurable: true,
109
+ writable: true,
110
+ value: void 0
111
+ });
112
+ /**
113
+ * Whether to stream from the runnable or not.
114
+ * If true, the underlying LLM is invoked in a streaming fashion to make it
115
+ * possible to get access to the individual LLM tokens when using
116
+ * `streamLog` with the Agent Executor. If false then LLM is invoked in a
117
+ * non-streaming fashion and individual LLM tokens will not be available
118
+ * in `streamLog`.
119
+ *
120
+ * Note that the runnable should still only stream a single action or
121
+ * finish chunk.
122
+ */
123
+ Object.defineProperty(this, "streamRunnable", {
96
124
  enumerable: true,
97
125
  configurable: true,
98
126
  writable: true,
99
127
  value: true
100
128
  });
129
+ Object.defineProperty(this, "defaultRunName", {
130
+ enumerable: true,
131
+ configurable: true,
132
+ writable: true,
133
+ value: "RunnableAgent"
134
+ });
135
+ this.runnable = fields.runnable;
136
+ this.defaultRunName = fields.defaultRunName ?? this.defaultRunName;
137
+ this.streamRunnable = fields.streamRunnable ?? this.streamRunnable;
138
+ }
139
+ async plan(steps, inputs, callbackManager, config) {
140
+ const combinedInput = { ...inputs, steps };
141
+ const combinedConfig = (0, runnables_1.patchConfig)(config, {
142
+ callbacks: callbackManager,
143
+ runName: this.defaultRunName,
144
+ });
145
+ if (this.streamRunnable) {
146
+ const stream = await this.runnable.stream(combinedInput, combinedConfig);
147
+ let finalOutput;
148
+ for await (const chunk of stream) {
149
+ if (finalOutput === undefined) {
150
+ finalOutput = chunk;
151
+ }
152
+ else {
153
+ throw new Error([
154
+ `Multiple agent actions/finishes received in streamed agent output.`,
155
+ `Set "streamRunnable: false" when initializing the agent to invoke this agent in non-streaming mode.`,
156
+ ].join("\n"));
157
+ }
158
+ }
159
+ if (finalOutput === undefined) {
160
+ throw new Error([
161
+ "No streaming output received from underlying runnable.",
162
+ `Set "streamRunnable: false" when initializing the agent to invoke this agent in non-streaming mode.`,
163
+ ].join("\n"));
164
+ }
165
+ return finalOutput;
166
+ }
167
+ else {
168
+ return this.runnable.invoke(combinedInput, combinedConfig);
169
+ }
170
+ }
171
+ }
172
+ exports.RunnableSingleActionAgent = RunnableSingleActionAgent;
173
+ /**
174
+ * Class representing a multi-action agent powered by runnables.
175
+ * Extends the BaseMultiActionAgent class and provides methods for
176
+ * planning agent actions with runnables.
177
+ */
178
+ class RunnableMultiActionAgent extends BaseMultiActionAgent {
179
+ get inputKeys() {
180
+ return [];
181
+ }
182
+ constructor(fields) {
183
+ super(fields);
101
184
  Object.defineProperty(this, "lc_namespace", {
102
185
  enumerable: true,
103
186
  configurable: true,
@@ -111,27 +194,71 @@ class RunnableAgent extends BaseMultiActionAgent {
111
194
  writable: true,
112
195
  value: void 0
113
196
  });
197
+ Object.defineProperty(this, "defaultRunName", {
198
+ enumerable: true,
199
+ configurable: true,
200
+ writable: true,
201
+ value: "RunnableAgent"
202
+ });
114
203
  Object.defineProperty(this, "stop", {
115
204
  enumerable: true,
116
205
  configurable: true,
117
206
  writable: true,
118
207
  value: void 0
119
208
  });
209
+ Object.defineProperty(this, "streamRunnable", {
210
+ enumerable: true,
211
+ configurable: true,
212
+ writable: true,
213
+ value: true
214
+ });
120
215
  this.runnable = fields.runnable;
121
216
  this.stop = fields.stop;
217
+ this.defaultRunName = fields.defaultRunName ?? this.defaultRunName;
218
+ this.streamRunnable = fields.streamRunnable ?? this.streamRunnable;
122
219
  }
123
220
  async plan(steps, inputs, callbackManager, config) {
124
- const invokeInput = { ...inputs, steps };
125
- const output = await this.runnable.invoke(invokeInput, (0, runnables_1.patchConfig)(config, {
221
+ const combinedInput = { ...inputs, steps };
222
+ const combinedConfig = (0, runnables_1.patchConfig)(config, {
126
223
  callbacks: callbackManager,
127
- runName: "RunnableAgent",
128
- }));
224
+ runName: this.defaultRunName,
225
+ });
226
+ let output;
227
+ if (this.streamRunnable) {
228
+ const stream = await this.runnable.stream(combinedInput, combinedConfig);
229
+ let finalOutput;
230
+ for await (const chunk of stream) {
231
+ if (finalOutput === undefined) {
232
+ finalOutput = chunk;
233
+ }
234
+ else {
235
+ throw new Error([
236
+ `Multiple agent actions/finishes received in streamed agent output.`,
237
+ `Set "streamRunnable: false" when initializing the agent to invoke this agent in non-streaming mode.`,
238
+ ].join("\n"));
239
+ }
240
+ }
241
+ if (finalOutput === undefined) {
242
+ throw new Error([
243
+ "No streaming output received from underlying runnable.",
244
+ `Set "streamRunnable: false" when initializing the agent to invoke this agent in non-streaming mode.`,
245
+ ].join("\n"));
246
+ }
247
+ output = finalOutput;
248
+ }
249
+ else {
250
+ output = await this.runnable.invoke(combinedInput, combinedConfig);
251
+ }
129
252
  if (isAgentAction(output)) {
130
253
  return [output];
131
254
  }
132
255
  return output;
133
256
  }
134
257
  }
258
+ exports.RunnableMultiActionAgent = RunnableMultiActionAgent;
259
+ /** @deprecated Renamed to RunnableMultiActionAgent. */
260
+ class RunnableAgent extends RunnableMultiActionAgent {
261
+ }
135
262
  exports.RunnableAgent = RunnableAgent;
136
263
  /**
137
264
  * Class representing a single action agent using a LLMChain in LangChain.
@@ -8,7 +8,7 @@ import { ChainValues } from "@langchain/core/utils/types";
8
8
  import { Serializable } from "@langchain/core/load/serializable";
9
9
  import { Runnable, type RunnableConfig } from "@langchain/core/runnables";
10
10
  import { LLMChain } from "../chains/llm_chain.js";
11
- import { AgentActionOutputParser, AgentInput, RunnableAgentInput, SerializedAgent, StoppingMethod } from "./types.js";
11
+ import type { AgentActionOutputParser, AgentInput, RunnableMultiActionAgentInput, RunnableSingleActionAgentInput, SerializedAgent, StoppingMethod } from "./types.js";
12
12
  /**
13
13
  * Record type for arguments passed to output parsers.
14
14
  */
@@ -75,22 +75,54 @@ export declare abstract class BaseMultiActionAgent extends BaseAgent {
75
75
  */
76
76
  abstract plan(steps: AgentStep[], inputs: ChainValues, callbackManager?: CallbackManager, config?: RunnableConfig): Promise<AgentAction[] | AgentFinish>;
77
77
  }
78
+ export declare function isRunnableAgent(x: BaseAgent): boolean;
78
79
  /**
79
- * Class representing a single action agent which accepts runnables.
80
+ * Class representing a single-action agent powered by runnables.
81
+ * Extends the BaseSingleActionAgent class and provides methods for
82
+ * planning agent actions with runnables.
83
+ */
84
+ export declare class RunnableSingleActionAgent extends BaseSingleActionAgent {
85
+ lc_namespace: string[];
86
+ runnable: Runnable<ChainValues & {
87
+ steps: AgentStep[];
88
+ }, AgentAction | AgentFinish>;
89
+ get inputKeys(): string[];
90
+ /**
91
+ * Whether to stream from the runnable or not.
92
+ * If true, the underlying LLM is invoked in a streaming fashion to make it
93
+ * possible to get access to the individual LLM tokens when using
94
+ * `streamLog` with the Agent Executor. If false then LLM is invoked in a
95
+ * non-streaming fashion and individual LLM tokens will not be available
96
+ * in `streamLog`.
97
+ *
98
+ * Note that the runnable should still only stream a single action or
99
+ * finish chunk.
100
+ */
101
+ streamRunnable: boolean;
102
+ defaultRunName: string;
103
+ constructor(fields: RunnableSingleActionAgentInput);
104
+ plan(steps: AgentStep[], inputs: ChainValues, callbackManager?: CallbackManager, config?: RunnableConfig): Promise<AgentAction | AgentFinish>;
105
+ }
106
+ /**
107
+ * Class representing a multi-action agent powered by runnables.
80
108
  * Extends the BaseMultiActionAgent class and provides methods for
81
109
  * planning agent actions with runnables.
82
110
  */
83
- export declare class RunnableAgent extends BaseMultiActionAgent {
84
- protected lc_runnable: boolean;
111
+ export declare class RunnableMultiActionAgent extends BaseMultiActionAgent {
85
112
  lc_namespace: string[];
86
113
  runnable: Runnable<ChainValues & {
87
114
  steps: AgentStep[];
88
115
  }, AgentAction[] | AgentAction | AgentFinish>;
116
+ defaultRunName: string;
89
117
  stop?: string[];
118
+ streamRunnable: boolean;
90
119
  get inputKeys(): string[];
91
- constructor(fields: RunnableAgentInput);
120
+ constructor(fields: RunnableMultiActionAgentInput);
92
121
  plan(steps: AgentStep[], inputs: ChainValues, callbackManager?: CallbackManager, config?: RunnableConfig): Promise<AgentAction[] | AgentFinish>;
93
122
  }
123
+ /** @deprecated Renamed to RunnableMultiActionAgent. */
124
+ export declare class RunnableAgent extends RunnableMultiActionAgent {
125
+ }
94
126
  /**
95
127
  * Interface for input data for creating a LLMSingleActionAgent.
96
128
  */
@@ -75,23 +75,104 @@ export class BaseMultiActionAgent extends BaseAgent {
75
75
  function isAgentAction(input) {
76
76
  return !Array.isArray(input) && input?.tool !== undefined;
77
77
  }
78
+ export function isRunnableAgent(x) {
79
+ return (x.runnable !==
80
+ undefined);
81
+ }
78
82
  /**
79
- * Class representing a single action agent which accepts runnables.
80
- * Extends the BaseMultiActionAgent class and provides methods for
83
+ * Class representing a single-action agent powered by runnables.
84
+ * Extends the BaseSingleActionAgent class and provides methods for
81
85
  * planning agent actions with runnables.
82
86
  */
83
- export class RunnableAgent extends BaseMultiActionAgent {
87
+ export class RunnableSingleActionAgent extends BaseSingleActionAgent {
84
88
  get inputKeys() {
85
89
  return [];
86
90
  }
87
91
  constructor(fields) {
88
- super();
89
- Object.defineProperty(this, "lc_runnable", {
92
+ super(fields);
93
+ Object.defineProperty(this, "lc_namespace", {
94
+ enumerable: true,
95
+ configurable: true,
96
+ writable: true,
97
+ value: ["langchain", "agents", "runnable"]
98
+ });
99
+ Object.defineProperty(this, "runnable", {
100
+ enumerable: true,
101
+ configurable: true,
102
+ writable: true,
103
+ value: void 0
104
+ });
105
+ /**
106
+ * Whether to stream from the runnable or not.
107
+ * If true, the underlying LLM is invoked in a streaming fashion to make it
108
+ * possible to get access to the individual LLM tokens when using
109
+ * `streamLog` with the Agent Executor. If false then LLM is invoked in a
110
+ * non-streaming fashion and individual LLM tokens will not be available
111
+ * in `streamLog`.
112
+ *
113
+ * Note that the runnable should still only stream a single action or
114
+ * finish chunk.
115
+ */
116
+ Object.defineProperty(this, "streamRunnable", {
90
117
  enumerable: true,
91
118
  configurable: true,
92
119
  writable: true,
93
120
  value: true
94
121
  });
122
+ Object.defineProperty(this, "defaultRunName", {
123
+ enumerable: true,
124
+ configurable: true,
125
+ writable: true,
126
+ value: "RunnableAgent"
127
+ });
128
+ this.runnable = fields.runnable;
129
+ this.defaultRunName = fields.defaultRunName ?? this.defaultRunName;
130
+ this.streamRunnable = fields.streamRunnable ?? this.streamRunnable;
131
+ }
132
+ async plan(steps, inputs, callbackManager, config) {
133
+ const combinedInput = { ...inputs, steps };
134
+ const combinedConfig = patchConfig(config, {
135
+ callbacks: callbackManager,
136
+ runName: this.defaultRunName,
137
+ });
138
+ if (this.streamRunnable) {
139
+ const stream = await this.runnable.stream(combinedInput, combinedConfig);
140
+ let finalOutput;
141
+ for await (const chunk of stream) {
142
+ if (finalOutput === undefined) {
143
+ finalOutput = chunk;
144
+ }
145
+ else {
146
+ throw new Error([
147
+ `Multiple agent actions/finishes received in streamed agent output.`,
148
+ `Set "streamRunnable: false" when initializing the agent to invoke this agent in non-streaming mode.`,
149
+ ].join("\n"));
150
+ }
151
+ }
152
+ if (finalOutput === undefined) {
153
+ throw new Error([
154
+ "No streaming output received from underlying runnable.",
155
+ `Set "streamRunnable: false" when initializing the agent to invoke this agent in non-streaming mode.`,
156
+ ].join("\n"));
157
+ }
158
+ return finalOutput;
159
+ }
160
+ else {
161
+ return this.runnable.invoke(combinedInput, combinedConfig);
162
+ }
163
+ }
164
+ }
165
+ /**
166
+ * Class representing a multi-action agent powered by runnables.
167
+ * Extends the BaseMultiActionAgent class and provides methods for
168
+ * planning agent actions with runnables.
169
+ */
170
+ export class RunnableMultiActionAgent extends BaseMultiActionAgent {
171
+ get inputKeys() {
172
+ return [];
173
+ }
174
+ constructor(fields) {
175
+ super(fields);
95
176
  Object.defineProperty(this, "lc_namespace", {
96
177
  enumerable: true,
97
178
  configurable: true,
@@ -105,27 +186,70 @@ export class RunnableAgent extends BaseMultiActionAgent {
105
186
  writable: true,
106
187
  value: void 0
107
188
  });
189
+ Object.defineProperty(this, "defaultRunName", {
190
+ enumerable: true,
191
+ configurable: true,
192
+ writable: true,
193
+ value: "RunnableAgent"
194
+ });
108
195
  Object.defineProperty(this, "stop", {
109
196
  enumerable: true,
110
197
  configurable: true,
111
198
  writable: true,
112
199
  value: void 0
113
200
  });
201
+ Object.defineProperty(this, "streamRunnable", {
202
+ enumerable: true,
203
+ configurable: true,
204
+ writable: true,
205
+ value: true
206
+ });
114
207
  this.runnable = fields.runnable;
115
208
  this.stop = fields.stop;
209
+ this.defaultRunName = fields.defaultRunName ?? this.defaultRunName;
210
+ this.streamRunnable = fields.streamRunnable ?? this.streamRunnable;
116
211
  }
117
212
  async plan(steps, inputs, callbackManager, config) {
118
- const invokeInput = { ...inputs, steps };
119
- const output = await this.runnable.invoke(invokeInput, patchConfig(config, {
213
+ const combinedInput = { ...inputs, steps };
214
+ const combinedConfig = patchConfig(config, {
120
215
  callbacks: callbackManager,
121
- runName: "RunnableAgent",
122
- }));
216
+ runName: this.defaultRunName,
217
+ });
218
+ let output;
219
+ if (this.streamRunnable) {
220
+ const stream = await this.runnable.stream(combinedInput, combinedConfig);
221
+ let finalOutput;
222
+ for await (const chunk of stream) {
223
+ if (finalOutput === undefined) {
224
+ finalOutput = chunk;
225
+ }
226
+ else {
227
+ throw new Error([
228
+ `Multiple agent actions/finishes received in streamed agent output.`,
229
+ `Set "streamRunnable: false" when initializing the agent to invoke this agent in non-streaming mode.`,
230
+ ].join("\n"));
231
+ }
232
+ }
233
+ if (finalOutput === undefined) {
234
+ throw new Error([
235
+ "No streaming output received from underlying runnable.",
236
+ `Set "streamRunnable: false" when initializing the agent to invoke this agent in non-streaming mode.`,
237
+ ].join("\n"));
238
+ }
239
+ output = finalOutput;
240
+ }
241
+ else {
242
+ output = await this.runnable.invoke(combinedInput, combinedConfig);
243
+ }
123
244
  if (isAgentAction(output)) {
124
245
  return [output];
125
246
  }
126
247
  return output;
127
248
  }
128
249
  }
250
+ /** @deprecated Renamed to RunnableMultiActionAgent. */
251
+ export class RunnableAgent extends RunnableMultiActionAgent {
252
+ }
129
253
  /**
130
254
  * Class representing a single action agent using a LLMChain in LangChain.
131
255
  * Extends the BaseSingleActionAgent class and provides methods for
@@ -282,11 +282,14 @@ class AgentExecutor extends base_js_1.BaseChain {
282
282
  let agent;
283
283
  let returnOnlyOutputs = true;
284
284
  if (runnables_1.Runnable.isRunnable(input.agent)) {
285
- agent = new agent_js_1.RunnableAgent({ runnable: input.agent });
285
+ agent = new agent_js_1.RunnableMultiActionAgent({ runnable: input.agent });
286
286
  // TODO: Update BaseChain implementation on breaking change
287
287
  returnOnlyOutputs = false;
288
288
  }
289
289
  else {
290
+ if ((0, agent_js_1.isRunnableAgent)(input.agent)) {
291
+ returnOnlyOutputs = false;
292
+ }
290
293
  agent = input.agent;
291
294
  }
292
295
  super(input);
@@ -3,7 +3,7 @@ import { Runnable, patchConfig, } from "@langchain/core/runnables";
3
3
  import { CallbackManager, } from "@langchain/core/callbacks/manager";
4
4
  import { OutputParserException } from "@langchain/core/output_parsers";
5
5
  import { Serializable } from "@langchain/core/load/serializable";
6
- import { RunnableAgent, } from "./agent.js";
6
+ import { RunnableMultiActionAgent, isRunnableAgent, } from "./agent.js";
7
7
  import { BaseChain } from "../chains/base.js";
8
8
  export class AgentExecutorIterator extends Serializable {
9
9
  get finalOutputs() {
@@ -277,11 +277,14 @@ export class AgentExecutor extends BaseChain {
277
277
  let agent;
278
278
  let returnOnlyOutputs = true;
279
279
  if (Runnable.isRunnable(input.agent)) {
280
- agent = new RunnableAgent({ runnable: input.agent });
280
+ agent = new RunnableMultiActionAgent({ runnable: input.agent });
281
281
  // TODO: Update BaseChain implementation on breaking change
282
282
  returnOnlyOutputs = false;
283
283
  }
284
284
  else {
285
+ if (isRunnableAgent(input.agent)) {
286
+ returnOnlyOutputs = false;
287
+ }
285
288
  agent = input.agent;
286
289
  }
287
290
  super(input);
@@ -219,7 +219,7 @@ exports.OpenAIAgent = OpenAIAgent;
219
219
  * });
220
220
  * ```
221
221
  */
222
- async function createOpenAIFunctionsAgent({ llm, tools, prompt, }) {
222
+ async function createOpenAIFunctionsAgent({ llm, tools, prompt, streamRunnable, }) {
223
223
  if (!prompt.inputVariables.includes("agent_scratchpad")) {
224
224
  throw new Error([
225
225
  `Prompt must have an input variable named "agent_scratchpad".`,
@@ -237,6 +237,10 @@ async function createOpenAIFunctionsAgent({ llm, tools, prompt, }) {
237
237
  llmWithTools,
238
238
  new output_parser_js_1.OpenAIFunctionsAgentOutputParser(),
239
239
  ]);
240
- return agent;
240
+ return new agent_js_1.RunnableSingleActionAgent({
241
+ runnable: agent,
242
+ defaultRunName: "OpenAIFunctionsAgent",
243
+ streamRunnable,
244
+ });
241
245
  }
242
246
  exports.createOpenAIFunctionsAgent = createOpenAIFunctionsAgent;
@@ -1,13 +1,12 @@
1
1
  import type { BaseLanguageModelInterface, BaseFunctionCallOptions } from "@langchain/core/language_models/base";
2
2
  import type { StructuredToolInterface } from "@langchain/core/tools";
3
3
  import type { BaseChatModel } from "@langchain/core/language_models/chat_models";
4
- import { RunnableSequence } from "@langchain/core/runnables";
5
4
  import type { AgentAction, AgentFinish, AgentStep } from "@langchain/core/agents";
6
5
  import { BaseMessage, SystemMessage } from "@langchain/core/messages";
7
6
  import { ChainValues } from "@langchain/core/utils/types";
8
7
  import { ChatPromptTemplate, BasePromptTemplate } from "@langchain/core/prompts";
9
8
  import { CallbackManager } from "@langchain/core/callbacks/manager";
10
- import { Agent, AgentArgs } from "../agent.js";
9
+ import { Agent, AgentArgs, RunnableSingleActionAgent } from "../agent.js";
11
10
  import { AgentInput } from "../types.js";
12
11
  import { OpenAIFunctionsAgentOutputParser } from "../openai/output_parser.js";
13
12
  export declare function _formatIntermediateSteps(intermediateSteps: AgentStep[]): BaseMessage[];
@@ -88,6 +87,11 @@ export type CreateOpenAIFunctionsAgentParams = {
88
87
  tools: StructuredToolInterface[];
89
88
  /** The prompt to use, must have an input key for `agent_scratchpad`. */
90
89
  prompt: ChatPromptTemplate;
90
+ /**
91
+ * Whether to invoke the underlying model in streaming mode,
92
+ * allowing streaming of intermediate steps. Defaults to true.
93
+ */
94
+ streamRunnable?: boolean;
91
95
  };
92
96
  /**
93
97
  * Create an agent that uses OpenAI-style function calling.
@@ -144,6 +148,4 @@ export type CreateOpenAIFunctionsAgentParams = {
144
148
  * });
145
149
  * ```
146
150
  */
147
- export declare function createOpenAIFunctionsAgent({ llm, tools, prompt, }: CreateOpenAIFunctionsAgentParams): Promise<RunnableSequence<{
148
- steps: AgentStep[];
149
- }, AgentAction | AgentFinish>>;
151
+ export declare function createOpenAIFunctionsAgent({ llm, tools, prompt, streamRunnable, }: CreateOpenAIFunctionsAgentParams): Promise<RunnableSingleActionAgent>;
@@ -2,7 +2,7 @@ import { RunnablePassthrough, RunnableSequence, } from "@langchain/core/runnable
2
2
  import { convertToOpenAIFunction } from "@langchain/core/utils/function_calling";
3
3
  import { AIMessage, FunctionMessage, } from "@langchain/core/messages";
4
4
  import { ChatPromptTemplate, HumanMessagePromptTemplate, MessagesPlaceholder, SystemMessagePromptTemplate, } from "@langchain/core/prompts";
5
- import { Agent } from "../agent.js";
5
+ import { Agent, RunnableSingleActionAgent } from "../agent.js";
6
6
  import { PREFIX } from "./prompt.js";
7
7
  import { LLMChain } from "../../chains/llm_chain.js";
8
8
  import { OpenAIFunctionsAgentOutputParser, } from "../openai/output_parser.js";
@@ -214,7 +214,7 @@ export class OpenAIAgent extends Agent {
214
214
  * });
215
215
  * ```
216
216
  */
217
- export async function createOpenAIFunctionsAgent({ llm, tools, prompt, }) {
217
+ export async function createOpenAIFunctionsAgent({ llm, tools, prompt, streamRunnable, }) {
218
218
  if (!prompt.inputVariables.includes("agent_scratchpad")) {
219
219
  throw new Error([
220
220
  `Prompt must have an input variable named "agent_scratchpad".`,
@@ -232,5 +232,9 @@ export async function createOpenAIFunctionsAgent({ llm, tools, prompt, }) {
232
232
  llmWithTools,
233
233
  new OpenAIFunctionsAgentOutputParser(),
234
234
  ]);
235
- return agent;
235
+ return new RunnableSingleActionAgent({
236
+ runnable: agent,
237
+ defaultRunName: "OpenAIFunctionsAgent",
238
+ streamRunnable,
239
+ });
236
240
  }
@@ -6,6 +6,7 @@ const function_calling_1 = require("@langchain/core/utils/function_calling");
6
6
  const openai_tools_js_1 = require("../format_scratchpad/openai_tools.cjs");
7
7
  const output_parser_js_1 = require("../openai/output_parser.cjs");
8
8
  Object.defineProperty(exports, "OpenAIToolsAgentOutputParser", { enumerable: true, get: function () { return output_parser_js_1.OpenAIToolsAgentOutputParser; } });
9
+ const agent_js_1 = require("../agent.cjs");
9
10
  /**
10
11
  * Create an agent that uses OpenAI-style tool calling.
11
12
  * @param params Params required to create the agent. Includes an LLM, tools, and prompt.
@@ -62,7 +63,7 @@ Object.defineProperty(exports, "OpenAIToolsAgentOutputParser", { enumerable: tru
62
63
  * });
63
64
  * ```
64
65
  */
65
- async function createOpenAIToolsAgent({ llm, tools, prompt, }) {
66
+ async function createOpenAIToolsAgent({ llm, tools, prompt, streamRunnable, }) {
66
67
  if (!prompt.inputVariables.includes("agent_scratchpad")) {
67
68
  throw new Error([
68
69
  `Prompt must have an input variable named "agent_scratchpad".`,
@@ -78,6 +79,10 @@ async function createOpenAIToolsAgent({ llm, tools, prompt, }) {
78
79
  modelWithTools,
79
80
  new output_parser_js_1.OpenAIToolsAgentOutputParser(),
80
81
  ]);
81
- return agent;
82
+ return new agent_js_1.RunnableMultiActionAgent({
83
+ runnable: agent,
84
+ defaultRunName: "OpenAIToolsAgent",
85
+ streamRunnable,
86
+ });
82
87
  }
83
88
  exports.createOpenAIToolsAgent = createOpenAIToolsAgent;
@@ -1,9 +1,9 @@
1
1
  import type { StructuredToolInterface } from "@langchain/core/tools";
2
2
  import type { BaseChatModel, BaseChatModelCallOptions } from "@langchain/core/language_models/chat_models";
3
3
  import { ChatPromptTemplate } from "@langchain/core/prompts";
4
- import { RunnableSequence } from "@langchain/core/runnables";
5
4
  import { OpenAIClient } from "@langchain/openai";
6
5
  import { OpenAIToolsAgentOutputParser, type ToolsAgentStep } from "../openai/output_parser.js";
6
+ import { RunnableMultiActionAgent } from "../agent.js";
7
7
  export { OpenAIToolsAgentOutputParser, type ToolsAgentStep };
8
8
  /**
9
9
  * Params used by the createOpenAIToolsAgent function.
@@ -22,6 +22,11 @@ export type CreateOpenAIToolsAgentParams = {
22
22
  tools: StructuredToolInterface[];
23
23
  /** The prompt to use, must have an input key of `agent_scratchpad`. */
24
24
  prompt: ChatPromptTemplate;
25
+ /**
26
+ * Whether to invoke the underlying model in streaming mode,
27
+ * allowing streaming of intermediate steps. Defaults to true.
28
+ */
29
+ streamRunnable?: boolean;
25
30
  };
26
31
  /**
27
32
  * Create an agent that uses OpenAI-style tool calling.
@@ -79,6 +84,4 @@ export type CreateOpenAIToolsAgentParams = {
79
84
  * });
80
85
  * ```
81
86
  */
82
- export declare function createOpenAIToolsAgent({ llm, tools, prompt, }: CreateOpenAIToolsAgentParams): Promise<RunnableSequence<{
83
- steps: ToolsAgentStep[];
84
- }, import("@langchain/core/agents").AgentFinish | import("@langchain/core/agents").AgentAction[]>>;
87
+ export declare function createOpenAIToolsAgent({ llm, tools, prompt, streamRunnable, }: CreateOpenAIToolsAgentParams): Promise<RunnableMultiActionAgent>;
@@ -2,6 +2,7 @@ import { RunnablePassthrough, RunnableSequence, } from "@langchain/core/runnable
2
2
  import { convertToOpenAITool } from "@langchain/core/utils/function_calling";
3
3
  import { formatToOpenAIToolMessages } from "../format_scratchpad/openai_tools.js";
4
4
  import { OpenAIToolsAgentOutputParser, } from "../openai/output_parser.js";
5
+ import { RunnableMultiActionAgent } from "../agent.js";
5
6
  export { OpenAIToolsAgentOutputParser };
6
7
  /**
7
8
  * Create an agent that uses OpenAI-style tool calling.
@@ -59,7 +60,7 @@ export { OpenAIToolsAgentOutputParser };
59
60
  * });
60
61
  * ```
61
62
  */
62
- export async function createOpenAIToolsAgent({ llm, tools, prompt, }) {
63
+ export async function createOpenAIToolsAgent({ llm, tools, prompt, streamRunnable, }) {
63
64
  if (!prompt.inputVariables.includes("agent_scratchpad")) {
64
65
  throw new Error([
65
66
  `Prompt must have an input variable named "agent_scratchpad".`,
@@ -75,5 +76,9 @@ export async function createOpenAIToolsAgent({ llm, tools, prompt, }) {
75
76
  modelWithTools,
76
77
  new OpenAIToolsAgentOutputParser(),
77
78
  ]);
78
- return agent;
79
+ return new RunnableMultiActionAgent({
80
+ runnable: agent,
81
+ defaultRunName: "OpenAIToolsAgent",
82
+ streamRunnable,
83
+ });
79
84
  }