nestjs-langchain 2.0.0 → 2.2.0

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 (112) hide show
  1. package/README.md +71 -6
  2. package/dist/agent.d.ts +21 -4
  3. package/dist/agent.d.ts.map +1 -1
  4. package/dist/agent.js +73 -33
  5. package/dist/agent.js.map +1 -1
  6. package/dist/constants.d.ts +16 -0
  7. package/dist/constants.d.ts.map +1 -1
  8. package/dist/constants.js +21 -0
  9. package/dist/constants.js.map +1 -1
  10. package/dist/errors/agent-aborted.error.d.ts +21 -0
  11. package/dist/errors/agent-aborted.error.d.ts.map +1 -0
  12. package/dist/errors/agent-aborted.error.js +22 -0
  13. package/dist/errors/agent-aborted.error.js.map +1 -0
  14. package/dist/errors/agent-recursion-limit.error.d.ts +23 -0
  15. package/dist/errors/agent-recursion-limit.error.d.ts.map +1 -0
  16. package/dist/errors/agent-recursion-limit.error.js +24 -0
  17. package/dist/errors/agent-recursion-limit.error.js.map +1 -0
  18. package/dist/errors/index.d.ts +5 -0
  19. package/dist/errors/index.d.ts.map +1 -1
  20. package/dist/errors/index.js +5 -0
  21. package/dist/errors/index.js.map +1 -1
  22. package/dist/errors/messages.d.ts +10 -0
  23. package/dist/errors/messages.d.ts.map +1 -1
  24. package/dist/errors/messages.js +24 -3
  25. package/dist/errors/messages.js.map +1 -1
  26. package/dist/errors/run-error.util.d.ts +21 -0
  27. package/dist/errors/run-error.util.d.ts.map +1 -0
  28. package/dist/errors/run-error.util.js +33 -0
  29. package/dist/errors/run-error.util.js.map +1 -0
  30. package/dist/errors/structured-output.error.d.ts +22 -0
  31. package/dist/errors/structured-output.error.d.ts.map +1 -0
  32. package/dist/errors/structured-output.error.js +23 -0
  33. package/dist/errors/structured-output.error.js.map +1 -0
  34. package/dist/errors/unwrap-middleware-error.util.d.ts +10 -0
  35. package/dist/errors/unwrap-middleware-error.util.d.ts.map +1 -0
  36. package/dist/errors/unwrap-middleware-error.util.js +17 -0
  37. package/dist/errors/unwrap-middleware-error.util.js.map +1 -0
  38. package/dist/index.d.ts +3 -1
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +2 -1
  41. package/dist/index.js.map +1 -1
  42. package/dist/interfaces/completed-run.interface.d.ts +1 -1
  43. package/dist/interfaces/completed-run.interface.d.ts.map +1 -1
  44. package/dist/interfaces/langchain-module-options.interface.d.ts +6 -0
  45. package/dist/interfaces/langchain-module-options.interface.d.ts.map +1 -1
  46. package/dist/interfaces/run-options.interface.d.ts +34 -0
  47. package/dist/interfaces/run-options.interface.d.ts.map +1 -0
  48. package/dist/interfaces/run-options.interface.js +2 -0
  49. package/dist/interfaces/run-options.interface.js.map +1 -0
  50. package/dist/output/index.d.ts +3 -0
  51. package/dist/output/index.d.ts.map +1 -0
  52. package/dist/output/index.js +3 -0
  53. package/dist/output/index.js.map +1 -0
  54. package/dist/output/run-output.d.ts +43 -0
  55. package/dist/output/run-output.d.ts.map +1 -0
  56. package/dist/output/run-output.js +107 -0
  57. package/dist/output/run-output.js.map +1 -0
  58. package/dist/output/structured-output.middleware.d.ts +22 -0
  59. package/dist/output/structured-output.middleware.d.ts.map +1 -0
  60. package/dist/output/structured-output.middleware.js +40 -0
  61. package/dist/output/structured-output.middleware.js.map +1 -0
  62. package/dist/run/answered-calls.util.d.ts +10 -0
  63. package/dist/run/answered-calls.util.d.ts.map +1 -0
  64. package/dist/run/answered-calls.util.js +12 -0
  65. package/dist/run/answered-calls.util.js.map +1 -0
  66. package/dist/run/index.d.ts +3 -0
  67. package/dist/run/index.d.ts.map +1 -1
  68. package/dist/run/index.js +3 -0
  69. package/dist/run/index.js.map +1 -1
  70. package/dist/run/recursion-limit.util.d.ts +10 -0
  71. package/dist/run/recursion-limit.util.d.ts.map +1 -0
  72. package/dist/run/recursion-limit.util.js +11 -0
  73. package/dist/run/recursion-limit.util.js.map +1 -0
  74. package/dist/run/run-summary.util.d.ts +10 -3
  75. package/dist/run/run-summary.util.d.ts.map +1 -1
  76. package/dist/run/run-summary.util.js +18 -6
  77. package/dist/run/run-summary.util.js.map +1 -1
  78. package/dist/run/usage-aside.d.ts +23 -0
  79. package/dist/run/usage-aside.d.ts.map +1 -0
  80. package/dist/run/usage-aside.js +33 -0
  81. package/dist/run/usage-aside.js.map +1 -0
  82. package/dist/tools/tool-errors.middleware.d.ts +7 -1
  83. package/dist/tools/tool-errors.middleware.d.ts.map +1 -1
  84. package/dist/tools/tool-errors.middleware.js +81 -16
  85. package/dist/tools/tool-errors.middleware.js.map +1 -1
  86. package/dist/tools/tool-name.util.d.ts.map +1 -1
  87. package/dist/tools/tool-name.util.js +1 -3
  88. package/dist/tools/tool-name.util.js.map +1 -1
  89. package/lib/agent.ts +119 -32
  90. package/lib/constants.ts +24 -0
  91. package/lib/errors/agent-aborted.error.ts +22 -0
  92. package/lib/errors/agent-recursion-limit.error.ts +24 -0
  93. package/lib/errors/index.ts +5 -0
  94. package/lib/errors/messages.ts +55 -3
  95. package/lib/errors/run-error.util.ts +57 -0
  96. package/lib/errors/structured-output.error.ts +23 -0
  97. package/lib/errors/unwrap-middleware-error.util.ts +19 -0
  98. package/lib/index.ts +9 -1
  99. package/lib/interfaces/completed-run.interface.ts +1 -1
  100. package/lib/interfaces/langchain-module-options.interface.ts +6 -0
  101. package/lib/interfaces/run-options.interface.ts +34 -0
  102. package/lib/output/index.ts +5 -0
  103. package/lib/output/run-output.ts +154 -0
  104. package/lib/output/structured-output.middleware.ts +44 -0
  105. package/lib/run/answered-calls.util.ts +16 -0
  106. package/lib/run/index.ts +3 -0
  107. package/lib/run/recursion-limit.util.ts +11 -0
  108. package/lib/run/run-summary.util.ts +33 -11
  109. package/lib/run/usage-aside.ts +41 -0
  110. package/lib/tools/tool-errors.middleware.ts +104 -10
  111. package/lib/tools/tool-name.util.ts +1 -4
  112. package/package.json +31 -12
