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
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The ids of the tool calls the messages answer: the tool node answers every
3
+ * call it runs. Structural rather than `BaseMessage`. See #52.
4
+ *
5
+ * @internal
6
+ * @param messages A run's messages.
7
+ * @returns The ids their `tool_call_id`s answer.
8
+ */
9
+ export const answeredCalls = (messages) => new Set(messages.flatMap((message) => 'tool_call_id' in message && typeof message.tool_call_id === 'string'
10
+ ? [message.tool_call_id]
11
+ : []));
12
+ //# sourceMappingURL=answered-calls.util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"answered-calls.util.js","sourceRoot":"","sources":["../../lib/run/answered-calls.util.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,QAA2B,EAAe,EAAE,CACxE,IAAI,GAAG,CACL,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAC3B,cAAc,IAAI,OAAO,IAAI,OAAO,OAAO,CAAC,YAAY,KAAK,QAAQ;IACnE,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC;IACxB,CAAC,CAAC,EAAE,CACP,CACF,CAAC"}
@@ -1,3 +1,6 @@
1
+ export { answeredCalls } from './answered-calls.util.js';
2
+ export { isRecursionLimit } from './recursion-limit.util.js';
1
3
  export { summariseRun } from './run-summary.util.js';
4
+ export { UsageAside } from './usage-aside.js';
2
5
  export type { RunSummary } from './run-summary.util.js';
3
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/run/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,YAAY,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/run/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,YAAY,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC"}
package/dist/run/index.js CHANGED
@@ -1,2 +1,5 @@
1
+ export { answeredCalls } from './answered-calls.util.js';
2
+ export { isRecursionLimit } from './recursion-limit.util.js';
1
3
  export { summariseRun } from './run-summary.util.js';
4
+ export { UsageAside } from './usage-aside.js';
2
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/run/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/run/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Whether a `recursionLimit` is one LangGraph applies: it rejects a limit
3
+ * below 1, but runs on with `NaN`. See #194.
4
+ *
5
+ * @internal
6
+ * @param limit The option as given, from untyped JavaScript too.
7
+ * @returns `true` for an integer of at least 1, or no limit.
8
+ */
9
+ export declare const isRecursionLimit: (limit: unknown) => boolean;
10
+ //# sourceMappingURL=recursion-limit.util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recursion-limit.util.d.ts","sourceRoot":"","sources":["../../lib/run/recursion-limit.util.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,GAAI,OAAO,OAAO,KAAG,OAEoB,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Whether a `recursionLimit` is one LangGraph applies: it rejects a limit
3
+ * below 1, but runs on with `NaN`. See #194.
4
+ *
5
+ * @internal
6
+ * @param limit The option as given, from untyped JavaScript too.
7
+ * @returns `true` for an integer of at least 1, or no limit.
8
+ */
9
+ export const isRecursionLimit = (limit) => limit === undefined ||
10
+ (typeof limit === 'number' && Number.isInteger(limit) && limit >= 1);
11
+ //# sourceMappingURL=recursion-limit.util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recursion-limit.util.js","sourceRoot":"","sources":["../../lib/run/recursion-limit.util.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAc,EAAW,EAAE,CAC1D,KAAK,KAAK,SAAS;IACnB,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC"}
@@ -3,11 +3,16 @@ interface MessageLike {
3
3
  usage_metadata?: UsageMetadata;
4
4
  tool_calls?: {
5
5
  name: string;
6
+ id?: string;
6
7
  }[];
8
+ tool_call_id?: string;
7
9
  }
8
10
  /** What a run did and cost. */
9
11
  export interface RunSummary {
10
- /** Every tool call the model made, failed and unknown ones included. */
12
+ /**
13
+ * Every tool call that reached the agent's tools, failed and unknown ones
14
+ * included, but not the one returning a structured output.
15
+ */
11
16
  tools: string[];
12
17
  /**
13
18
  * Summed over the run's model calls; absent when the provider reports no
@@ -24,8 +29,10 @@ export interface RunSummary {
24
29
  *
25
30
  * @internal
26
31
  * @param messages The messages of the finished run.
27
- * @returns The tool calls the model made, and the tokens if reported.
32
+ * @param outputTool The tool the model returned a structured output through.
33
+ * @param aside The usage of the replies the run left out of its messages.
34
+ * @returns The tool calls that reached the tools, and the tokens if reported.
28
35
  */
29
- export declare const summariseRun: (messages: readonly MessageLike[]) => RunSummary;
36
+ export declare const summariseRun: (messages: readonly MessageLike[], outputTool?: string, aside?: readonly UsageMetadata[]) => RunSummary;
30
37
  export {};
31
38
  //# sourceMappingURL=run-summary.util.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"run-summary.util.d.ts","sourceRoot":"","sources":["../../lib/run/run-summary.util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAG7E,UAAU,WAAW;IACnB,cAAc,CAAC,EAAE,aAAa,CAAC;IAC/B,UAAU,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CACjC;AAED,+BAA+B;AAC/B,MAAM,WAAW,UAAU;IACzB,wEAAwE;IACxE,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB;;;OAGG;IACH,MAAM,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;CAC3D;AAED;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,GAAI,UAAU,SAAS,WAAW,EAAE,KAAG,UAwB/D,CAAC"}
1
+ {"version":3,"file":"run-summary.util.d.ts","sourceRoot":"","sources":["../../lib/run/run-summary.util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAI7E,UAAU,WAAW;IACnB,cAAc,CAAC,EAAE,aAAa,CAAC;IAC/B,UAAU,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC7C,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,+BAA+B;AAC/B,MAAM,WAAW,UAAU;IACzB;;;OAGG;IACH,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB;;;OAGG;IACH,MAAM,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;CAC3D;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,GACvB,UAAU,SAAS,WAAW,EAAE,EAChC,aAAa,MAAM,EACnB,QAAO,SAAS,aAAa,EAAO,KACnC,UAmCF,CAAC"}
@@ -1,16 +1,28 @@
1
1
  import { mergeUsageMetadata } from '@langchain/core/messages';
2
+ import { answeredCalls } from './answered-calls.util.js';
2
3
  /**
3
4
  * What a finished run cost, read off the messages it returned.
4
5
  *
5
6
  * @internal
6
7
  * @param messages The messages of the finished run.
7
- * @returns The tool calls the model made, and the tokens if reported.
8
+ * @param outputTool The tool the model returned a structured output through.
9
+ * @param aside The usage of the replies the run left out of its messages.
10
+ * @returns The tool calls that reached the tools, and the tokens if reported.
8
11
  */
9
- export const summariseRun = (messages) => {
10
- const tools = messages.flatMap((message) => (message.tool_calls ?? []).map((call) => call.name));
11
- const reported = messages
12
- .map((message) => message.usage_metadata)
13
- .filter((usage) => usage !== undefined);
12
+ export const summariseRun = (messages, outputTool, aside = []) => {
13
+ // One that did not run has no answer (see #290). One with no id cannot be
14
+ // told, and counts (see #295).
15
+ const answered = answeredCalls(messages);
16
+ const tools = messages
17
+ .flatMap((message) => message.tool_calls ?? [])
18
+ .filter(({ name, id }) => name !== outputTool && (id === undefined || answered.has(id)))
19
+ .map((call) => call.name);
20
+ const reported = [
21
+ ...messages
22
+ .map((message) => message.usage_metadata)
23
+ .filter((usage) => usage !== undefined),
24
+ ...aside,
25
+ ];
14
26
  if (reported.length === 0) {
15
27
  return { tools };
16
28
  }
@@ -1 +1 @@
1
- {"version":3,"file":"run-summary.util.js","sourceRoot":"","sources":["../../lib/run/run-summary.util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAiB,MAAM,0BAA0B,CAAC;AAmB7E;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,QAAgC,EAAc,EAAE;IAC3E,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CACzC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C,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,EAAE,CACf,IAAI,KAAK,UAAU,IAAI,CAAC,EAAE,KAAK,SAAS,IAAI,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAChE;SACA,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAE5B,MAAM,QAAQ,GAAG;QACf,GAAG,QAAQ;aACR,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,cAAc,CAAC;aACxC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC;QACzC,GAAG,KAAK;KACT,CAAC;IAEF,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,EAAE,KAAK,EAAE,CAAC;IACnB,CAAC;IAED,oEAAoE;IACpE,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,kBAAkB,EAAE,kBAAkB,EAAE,CAAC,CAAC;IAExE,OAAO;QACL,KAAK;QACL,MAAM,EAAE;YACN,KAAK,EAAE,KAAK,CAAC,YAAY;YACzB,MAAM,EAAE,KAAK,CAAC,aAAa;YAC3B,KAAK,EAAE,KAAK,CAAC,YAAY;SAC1B;KACF,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { UsageMetadata } from '@langchain/core/messages';
2
+ /**
3
+ * The usage of the model's replies a run leaves out of its messages, which its
4
+ * `tokens` still count: those the `unknownTools` re-ask asks again about. One
5
+ * per run, handed to the middlewares in `configurable`. See #296.
6
+ *
7
+ * @internal
8
+ */
9
+ export declare class UsageAside {
10
+ readonly usage: UsageMetadata[];
11
+ /** The `configurable` entry that hands it to the middlewares. */
12
+ get config(): Record<string, UsageAside>;
13
+ /**
14
+ * @param usage A left-out reply's usage, when the provider reported it.
15
+ */
16
+ add(usage: UsageMetadata | undefined): void;
17
+ /**
18
+ * @param configurable A middleware's `runtime.configurable`.
19
+ * @returns The run's aside, when it set one.
20
+ */
21
+ static of(configurable: Record<string, unknown> | undefined): UsageAside | undefined;
22
+ }
23
+ //# sourceMappingURL=usage-aside.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usage-aside.d.ts","sourceRoot":"","sources":["../../lib/run/usage-aside.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAKzD;;;;;;GAMG;AACH,qBAAa,UAAU;IACrB,QAAQ,CAAC,KAAK,EAAE,aAAa,EAAE,CAAM;IAErC,iEAAiE;IACjE,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAEvC;IAED;;OAEG;IACH,GAAG,CAAC,KAAK,EAAE,aAAa,GAAG,SAAS,GAAG,IAAI;IAM3C;;;OAGG;IACH,MAAM,CAAC,EAAE,CACP,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GAChD,UAAU,GAAG,SAAS;CAK1B"}
@@ -0,0 +1,33 @@
1
+ // Our own key in `configurable`, like the run's output. See #296.
2
+ const USAGE_ASIDE_KEY = 'nestjs-langchain:usage-aside';
3
+ /**
4
+ * The usage of the model's replies a run leaves out of its messages, which its
5
+ * `tokens` still count: those the `unknownTools` re-ask asks again about. One
6
+ * per run, handed to the middlewares in `configurable`. See #296.
7
+ *
8
+ * @internal
9
+ */
10
+ export class UsageAside {
11
+ usage = [];
12
+ /** The `configurable` entry that hands it to the middlewares. */
13
+ get config() {
14
+ return { [USAGE_ASIDE_KEY]: this };
15
+ }
16
+ /**
17
+ * @param usage A left-out reply's usage, when the provider reported it.
18
+ */
19
+ add(usage) {
20
+ if (usage) {
21
+ this.usage.push(usage);
22
+ }
23
+ }
24
+ /**
25
+ * @param configurable A middleware's `runtime.configurable`.
26
+ * @returns The run's aside, when it set one.
27
+ */
28
+ static of(configurable) {
29
+ const aside = configurable?.[USAGE_ASIDE_KEY];
30
+ return aside instanceof UsageAside ? aside : undefined;
31
+ }
32
+ }
33
+ //# sourceMappingURL=usage-aside.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usage-aside.js","sourceRoot":"","sources":["../../lib/run/usage-aside.ts"],"names":[],"mappings":"AAEA,kEAAkE;AAClE,MAAM,eAAe,GAAG,8BAA8B,CAAC;AAEvD;;;;;;GAMG;AACH,MAAM,OAAO,UAAU;IACZ,KAAK,GAAoB,EAAE,CAAC;IAErC,iEAAiE;IACjE,IAAI,MAAM;QACR,OAAO,EAAE,CAAC,eAAe,CAAC,EAAE,IAAI,EAAE,CAAC;IACrC,CAAC;IAED;;OAEG;IACH,GAAG,CAAC,KAAgC;QAClC,IAAI,KAAK,EAAE,CAAC;YACV,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACzB,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,EAAE,CACP,YAAiD;QAEjD,MAAM,KAAK,GAAG,YAAY,EAAE,CAAC,eAAe,CAAC,CAAC;QAE9C,OAAO,KAAK,YAAY,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IACzD,CAAC;CACF"}
@@ -16,6 +16,12 @@ export declare const toolErrors: (reporter: RunReporter) => import("langchain").
16
16
  /**
17
17
  * Reports a call to a tool the agent does not have. LangChain's tool node
18
18
  * answers the model itself, without throwing, so `toolErrors` never sees it.
19
+ * One the model invents with the `extract-` prefix never reaches the tool
20
+ * node: it is answered here, as the tool node answers any other, and so is
21
+ * any call LangChain leaves unanswered.
22
+ *
23
+ * @param reporter The agent's reporter.
24
+ * @param tools The names of the agent's tools, which the answer lists.
19
25
  */
20
- export declare const unknownTools: (reporter: RunReporter) => import("langchain").AgentMiddleware<undefined, undefined, unknown, readonly (import("@langchain/core/tools").ServerTool | import("@langchain/core/tools").ClientTool)[], readonly []>;
26
+ export declare const unknownTools: (reporter: RunReporter, tools: string[]) => import("langchain").AgentMiddleware<undefined, undefined, unknown, readonly (import("@langchain/core/tools").ServerTool | import("@langchain/core/tools").ClientTool)[], readonly []>;
21
27
  //# sourceMappingURL=tool-errors.middleware.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tool-errors.middleware.d.ts","sourceRoot":"","sources":["../../lib/tools/tool-errors.middleware.ts"],"names":[],"mappings":"AAMA,OAAO,EAAmB,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEnE;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,UAAU,GAAI,UAAU,WAAW,0LAwB5C,CAAC;AAEL;;;GAGG;AACH,eAAO,MAAM,YAAY,GAAI,UAAU,WAAW,0LAgB9C,CAAC"}
1
+ {"version":3,"file":"tool-errors.middleware.d.ts","sourceRoot":"","sources":["../../lib/tools/tool-errors.middleware.ts"],"names":[],"mappings":"AAaA,OAAO,EAAmB,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAkBnE;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,UAAU,GAAI,UAAU,WAAW,0LAwB5C,CAAC;AAEL;;;;;;;;;GASG;AACH,eAAO,MAAM,YAAY,GAAI,UAAU,WAAW,EAAE,OAAO,MAAM,EAAE,0LAiFlE,CAAC"}
@@ -1,6 +1,17 @@
1
+ import { AIMessage, ToolMessage, } from '@langchain/core/messages';
1
2
  import { createMiddleware, toolErrorMiddleware, ToolInvocationError, } from 'langchain';
2
- import { unknownTool } from '../errors/messages.js';
3
+ import { OUTPUT_TOOL, STRUCTURED_OUTPUT_PREFIX } from '../constants.js';
4
+ import { invalidTool, toolNotRun, unknownTool } from '../errors/messages.js';
3
5
  import { reportToolError } from '../logging/index.js';
6
+ import { answeredCalls, UsageAside } from '../run/index.js';
7
+ // The default of LangChain's own retry middlewares. See #151.
8
+ const MAX_REASKS = 2;
9
+ // LangChain routes every `extract-` call to structured output, never to the
10
+ // tools: one the model invents, which is not the run's output, neither runs
11
+ // nor gets an answer. See #264.
12
+ const isInvented = ({ name }) => name.startsWith(STRUCTURED_OUTPUT_PREFIX) && name !== OUTPUT_TOOL;
13
+ const invented = (calls) => calls.filter(isInvented);
14
+ const callsOf = (message) => AIMessage.isInstance(message) ? (message.tool_calls ?? []) : [];
4
15
  /**
5
16
  * Turns a failed tool call into the text the model receives, LangChain's own,
6
17
  * without the stack (and its server paths) LangChain puts in a schema failure.
@@ -36,20 +47,74 @@ export const toolErrors = (reporter) => toolErrorMiddleware({
36
47
  /**
37
48
  * Reports a call to a tool the agent does not have. LangChain's tool node
38
49
  * answers the model itself, without throwing, so `toolErrors` never sees it.
50
+ * One the model invents with the `extract-` prefix never reaches the tool
51
+ * node: it is answered here, as the tool node answers any other, and so is
52
+ * any call LangChain leaves unanswered.
53
+ *
54
+ * @param reporter The agent's reporter.
55
+ * @param tools The names of the agent's tools, which the answer lists.
39
56
  */
40
- export const unknownTools = (reporter) => createMiddleware({
41
- name: 'unknownTools',
42
- wrapToolCall: (request, handler) => {
43
- if (!request.tool) {
44
- reportToolError(reporter, {
45
- tool: request.toolCall.name,
46
- callId: request.toolCall.id ?? '',
47
- reason: 'unknown-tool',
48
- error: new Error(unknownTool()),
49
- durationMs: 0,
50
- });
51
- }
52
- return handler(request);
53
- },
54
- });
57
+ export const unknownTools = (reporter, tools) => {
58
+ const report = ({ name, id }) => reportToolError(reporter, {
59
+ tool: name,
60
+ callId: id ?? '',
61
+ reason: 'unknown-tool',
62
+ error: new Error(unknownTool()),
63
+ durationMs: 0,
64
+ });
65
+ const answer = (call) => new ToolMessage({
66
+ content: isInvented(call)
67
+ ? invalidTool(call.name, tools)
68
+ : toolNotRun(call.name),
69
+ tool_call_id: call.id ?? '',
70
+ name: call.name,
71
+ status: 'error',
72
+ });
73
+ // Every call without an answer gets one right after its message, which
74
+ // providers require: an invented one (see #264), or one LangChain left out
75
+ // next to the output (see #290). In the request, which the output's retry
76
+ // reaches without `beforeModel`; rebuilt on every model call, so only the
77
+ // reply just made is reported. See #297.
78
+ const answerLeft = (messages) => {
79
+ const done = answeredCalls(messages);
80
+ const left = (message) => callsOf(message).filter(({ id }) => id !== undefined && !done.has(id));
81
+ invented(left(messages.findLast((m) => AIMessage.isInstance(m)))).forEach(report);
82
+ return messages.flatMap((message) => [
83
+ message,
84
+ ...left(message).map(answer),
85
+ ]);
86
+ };
87
+ return createMiddleware({
88
+ name: 'unknownTools',
89
+ // Alone, LangChain would end the run: answered, and the model asked again,
90
+ // as `modelRetryMiddleware` asks it again. See #264.
91
+ wrapModelCall: async (request, handler) => {
92
+ let current = { ...request, messages: answerLeft(request.messages) };
93
+ for (let asked = 0;; asked += 1) {
94
+ const reply = await handler(current);
95
+ const calls = callsOf(reply);
96
+ const left = invented(calls);
97
+ if (calls.length === 0 || left.length < calls.length) {
98
+ return reply;
99
+ }
100
+ left.forEach(report);
101
+ if (asked === MAX_REASKS) {
102
+ return reply;
103
+ }
104
+ // Left out of the run's messages, but paid for. See #296.
105
+ UsageAside.of(request.runtime.configurable)?.add(AIMessage.isInstance(reply) ? reply.usage_metadata : undefined);
106
+ current = {
107
+ ...current,
108
+ messages: [...current.messages, reply, ...left.map(answer)],
109
+ };
110
+ }
111
+ },
112
+ wrapToolCall: (request, handler) => {
113
+ if (!request.tool) {
114
+ report(request.toolCall);
115
+ }
116
+ return handler(request);
117
+ },
118
+ });
119
+ };
55
120
  //# sourceMappingURL=tool-errors.middleware.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tool-errors.middleware.js","sourceRoot":"","sources":["../../lib/tools/tool-errors.middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAe,MAAM,qBAAqB,CAAC;AAEnE;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,QAAqB,EAAE,EAAE,CAClD,mBAAmB,CAAC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AEF;;;GAGG;AACH,eAAO,MAAM,sBAAsB,GACjC,OAAO;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EAAE,KACvC,MAAM,EAgBR,CAAC"}
1
+ {"version":3,"file":"tool-name.util.d.ts","sourceRoot":"","sources":["../../lib/tools/tool-name.util.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,eAAe,GAC1B,UAAU,MAAM,GAAG,SAAS,EAC5B,QAAQ,MAAM,EACd,OAAO,MAAM,KACZ,MAcF,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,sBAAsB,GACjC,OAAO;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EAAE,KACvC,MAAM,EAgBR,CAAC"}
@@ -1,10 +1,8 @@
1
+ import { STRUCTURED_OUTPUT_PREFIX } from '../constants.js';
1
2
  import { duplicateToolName, invalidToolName, reservedToolName, } from '../errors/messages.js';
2
3
  // OpenAI's limit, the strictest published, restated: no provider SDK exports
3
4
  // it. See #90.
4
5
  const TOOL_NAME = /^[a-zA-Z0-9_-]{1,64}$/;
5
- // The agent routes a call with this prefix to structured output, never to the
6
- // tool. Restated: LangChain does not export it. See #213.
7
- const STRUCTURED_OUTPUT_PREFIX = 'extract-';
8
6
  export const resolveToolName = (declared, method, where) => {
9
7
  const name = declared ?? method;
10
8
  if (!TOOL_NAME.test(name)) {
@@ -1 +1 @@
1
- {"version":3,"file":"tool-name.util.js","sourceRoot":"","sources":["../../lib/tools/tool-name.util.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAE/B,6EAA6E;AAC7E,eAAe;AACf,MAAM,SAAS,GAAG,uBAAuB,CAAC;AAE1C,8EAA8E;AAC9E,0DAA0D;AAC1D,MAAM,wBAAwB,GAAG,UAAU,CAAC;AAE5C,MAAM,CAAC,MAAM,eAAe,GAAG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