package/README.md CHANGED
@@ -2,8 +2,14 @@
2
2
  <a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="200" alt="Nest Logo" /></a>
3
3
  </p>
4
4
 
5
+ <h1 align="center">nestjs-langchain</h1>
6
+
7
+ <p align="center">
8
+ <strong>AI agents for <a href="https://nestjs.com/">NestJS</a>, powered by <a href="https://www.langchain.com/">LangChain</a>.</strong>
9
+ </p>
10
+
5
11
  <p align="center">
6
- A <a href="https://nestjs.com/">Nest</a> module wrapper for building AI agents with <a href="https://www.langchain.com/">LangChain</a>.
12
+ Declare agents as modules, inject them like any provider, and give them your services as tools.
7
13
  </p>
8
14
 
9
15
  <p align="center">
@@ -26,15 +32,32 @@
26
32
  - [Quick start](#quick-start)
27
33
  - [Defining tools](#defining-tools)
28
34
  - [Multi-agent support](#multi-agent-support)
35
+ - [Structured output](#structured-output)
29
36
  - [Async configuration](#async-configuration)
30
37
  - [Testing](#testing)
31
38
  - [Logging and observing](#logging-and-observing)
39
+ - [Roadmap](#roadmap)
40
+ - [Tutorials](#tutorials)
32
41
  - [Contributing](#contributing)
33
42
  - [License](#license)
34
43
 
35
44
  ## Description
36
45
 
37
- **nestjs-langchain** is a powerful, decorator-driven wrapper that integrates LangChain agents seamlessly into the NestJS ecosystem. It allows you to transform standard NestJS services into AI tools and manage multiple isolated agents with distinct roles and configurations.
46
+ **nestjs-langchain** brings AI agents to NestJS. Your app becomes their harness: an agent is a
47
+ module, its tools are your services, and dependency injection, configuration and tests work as
48
+ everywhere else in Nest. LangChain runs the agent loop underneath.
49
+
50
+ - **[Agents as modules](#quick-start)**: register an agent, inject it, `run()` it.
51
+ - **[Your services as tools](#defining-tools)**: `@Tool()` turns a method into a tool the model
52
+ can call.
53
+ - **[Several agents, several models](#multi-agent-support)**: each agent has its own prompt,
54
+ tools and model, from OpenAI, Anthropic, Mistral, Google, Ollama or any LangChain chat model.
55
+ - **[Typed answers](#structured-output)**: structured output parsed from a Zod schema.
56
+ - **[Observable](#logging-and-observing) and [testable](#testing)**: an observer on every run
57
+ and tool call, LangSmith tracing, and tests on LangChain's `fakeModel()`.
58
+
59
+ MCP servers, conversation memory and streaming are on the [roadmap](#roadmap). New to it? Start
60
+ with the [tutorials](#tutorials).
38
61
 
39
62
  ## Installation
40
63
 
@@ -186,7 +209,7 @@ Before exposing tools to users, read [docs/security.md](docs/security.md).
186
209
 
187
210
  ## Multi-Agent Support
188
211
 
189
- Give each agent a `name`, and inject it with `@InjectAgent()`.
212
+ Give each agent a `name`, its own model and tools, and inject it with `@InjectAgent()`.
190
213
 
191
214
  ### 1. Register a specific agent
192
215
 
@@ -202,7 +225,7 @@ Give each agent a `name`, and inject it with `@InjectAgent()`.
202
225
  }),
203
226
  LangChainModule.register({
204
227
  name: 'MONGO_AGENT',
205
- model: { model: 'openai:gpt-5-mini' },
228
+ model: { model: 'anthropic:claude-sonnet-5-5' },
206
229
  tools: [MongoModule],
207
230
  }),
208
231
  ],
@@ -225,6 +248,22 @@ export class AppService {
225
248
 
226
249
  `Agent` without `@InjectAgent()` is the agent registered without a name.
227
250
 
251
+ ## Structured output
252
+
253
+ Pass a Zod schema as `output`, and `run()` returns the object it parses, typed from it:
254
+
255
+ ```ts
256
+ import { z } from 'zod';
257
+
258
+ const Classification = z.object({
259
+ category: z.enum(['billing', 'bug', 'other']),
260
+ priority: z.number().int().min(1).max(3),
261
+ });
262
+
263
+ const { output } = await this.agent.run(ticket.body, { output: Classification });
264
+ // ^? { category: 'billing' | 'bug' | 'other'; priority: number }
265
+ ```
266
+
228
267
  ## Async Configuration
229
268
 
230
269
  Build the options from other providers with `registerAsync`:
@@ -311,14 +350,16 @@ LangChainModule.register({
311
350
  });
312
351
  ```
313
352
 
314
- With `LANGSMITH_TRACING=true` and `LANGSMITH_API_KEY` set, every run is also traced in LangSmith.
353
+ With `LANGSMITH_TRACING=true` and `LANGSMITH_API_KEY` set, every run is also traced in LangSmith,
354
+ named after its agent.
315
355
 
316
356
  Every event, the errors, the log lines and `callbacks`: [docs/observing.md](docs/observing.md).
317
357
 
318
358
  ### Errors
319
359
 
320
360
  Everything `run()` throws is an `AgentRunError`, with the `agent` that failed and the original
321
- error in `cause`:
361
+ error in `cause`. Its subclasses tell some failures apart: `StructuredOutputError`,
362
+ `AgentAbortedError` and `AgentRecursionLimitError`.
322
363
 
323
364
  ```ts
324
365
  import { AgentRunError } from 'nestjs-langchain';
@@ -332,6 +373,30 @@ try {
332
373
  }
333
374
  ```
334
375
 
376
+ ## Roadmap
377
+
378
+ What comes next, tracked in the issues:
379
+
380
+ - Tools from MCP servers and LangChain integrations ([#195](https://github.com/Martin-Bruel/nestjs-langchain/issues/195))
381
+ - Conversation memory ([#149](https://github.com/Martin-Bruel/nestjs-langchain/issues/149))
382
+ - Streaming ([#154](https://github.com/Martin-Bruel/nestjs-langchain/issues/154))
383
+ - Human-in-the-loop approval of tool calls ([#153](https://github.com/Martin-Bruel/nestjs-langchain/issues/153))
384
+ - A per-run context for tools, such as the current user ([#148](https://github.com/Martin-Bruel/nestjs-langchain/issues/148))
385
+
386
+ ## Tutorials
387
+
388
+ The series [AI agents with NestJS](https://dev.to/martinbruel/series/45463), on DEV:
389
+
390
+ 1. [NestJS + LangChain: Build an AI Agent in 5 Minutes](https://dev.to/martinbruel/nestjs-langchain-build-an-ai-agent-in-5-minutes-1jfd):
391
+ from `nest new` to a `POST /ask` endpoint.
392
+ 2. [NestJS Tool Calling: Turn Services into LLM Tools](https://dev.to/martinbruel/nestjs-tool-calling-turn-services-into-llm-tools-2ac4):
393
+ `@Tool()`, Zod arguments and what the model sees when a tool fails.
394
+ 3. [LangChain Structured Output in NestJS: Typed with Zod](https://dev.to/martinbruel/langchain-structured-output-in-nestjs-typed-with-zod-12a1):
395
+ an object instead of text from `run()`, and what happens when the model gets it wrong.
396
+
397
+ In French: [Gouvernez votre agent IA : NestJS et Mistral en 30 lignes](https://dev.to/martinbruel/gouvernez-votre-agent-ia-nestjs-et-mistral-en-30-lignes-11ad),
398
+ a Mistral model, through its API or on your own servers with Ollama.
399
+
335
400
  ## Contributing
336
401
 
337
402
  Contributions are welcome. Read the
package/dist/agent.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  import { OnModuleInit } from '@nestjs/common';
2
2
  import { DiscoveryService } from '@nestjs/core';
3
+ import type { z, ZodType } from 'zod';
3
4
  import { LangChainModuleOptions } from './interfaces/langchain-module-options.interface.js';
4
5
  import { CompletedRun } from './interfaces/completed-run.interface.js';
6
+ import { RunOptions } from './interfaces/run-options.interface.js';
5
7
  import { ToolDiscoveryService } from './tools/index.js';
6
8
  /**
7
9
  * One agent, registered through `LangChainModule`. Inject it directly for the
@@ -26,7 +28,6 @@ export declare class Agent implements OnModuleInit {
26
28
  private readonly logger;
27
29
  private readonly prefix;
28
30
  private readonly reporter;
29
- private readonly modelErrors;
30
31
  /** @internal Built by `LangChainModule`, never by hand. */
31
32
  constructor(options: LangChainModuleOptions, agentName: string, toolDiscovery: ToolDiscoveryService, discovery: DiscoveryService);
32
33
  /**
@@ -51,13 +52,29 @@ export declare class Agent implements OnModuleInit {
51
52
  * as an `AgentRunError`, the original error in its `cause`.
52
53
  *
53
54
  * @param input The user's message.
54
- * @returns The model's answer, the tools it called and what the run cost.
55
+ * @param options With `output`, the schema the answer must match; with
56
+ * `signal`, what aborts the run; with `recursionLimit`, its most steps.
57
+ * @returns The model's answer, the object `output` parses when given, the
58
+ * tools it called and what the run cost.
55
59
  * @example
56
60
  * ```ts
57
- * const { output, tools } = await agent.run('What is 6 times 7?');
61
+ * const { output, tools } = await agent.run('What is 6 times 7?', {
62
+ * signal: AbortSignal.timeout(30_000),
63
+ * });
64
+ *
65
+ * const { output: ticket } = await agent.run(email, {
66
+ * output: z.object({ category: z.enum(['billing', 'bug', 'other']) }),
67
+ * });
58
68
  * ```
59
69
  */
60
- run(input: string): Promise<CompletedRun>;
70
+ run<S extends ZodType>(input: string, options: RunOptions & {
71
+ output: S;
72
+ }): Promise<CompletedRun<z.output<S>>>;
73
+ run(input: string, options?: RunOptions & {
74
+ output?: undefined;
75
+ }): Promise<CompletedRun>;
76
+ run(input: string, options?: RunOptions): Promise<CompletedRun<unknown>>;
77
+ private modelErrors;
61
78
  private complete;
62
79
  }
63
80
  //# sourceMappingURL=agent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../lib/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAOhD,OAAO,EACL,sBAAsB,EAEvB,MAAM,oDAAoD,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC;AACvE,OAAO,EACL,oBAAoB,EAGrB,MAAM,kBAAkB,CAAC;AAsB1B;;;;;;;;;;;;;GAaG;AACH,qBACa,KAAM,YAAW,YAAY;;IActC,OAAO,CAAC,QAAQ,CAAC,OAAO;IAExB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,SAAS;IAd5B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IACvC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAc;IAGvC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAsB;IAElD,2DAA2D;gBAGxC,OAAO,EAAE,sBAAsB,EAE/B,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,oBAAoB,EACnC,SAAS,EAAE,gBAAgB;IAmB9C;;;;OAIG;IACG,YAAY;IAwBlB,OAAO,CAAC,gBAAgB;IAiBxB;;;;;;;;OAQG;YACW,YAAY;IA8B1B;;;;;;;;;;OAUG;IACG,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;YAsCjC,QAAQ;CA+BvB"}
1
+ {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../lib/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,YAA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AAM,CAAC,EAAE,SAAS,CAAA;KAAE,GAC5C,OAAO,CAAC,YAAY,CAAC;IAExB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IAiExE,OAAO,CAAC,WAAW;YAeL,QAAQ;CA8CvB"}
package/dist/agent.js CHANGED
@@ -17,9 +17,11 @@ import { AGENT_NAME_TOKEN, MODULE_OPTIONS_TOKEN, UNNAMED_AGENT, } from './langch
17
17
  import { ToolDiscoveryService, toolErrors, unknownTools, } from './tools/index.js';
18
18
  import { BaseCallbackHandler } from '@langchain/core/callbacks/base';
19
19
  import { LOG_CONTEXT, messageOf, RunReporter } from './logging/index.js';
20
- import { summariseRun } from './run/index.js';
21
- import { AgentRunError } from './errors/index.js';
22
- import { agentNotBootstrapped, agentPrefix, agentRunFailed, duplicateAgentName, modelNeverReplied, modelNotBuilt, modelReplyEmpty, notAChatModel, } from './errors/messages.js';
20
+ import { DEFAULT_RECURSION_LIMIT } from './constants.js';
21
+ import { isRecursionLimit, summariseRun, UsageAside } from './run/index.js';
22
+ import { outputConfig, RunOutput, structuredOutput } from './output/index.js';
23
+ import { AgentRunError, toRunError } from './errors/index.js';
24
+ import { agentNotBootstrapped, agentPrefix, duplicateAgentName, invalidRecursionLimit, modelNeverReplied, modelNotBuilt, modelReplyEmpty, notAChatModel, } from './errors/messages.js';
23
25
  /**
24
26
  * One agent, registered through `LangChainModule`. Inject it directly for the
25
27
  * unnamed agent, or with `@InjectAgent(name)` for a named one.
@@ -45,9 +47,6 @@ let Agent = class Agent {
45
47
  logger = new Logger();
46
48
  prefix;
47
49
  reporter;
48
- // Model failures, which only LangChain's callbacks see. Tool calls are
49
- // reported by their wrapper and the tool middlewares.
50
- modelErrors;
51
50
  /** @internal Built by `LangChainModule`, never by hand. */
52
51
  constructor(options, agentName, toolDiscovery, discovery) {
53
52
  this.options = options;
@@ -61,12 +60,6 @@ let Agent = class Agent {
61
60
  prefix: this.prefix,
62
61
  observer: options.observer,
63
62
  });
64
- this.modelErrors = BaseCallbackHandler.fromMethods({
65
- handleLLMError: (error) => {
66
- this.reporter.logError(`the model failed: ${messageOf(error)}`);
67
- this.reporter.notify((observer) => observer.onModelError?.({ agent: agentName, error }));
68
- },
69
- });
70
63
  }
71
64
  /**
72
65
  * Called by Nest: builds the agent, once the tool modules' providers exist.
@@ -75,13 +68,27 @@ let Agent = class Agent {
75
68
  */
76
69
  async onModuleInit() {
77
70
  this.assertUniqueName();
71
+ const { recursionLimit } = this.options;
72
+ if (!isRecursionLimit(recursionLimit)) {
73
+ throw new Error(invalidRecursionLimit(this.prefix, recursionLimit));
74
+ }
78
75
  const tools = await this.toolDiscovery.getToolsFromModules(this.options.tools ?? [], this.reporter);
79
76
  this.#graph = createAgent({
80
77
  model: await this.resolveModel(this.options.model),
81
78
  tools,
82
79
  systemPrompt: this.options.systemPrompt,
83
- // The first wraps the next: `toolErrors` sits right around the tool.
84
- middleware: [unknownTools(this.reporter), toolErrors(this.reporter)],
80
+ // The first wraps the next: `toolErrors` sits right around the tool,
81
+ // `structuredOutput` right around the model.
82
+ middleware: [
83
+ unknownTools(this.reporter, tools.map((tool) => tool.name)),
84
+ toolErrors(this.reporter),
85
+ structuredOutput(),
86
+ ],
87
+ }).withConfig({
88
+ // Traces and callbacks tell agents apart; the unnamed one keeps
89
+ // LangGraph's name. See #235.
90
+ runName: this.agentName === UNNAMED_AGENT ? undefined : this.agentName,
91
+ metadata: { agent: this.agentName },
85
92
  });
86
93
  this.logger.log(`${this.prefix}ready with ${tools.length} tool${tools.length === 1 ? '' : 's'}`, LOG_CONTEXT);
87
94
  }
@@ -127,33 +134,41 @@ let Agent = class Agent {
127
134
  // The same object, typed from the declarations `createAgent` reads.
128
135
  return option;
129
136
  }
130
- /**
131
- * Runs the agent to completion on one user message. Every failure is thrown
132
- * as an `AgentRunError`, the original error in its `cause`.
133
- *
134
- * @param input The user's message.
135
- * @returns The model's answer, the tools it called and what the run cost.
136
- * @example
137
- * ```ts
138
- * const { output, tools } = await agent.run('What is 6 times 7?');
139
- * ```
140
- */
141
- async run(input) {
137
+ async run(input, options) {
142
138
  const startedAt = Date.now();
143
139
  const durationMs = () => Date.now() - startedAt;
140
+ // Always passed: left out, a run from another agent's tool would take
141
+ // that run's limit. See #315.
142
+ const recursionLimit = options?.recursionLimit ??
143
+ this.options.recursionLimit ??
144
+ DEFAULT_RECURSION_LIMIT;
144
145
  try {
145
- const { answer, messages } = await this.complete(input);
146
+ // Read in the `try`, and `null` from untyped JavaScript taken as no
147
+ // options, as LangChain takes a `null` config. See #291.
148
+ const schema = options?.output;
149
+ if (!isRecursionLimit(recursionLimit)) {
150
+ throw new AgentRunError(invalidRecursionLimit(this.prefix, recursionLimit), this.agentName);
151
+ }
152
+ const output = schema && new RunOutput(schema, this.agentName);
153
+ const aside = new UsageAside();
154
+ const { answer, messages } = await this.complete(input, output, aside, {
155
+ signal: options?.signal,
156
+ recursionLimit,
157
+ });
146
158
  const finished = {
147
159
  durationMs: durationMs(),
148
- ...summariseRun(messages),
160
+ ...summariseRun(messages, output?.toolName, aside.usage),
149
161
  };
150
162
  this.reporter.notify((observer) => observer.onRunFinish?.({ agent: this.agentName, ...finished }));
151
163
  return { status: 'completed', output: answer, ...finished };
152
164
  }
153
165
  catch (thrown) {
154
- const error = thrown instanceof AgentRunError
155
- ? thrown
156
- : new AgentRunError(agentRunFailed(this.prefix, thrown), this.agentName, { cause: thrown });
166
+ const error = toRunError(thrown, {
167
+ agent: this.agentName,
168
+ prefix: this.prefix,
169
+ signal: options?.signal,
170
+ recursionLimit,
171
+ });
157
172
  this.reporter.notify((observer) => observer.onRunError?.({
158
173
  agent: this.agentName,
159
174
  durationMs: durationMs(),
@@ -162,15 +177,40 @@ let Agent = class Agent {
162
177
  throw error;
163
178
  }
164
179
  }
165
- async complete(input) {
180
+ // Model failures, which only LangChain's callbacks see; tool calls are
181
+ // reported by their wrapper and the tool middlewares. One handler per run:
182
+ // a call the run's signal cuts short is no failure. See #318.
183
+ modelErrors(signal) {
184
+ return BaseCallbackHandler.fromMethods({
185
+ handleLLMError: (error) => {
186
+ if (signal?.aborted) {
187
+ return;
188
+ }
189
+ this.reporter.logError(`the model failed: ${messageOf(error)}`);
190
+ this.reporter.notify((observer) => observer.onModelError?.({ agent: this.agentName, error }));
191
+ },
192
+ });
193
+ }
194
+ async complete(input, output, aside, run) {
166
195
  if (!this.#graph) {
167
196
  throw new AgentRunError(agentNotBootstrapped(this.prefix), this.agentName);
168
197
  }
169
- const { messages } = await this.#graph.invoke({ messages: [{ role: 'user', content: input }] }, { callbacks: [this.modelErrors, ...(this.options.callbacks ?? [])] });
198
+ const state = await this.#graph.invoke({ messages: [{ role: 'user', content: input }] }, {
199
+ callbacks: [
200
+ this.modelErrors(run.signal),
201
+ ...(this.options.callbacks ?? []),
202
+ ],
203
+ configurable: { ...outputConfig(output), ...aside.config },
204
+ ...run,
205
+ });
206
+ const { messages } = state;
170
207
  const last = messages[messages.length - 1];
171
208
  if (!last || last.type !== 'ai') {
172
209
  throw new AgentRunError(modelNeverReplied(this.prefix, last?.type), this.agentName);
173
210
  }
211
+ if (output) {
212
+ return { answer: output.read(state.structuredResponse), messages };
213
+ }
174
214
  // `text`, not `content`: block answers are an array.
175
215
  if (!last.text) {
176
216
  throw new AgentRunError(modelReplyEmpty(this.prefix), this.agentName);
package/dist/agent.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"agent.js","sourceRoot":"","sources":["../lib/agent.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAgB,MAAM,gBAAgB,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,aAAa,GACd,MAAM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:tool-params";
3
3
  export declare const PARAM_TYPES_METADATA = "design:paramtypes";
4
+ export declare const STRUCTURED_OUTPUT_PREFIX = "extract-";
5
+ /**
6
+ * The name of the tool a run with an `output` schema answers through: a test
7
+ * faking the model queues a call to it.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * const model = fakeModel().respondWithTools([
12
+ * { name: OUTPUT_TOOL, args: { category: 'bug' } },
13
+ * ]);
14
+ *
15
+ * const { output } = await agent.run(email, { output: Ticket });
16
+ * ```
17
+ */
18
+ export declare const OUTPUT_TOOL: "extract-output";
19
+ export declare const DEFAULT_RECURSION_LIMIT = 25;
4
20
  export declare const MODULE_METADATA_KEYS: string[];
5
21
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../lib/constants.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,aAAa,0BAA0B,CAAC;AACrD,eAAO,MAAM,oBAAoB,iCAAiC,CAAC;AAGnE,eAAO,MAAM,oBAAoB,sBAAsB,CAAC;AAIxD,eAAO,MAAM,oBAAoB,UAKhC,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../lib/constants.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,aAAa,0BAA0B,CAAC;AACrD,eAAO,MAAM,oBAAoB,iCAAiC,CAAC;AAGnE,eAAO,MAAM,oBAAoB,sBAAsB,CAAC;AAIxD,eAAO,MAAM,wBAAwB,aAAa,CAAC;AAInD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,WAAW,kBAA+C,CAAC;AAGxE,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAI1C,eAAO,MAAM,oBAAoB,UAKhC,CAAC"}
package/dist/constants.js CHANGED
@@ -3,6 +3,27 @@ export const TOOL_METADATA = 'nestjs-langchain:tool';
3
3
  export const TOOL_PARAMS_METADATA = 'nestjs-langchain:tool-params';
4
4
  // Emitted by `emitDecoratorMetadata` on every decorated method.
5
5
  export const PARAM_TYPES_METADATA = 'design:paramtypes';
6
+ // The agent routes a call with this prefix to structured output, never to the
7
+ // tool. Restated: LangChain does not export it. See #213.
8
+ export const STRUCTURED_OUTPUT_PREFIX = 'extract-';
9
+ // Ours rather than LangChain's counter or the schema's title: the same tool on
10
+ // every run, under the prefix no `@Tool` can take. See #281.
11
+ /**
12
+ * The name of the tool a run with an `output` schema answers through: a test
13
+ * faking the model queues a call to it.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * const model = fakeModel().respondWithTools([
18
+ * { name: OUTPUT_TOOL, args: { category: 'bug' } },
19
+ * ]);
20
+ *
21
+ * const { output } = await agent.run(email, { output: Ticket });
22
+ * ```
23
+ */
24
+ export const OUTPUT_TOOL = `${STRUCTURED_OUTPUT_PREFIX}output`;
25
+ // LangChain's default, restated: it does not export it.
26
+ export const DEFAULT_RECURSION_LIMIT = 25;
6
27
  // The keys `@Module()` writes, restated: `@nestjs/common/constants` is
7
28
  // internal. See #97.
8
29
  export const MODULE_METADATA_KEYS = [
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../lib/constants.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,MAAM,CAAC,MAAM,aAAa,GAAG,uBAAuB,CAAC;AACrD,MAAM,CAAC,MAAM,oBAAoB,GAAG,8BAA8B,CAAC;AAEnE,gEAAgE;AAChE,MAAM,CAAC,MAAM,oBAAoB,GAAG,mBAAmB,CAAC;AAExD,uEAAuE;AACvE,qBAAqB;AACrB,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,SAAS;IACT,WAAW;IACX,aAAa;IACb,SAAS;CACV,CAAC"}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../lib/constants.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,MAAM,CAAC,MAAM,aAAa,GAAG,uBAAuB,CAAC;AACrD,MAAM,CAAC,MAAM,oBAAoB,GAAG,8BAA8B,CAAC;AAEnE,gEAAgE;AAChE,MAAM,CAAC,MAAM,oBAAoB,GAAG,mBAAmB,CAAC;AAExD,8EAA8E;AAC9E,0DAA0D;AAC1D,MAAM,CAAC,MAAM,wBAAwB,GAAG,UAAU,CAAC;AAEnD,+EAA+E;AAC/E,6DAA6D;AAC7D;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,wBAAwB,QAAiB,CAAC;AAExE,wDAAwD;AACxD,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAE1C,uEAAuE;AACvE,qBAAqB;AACrB,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,SAAS;IACT,WAAW;IACX,aAAa;IACb,SAAS;CACV,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { AgentRunError } from './agent-run.error.js';
2
+ /**
3
+ * The run's `signal` was aborted. Its `reason` is in `cause`.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * try {
8
+ * await agent.run(question, { signal: AbortSignal.timeout(30_000) });
9
+ * } catch (error) {
10
+ * if (error instanceof AgentAbortedError) {
11
+ * console.warn('gave up:', error.cause);
12
+ * }
13
+ * }
14
+ * ```
15
+ */
16
+ export declare class AgentAbortedError extends AgentRunError {
17
+ constructor(message: string, agent: string, options?: {
18
+ cause?: unknown;
19
+ });
20
+ }
21
+ //# sourceMappingURL=agent-aborted.error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-aborted.error.d.ts","sourceRoot":"","sources":["../../lib/errors/agent-aborted.error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD;;;;;;;;;;;;;GAaG;AACH,qBAAa,iBAAkB,SAAQ,aAAa;gBACtC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAI1E"}
@@ -0,0 +1,22 @@
1
+ import { AgentRunError } from './agent-run.error.js';
2
+ /**
3
+ * The run's `signal` was aborted. Its `reason` is in `cause`.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * try {
8
+ * await agent.run(question, { signal: AbortSignal.timeout(30_000) });
9
+ * } catch (error) {
10
+ * if (error instanceof AgentAbortedError) {
11
+ * console.warn('gave up:', error.cause);
12
+ * }
13
+ * }
14
+ * ```
15
+ */
16
+ export class AgentAbortedError extends AgentRunError {
17
+ constructor(message, agent, options) {
18
+ super(message, agent, options);
19
+ this.name = 'AgentAbortedError';
20
+ }
21
+ }
22
+ //# sourceMappingURL=agent-aborted.error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-aborted.error.js","sourceRoot":"","sources":["../../lib/errors/agent-aborted.error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,iBAAkB,SAAQ,aAAa;IAClD,YAAY,OAAe,EAAE,KAAa,EAAE,OAA6B;QACvE,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF"}
@@ -0,0 +1,23 @@
1
+ import { AgentRunError } from './agent-run.error.js';
2
+ /**
3
+ * The run took its `recursionLimit` of steps without an answer: the model kept
4
+ * calling tools. LangGraph's error is in `cause`.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * try {
9
+ * await agent.run(question, { recursionLimit: 10 });
10
+ * } catch (error) {
11
+ * if (error instanceof AgentRecursionLimitError) {
12
+ * return 'This question needs too many steps.';
13
+ * }
14
+ * throw error;
15
+ * }
16
+ * ```
17
+ */
18
+ export declare class AgentRecursionLimitError extends AgentRunError {
19
+ constructor(message: string, agent: string, options?: {
20
+ cause?: unknown;
21
+ });
22
+ }
23
+ //# sourceMappingURL=agent-recursion-limit.error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-recursion-limit.error.d.ts","sourceRoot":"","sources":["../../lib/errors/agent-recursion-limit.error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,wBAAyB,SAAQ,aAAa;gBAC7C,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAI1E"}
@@ -0,0 +1,24 @@
1
+ import { AgentRunError } from './agent-run.error.js';
2
+ /**
3
+ * The run took its `recursionLimit` of steps without an answer: the model kept
4
+ * calling tools. LangGraph's error is in `cause`.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * try {
9
+ * await agent.run(question, { recursionLimit: 10 });
10
+ * } catch (error) {
11
+ * if (error instanceof AgentRecursionLimitError) {
12
+ * return 'This question needs too many steps.';
13
+ * }
14
+ * throw error;
15
+ * }
16
+ * ```
17
+ */
18
+ export class AgentRecursionLimitError extends AgentRunError {
19
+ constructor(message, agent, options) {
20
+ super(message, agent, options);
21
+ this.name = 'AgentRecursionLimitError';
22
+ }
23
+ }
24
+ //# sourceMappingURL=agent-recursion-limit.error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-recursion-limit.error.js","sourceRoot":"","sources":["../../lib/errors/agent-recursion-limit.error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,wBAAyB,SAAQ,aAAa;IACzD,YAAY,OAAe,EAAE,KAAa,EAAE,OAA6B;QACvE,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IACzC,CAAC;CACF"}
@@ -1,3 +1,8 @@
1
+ export { AgentAbortedError } from './agent-aborted.error.js';
2
+ export { AgentRecursionLimitError } from './agent-recursion-limit.error.js';
1
3
  export { AgentRunError } from './agent-run.error.js';
4
+ export { toRunError } from './run-error.util.js';
5
+ export { StructuredOutputError } from './structured-output.error.js';
2
6
  export { ToolConfigurationError } from './tool-configuration.error.js';
7
+ export { unwrapMiddlewareError } from './unwrap-middleware-error.util.js';
3
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/errors/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/errors/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC"}
@@ -1,3 +1,8 @@
1
+ export { AgentAbortedError } from './agent-aborted.error.js';
2
+ export { AgentRecursionLimitError } from './agent-recursion-limit.error.js';
1
3
  export { AgentRunError } from './agent-run.error.js';
4
+ export { toRunError } from './run-error.util.js';
5
+ export { StructuredOutputError } from './structured-output.error.js';
2
6
  export { ToolConfigurationError } from './tool-configuration.error.js';
7
+ export { unwrapMiddlewareError } from './unwrap-middleware-error.util.js';
3
8
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/errors/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/errors/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC"}
@@ -22,5 +22,15 @@ export declare const reservedAgentName: (name: string) => string;
22
22
  export declare const agentRunFailed: (prefix: string, cause: unknown) => string;
23
23
  export declare const modelNeverReplied: (prefix: string, last: string | undefined) => string;
24
24
  export declare const modelReplyEmpty: (prefix: string) => string;
25
+ export declare const runAborted: (prefix: string) => string;
26
+ export declare const recursionLimitReached: (prefix: string, limit: number) => string;
27
+ export declare const invalidRecursionLimit: (prefix: string, limit: unknown) => string;
28
+ export declare const noOutputJsonSchemaForm: (prefix: string, reason: string) => string;
29
+ export declare const outputNotAnObject: (prefix: string) => string;
30
+ export declare const structuredOutputMissing: (prefix: string) => string;
31
+ export declare const structuredOutputInvalid: (prefix: string, reason: string) => string;
32
+ export declare const structuredOutputMultiple: (prefix: string, count: number) => string;
25
33
  export declare const unknownTool: () => string;
34
+ export declare const invalidTool: (tool: string, tools: string[]) => string;
35
+ export declare const toolNotRun: (tool: string) => string;
26
36
  //# sourceMappingURL=messages.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../lib/errors/messages.ts"],"names":[],"mappings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