nestjs-langchain 2.0.0-rc.0 → 2.1.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.
- package/README.md +67 -5
- package/dist/agent.d.ts +16 -2
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +31 -23
- package/dist/agent.js.map +1 -1
- package/dist/constants.d.ts +2 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +6 -0
- package/dist/constants.js.map +1 -1
- package/dist/errors/index.d.ts +2 -0
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +2 -0
- package/dist/errors/index.js.map +1 -1
- package/dist/errors/messages.d.ts +7 -0
- package/dist/errors/messages.d.ts.map +1 -1
- package/dist/errors/messages.js +18 -3
- package/dist/errors/messages.js.map +1 -1
- package/dist/errors/structured-output.error.d.ts +22 -0
- package/dist/errors/structured-output.error.d.ts.map +1 -0
- package/dist/errors/structured-output.error.js +23 -0
- package/dist/errors/structured-output.error.js.map +1 -0
- package/dist/errors/unwrap-middleware-error.util.d.ts +10 -0
- package/dist/errors/unwrap-middleware-error.util.d.ts.map +1 -0
- package/dist/errors/unwrap-middleware-error.util.js +17 -0
- package/dist/errors/unwrap-middleware-error.util.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/interfaces/completed-run.interface.d.ts +1 -1
- package/dist/interfaces/completed-run.interface.d.ts.map +1 -1
- package/dist/interfaces/run-options.interface.d.ts +21 -0
- package/dist/interfaces/run-options.interface.d.ts.map +1 -0
- package/dist/interfaces/run-options.interface.js +2 -0
- package/dist/interfaces/run-options.interface.js.map +1 -0
- package/dist/output/index.d.ts +3 -0
- package/dist/output/index.d.ts.map +1 -0
- package/dist/output/index.js +3 -0
- package/dist/output/index.js.map +1 -0
- package/dist/output/run-output.d.ts +43 -0
- package/dist/output/run-output.d.ts.map +1 -0
- package/dist/output/run-output.js +107 -0
- package/dist/output/run-output.js.map +1 -0
- package/dist/output/structured-output.middleware.d.ts +22 -0
- package/dist/output/structured-output.middleware.d.ts.map +1 -0
- package/dist/output/structured-output.middleware.js +40 -0
- package/dist/output/structured-output.middleware.js.map +1 -0
- package/dist/run/answered-calls.util.d.ts +10 -0
- package/dist/run/answered-calls.util.d.ts.map +1 -0
- package/dist/run/answered-calls.util.js +12 -0
- package/dist/run/answered-calls.util.js.map +1 -0
- package/dist/run/index.d.ts +2 -0
- package/dist/run/index.d.ts.map +1 -1
- package/dist/run/index.js +2 -0
- package/dist/run/index.js.map +1 -1
- package/dist/run/run-summary.util.d.ts +10 -3
- package/dist/run/run-summary.util.d.ts.map +1 -1
- package/dist/run/run-summary.util.js +18 -6
- package/dist/run/run-summary.util.js.map +1 -1
- package/dist/run/usage-aside.d.ts +23 -0
- package/dist/run/usage-aside.d.ts.map +1 -0
- package/dist/run/usage-aside.js +33 -0
- package/dist/run/usage-aside.js.map +1 -0
- package/dist/tools/tool-errors.middleware.d.ts +7 -1
- package/dist/tools/tool-errors.middleware.d.ts.map +1 -1
- package/dist/tools/tool-errors.middleware.js +81 -16
- package/dist/tools/tool-errors.middleware.js.map +1 -1
- package/dist/tools/tool-name.util.d.ts.map +1 -1
- package/dist/tools/tool-name.util.js +1 -3
- package/dist/tools/tool-name.util.js.map +1 -1
- package/lib/agent.ts +61 -15
- package/lib/constants.ts +8 -0
- package/lib/errors/index.ts +2 -0
- package/lib/errors/messages.ts +43 -3
- package/lib/errors/structured-output.error.ts +23 -0
- package/lib/errors/unwrap-middleware-error.util.ts +19 -0
- package/lib/index.ts +6 -1
- package/lib/interfaces/completed-run.interface.ts +1 -1
- package/lib/interfaces/run-options.interface.ts +21 -0
- package/lib/output/index.ts +5 -0
- package/lib/output/run-output.ts +154 -0
- package/lib/output/structured-output.middleware.ts +44 -0
- package/lib/run/answered-calls.util.ts +16 -0
- package/lib/run/index.ts +2 -0
- package/lib/run/run-summary.util.ts +33 -11
- package/lib/run/usage-aside.ts +41 -0
- package/lib/tools/tool-errors.middleware.ts +104 -10
- package/lib/tools/tool-name.util.ts +1 -4
- package/package.json +28 -9
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
|
-
|
|
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**
|
|
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: '
|
|
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`:
|
|
@@ -318,7 +357,8 @@ Every event, the errors, the log lines and `callbacks`: [docs/observing.md](docs
|
|
|
318
357
|
### Errors
|
|
319
358
|
|
|
320
359
|
Everything `run()` throws is an `AgentRunError`, with the `agent` that failed and the original
|
|
321
|
-
error in `cause
|
|
360
|
+
error in `cause`. A structured output that is missing or invalid throws its subclass,
|
|
361
|
+
`StructuredOutputError`:
|
|
322
362
|
|
|
323
363
|
```ts
|
|
324
364
|
import { AgentRunError } from 'nestjs-langchain';
|
|
@@ -332,6 +372,28 @@ try {
|
|
|
332
372
|
}
|
|
333
373
|
```
|
|
334
374
|
|
|
375
|
+
## Roadmap
|
|
376
|
+
|
|
377
|
+
What comes next, tracked in the issues:
|
|
378
|
+
|
|
379
|
+
- Tools from MCP servers and LangChain integrations ([#195](https://github.com/Martin-Bruel/nestjs-langchain/issues/195))
|
|
380
|
+
- Conversation memory ([#149](https://github.com/Martin-Bruel/nestjs-langchain/issues/149))
|
|
381
|
+
- Streaming ([#154](https://github.com/Martin-Bruel/nestjs-langchain/issues/154))
|
|
382
|
+
- Human-in-the-loop approval of tool calls ([#153](https://github.com/Martin-Bruel/nestjs-langchain/issues/153))
|
|
383
|
+
- A per-run context for tools, such as the current user ([#148](https://github.com/Martin-Bruel/nestjs-langchain/issues/148))
|
|
384
|
+
|
|
385
|
+
## Tutorials
|
|
386
|
+
|
|
387
|
+
The series [AI agents with NestJS](https://dev.to/martinbruel/series/45463), on DEV:
|
|
388
|
+
|
|
389
|
+
1. [NestJS + LangChain: Build an AI Agent in 5 Minutes](https://dev.to/martinbruel/nestjs-langchain-build-an-ai-agent-in-5-minutes-1jfd):
|
|
390
|
+
from `nest new` to a `POST /ask` endpoint.
|
|
391
|
+
2. [NestJS Tool Calling: Turn Services into LLM Tools](https://dev.to/martinbruel/nestjs-tool-calling-turn-services-into-llm-tools-2ac4):
|
|
392
|
+
`@Tool()`, Zod arguments and what the model sees when a tool fails.
|
|
393
|
+
|
|
394
|
+
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),
|
|
395
|
+
a Mistral model, through its API or on your own servers with Ollama.
|
|
396
|
+
|
|
335
397
|
## Contributing
|
|
336
398
|
|
|
337
399
|
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
|
|
@@ -51,13 +53,25 @@ export declare class Agent implements OnModuleInit {
|
|
|
51
53
|
* as an `AgentRunError`, the original error in its `cause`.
|
|
52
54
|
*
|
|
53
55
|
* @param input The user's message.
|
|
54
|
-
* @
|
|
56
|
+
* @param options With `output`, the schema the answer must match.
|
|
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
61
|
* const { output, tools } = await agent.run('What is 6 times 7?');
|
|
62
|
+
*
|
|
63
|
+
* const { output: ticket } = await agent.run(email, {
|
|
64
|
+
* output: z.object({ category: z.enum(['billing', 'bug', 'other']) }),
|
|
65
|
+
* });
|
|
58
66
|
* ```
|
|
59
67
|
*/
|
|
60
|
-
run(input: string
|
|
68
|
+
run<S extends ZodType>(input: string, options: RunOptions & {
|
|
69
|
+
output: S;
|
|
70
|
+
}): Promise<CompletedRun<z.output<S>>>;
|
|
71
|
+
run(input: string, options?: RunOptions & {
|
|
72
|
+
output?: undefined;
|
|
73
|
+
}): Promise<CompletedRun>;
|
|
74
|
+
run(input: string, options?: RunOptions): Promise<CompletedRun<unknown>>;
|
|
61
75
|
private complete;
|
|
62
76
|
}
|
|
63
77
|
//# sourceMappingURL=agent.d.ts.map
|
package/dist/agent.d.ts.map
CHANGED
|
@@ -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;
|
|
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;AAEhD,OAAO,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAMtC,OAAO,EACL,sBAAsB,EAEvB,MAAM,oDAAoD,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AACnE,OAAO,EACL,oBAAoB,EAGrB,MAAM,kBAAkB,CAAC;AAuB1B;;;;;;;;;;;;;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;IAgClB,OAAO,CAAC,gBAAgB;IAiBxB;;;;;;;;OAQG;YACW,YAAY;IA8B1B;;;;;;;;;;;;;;;;OAgBG;IACH,GAAG,CAAC,CAAC,SAAS,OAAO,EACnB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,UAAU,GAAG;QAAE,MAAM,EAAE,CAAC,CAAA;KAAE,GAClC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IACrC,GAAG,CACD,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,UAAU,GAAG;QAAE,MAAM,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;YAgD1D,QAAQ;CAyCvB"}
|
package/dist/agent.js
CHANGED
|
@@ -17,8 +17,9 @@ 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 {
|
|
20
|
+
import { summariseRun, UsageAside } from './run/index.js';
|
|
21
|
+
import { outputConfig, RunOutput, structuredOutput } from './output/index.js';
|
|
22
|
+
import { AgentRunError, unwrapMiddlewareError } from './errors/index.js';
|
|
22
23
|
import { agentNotBootstrapped, agentPrefix, agentRunFailed, duplicateAgentName, modelNeverReplied, modelNotBuilt, modelReplyEmpty, notAChatModel, } from './errors/messages.js';
|
|
23
24
|
/**
|
|
24
25
|
* One agent, registered through `LangChainModule`. Inject it directly for the
|
|
@@ -80,8 +81,13 @@ let Agent = class Agent {
|
|
|
80
81
|
model: await this.resolveModel(this.options.model),
|
|
81
82
|
tools,
|
|
82
83
|
systemPrompt: this.options.systemPrompt,
|
|
83
|
-
// The first wraps the next: `toolErrors` sits right around the tool
|
|
84
|
-
|
|
84
|
+
// The first wraps the next: `toolErrors` sits right around the tool,
|
|
85
|
+
// `structuredOutput` right around the model.
|
|
86
|
+
middleware: [
|
|
87
|
+
unknownTools(this.reporter, tools.map((tool) => tool.name)),
|
|
88
|
+
toolErrors(this.reporter),
|
|
89
|
+
structuredOutput(),
|
|
90
|
+
],
|
|
85
91
|
});
|
|
86
92
|
this.logger.log(`${this.prefix}ready with ${tools.length} tool${tools.length === 1 ? '' : 's'}`, LOG_CONTEXT);
|
|
87
93
|
}
|
|
@@ -127,33 +133,28 @@ let Agent = class Agent {
|
|
|
127
133
|
// The same object, typed from the declarations `createAgent` reads.
|
|
128
134
|
return option;
|
|
129
135
|
}
|
|
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) {
|
|
136
|
+
async run(input, options) {
|
|
142
137
|
const startedAt = Date.now();
|
|
143
138
|
const durationMs = () => Date.now() - startedAt;
|
|
144
139
|
try {
|
|
145
|
-
|
|
140
|
+
// Read in the `try`, and `null` from untyped JavaScript taken as no
|
|
141
|
+
// options, as LangChain takes a `null` config. See #291.
|
|
142
|
+
const schema = options?.output;
|
|
143
|
+
const output = schema && new RunOutput(schema, this.agentName);
|
|
144
|
+
const aside = new UsageAside();
|
|
145
|
+
const { answer, messages } = await this.complete(input, output, aside);
|
|
146
146
|
const finished = {
|
|
147
147
|
durationMs: durationMs(),
|
|
148
|
-
...summariseRun(messages),
|
|
148
|
+
...summariseRun(messages, output?.toolName, aside.usage),
|
|
149
149
|
};
|
|
150
150
|
this.reporter.notify((observer) => observer.onRunFinish?.({ agent: this.agentName, ...finished }));
|
|
151
151
|
return { status: 'completed', output: answer, ...finished };
|
|
152
152
|
}
|
|
153
153
|
catch (thrown) {
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
154
|
+
const cause = unwrapMiddlewareError(thrown);
|
|
155
|
+
const error = cause instanceof AgentRunError
|
|
156
|
+
? cause
|
|
157
|
+
: new AgentRunError(agentRunFailed(this.prefix, cause), this.agentName, { cause });
|
|
157
158
|
this.reporter.notify((observer) => observer.onRunError?.({
|
|
158
159
|
agent: this.agentName,
|
|
159
160
|
durationMs: durationMs(),
|
|
@@ -162,15 +163,22 @@ let Agent = class Agent {
|
|
|
162
163
|
throw error;
|
|
163
164
|
}
|
|
164
165
|
}
|
|
165
|
-
async complete(input) {
|
|
166
|
+
async complete(input, output, aside) {
|
|
166
167
|
if (!this.#graph) {
|
|
167
168
|
throw new AgentRunError(agentNotBootstrapped(this.prefix), this.agentName);
|
|
168
169
|
}
|
|
169
|
-
const
|
|
170
|
+
const state = await this.#graph.invoke({ messages: [{ role: 'user', content: input }] }, {
|
|
171
|
+
callbacks: [this.modelErrors, ...(this.options.callbacks ?? [])],
|
|
172
|
+
configurable: { ...outputConfig(output), ...aside.config },
|
|
173
|
+
});
|
|
174
|
+
const { messages } = state;
|
|
170
175
|
const last = messages[messages.length - 1];
|
|
171
176
|
if (!last || last.type !== 'ai') {
|
|
172
177
|
throw new AgentRunError(modelNeverReplied(this.prefix, last?.type), this.agentName);
|
|
173
178
|
}
|
|
179
|
+
if (output) {
|
|
180
|
+
return { answer: output.read(state.structuredResponse), messages };
|
|
181
|
+
}
|
|
174
182
|
// `text`, not `content`: block answers are an array.
|
|
175
183
|
if (!last.text) {
|
|
176
184
|
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;
|
|
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;AAEvD,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,aAAa,GACd,MAAM,kCAAkC,CAAC;AAO1C,OAAO,EACL,oBAAoB,EACpB,UAAU,EACV,YAAY,GACb,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAA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AAC,CAAC;QAE3C,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;YAChC,MAAM,IAAI,aAAa,CACrB,iBAAiB,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,EAC1C,IAAI,CAAC,SAAS,CACf,CAAC;QACJ,CAAC;QAED,IAAI,MAAM,EAAE,CAAC;YACX,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,EAAE,QAAQ,EAAE,CAAC;QACrE,CAAC;QAED,qDAAqD;QACrD,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YACf,MAAM,IAAI,aAAa,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;QACxE,CAAC;QAED,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,CAAC;IACzC,CAAC;CACF,CAAA;AArPY,KAAK;IADjB,UAAU,EAAE;IAcR,WAAA,MAAM,CAAC,oBAAoB,CAAC,CAAA;IAE5B,WAAA,MAAM,CAAC,gBAAgB,CAAC,CAAA;qDAEO,oBAAoB;QACxB,gBAAgB;GAlBnC,KAAK,CAqPjB"}
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export declare const TOOL_METADATA = "nestjs-langchain:tool";
|
|
2
2
|
export declare const TOOL_PARAMS_METADATA = "nestjs-langchain:tool-params";
|
|
3
3
|
export declare const PARAM_TYPES_METADATA = "design:paramtypes";
|
|
4
|
+
export declare const STRUCTURED_OUTPUT_PREFIX = "extract-";
|
|
5
|
+
export declare const OUTPUT_TOOL = "extract-output";
|
|
4
6
|
export declare const MODULE_METADATA_KEYS: string[];
|
|
5
7
|
//# sourceMappingURL=constants.d.ts.map
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -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,eAAO,MAAM,WAAW,mBAAsC,CAAC;AAI/D,eAAO,MAAM,oBAAoB,UAKhC,CAAC"}
|
package/dist/constants.js
CHANGED
|
@@ -3,6 +3,12 @@ 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
|
+
export const OUTPUT_TOOL = `${STRUCTURED_OUTPUT_PREFIX}output`;
|
|
6
12
|
// The keys `@Module()` writes, restated: `@nestjs/common/constants` is
|
|
7
13
|
// internal. See #97.
|
|
8
14
|
export const MODULE_METADATA_KEYS = [
|
package/dist/constants.js.map
CHANGED
|
@@ -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,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,wBAAwB,QAAQ,CAAC;AAE/D,uEAAuE;AACvE,qBAAqB;AACrB,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,SAAS;IACT,WAAW;IACX,aAAa;IACb,SAAS;CACV,CAAC"}
|
package/dist/errors/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { AgentRunError } from './agent-run.error.js';
|
|
2
|
+
export { StructuredOutputError } from './structured-output.error.js';
|
|
2
3
|
export { ToolConfigurationError } from './tool-configuration.error.js';
|
|
4
|
+
export { unwrapMiddlewareError } from './unwrap-middleware-error.util.js';
|
|
3
5
|
//# 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,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC"}
|
package/dist/errors/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { AgentRunError } from './agent-run.error.js';
|
|
2
|
+
export { StructuredOutputError } from './structured-output.error.js';
|
|
2
3
|
export { ToolConfigurationError } from './tool-configuration.error.js';
|
|
4
|
+
export { unwrapMiddlewareError } from './unwrap-middleware-error.util.js';
|
|
3
5
|
//# sourceMappingURL=index.js.map
|
package/dist/errors/index.js.map
CHANGED
|
@@ -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,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,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,12 @@ 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 noOutputJsonSchemaForm: (prefix: string, reason: string) => string;
|
|
26
|
+
export declare const outputNotAnObject: (prefix: string) => string;
|
|
27
|
+
export declare const structuredOutputMissing: (prefix: string) => string;
|
|
28
|
+
export declare const structuredOutputInvalid: (prefix: string, reason: string) => string;
|
|
29
|
+
export declare const structuredOutputMultiple: (prefix: string, count: number) => string;
|
|
25
30
|
export declare const unknownTool: () => string;
|
|
31
|
+
export declare const invalidTool: (tool: string, tools: string[]) => string;
|
|
32
|
+
export declare const toolNotRun: (tool: string) => string;
|
|
26
33
|
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../lib/errors/messages.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,KAAG,MACA,CAAC;AAE7C,eAAO,MAAM,YAAY,GAAI,QAAQ,MAAM,EAAE,UAAU,MAAM,EAAE,KAAG,MAIV,CAAC;AAEzD,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,KAAG,MAE6B,CAAC;AAE7E,eAAO,MAAM,qBAAqB,GAAI,OAAO,MAAM,KAAG,MAEU,CAAC;AAEjE,eAAO,MAAM,0BAA0B,GACrC,OAAO,MAAM,EACb,OAAO,MAAM,KACZ,MAG8C,CAAC;AAElD,eAAO,MAAM,sBAAsB,GAAI,OAAO,MAAM,KAAG,MAGhC,CAAC;AAExB,eAAO,MAAM,oBAAoB,GAAI,OAAO,MAAM,KAAG,MAEiB,CAAC;AAEvE,eAAO,MAAM,sBAAsB,QAAO,MACW,CAAC;AAEtD,eAAO,MAAM,kBAAkB,GAC7B,UAAU,MAAM,EAChB,OAAO,SAA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AO,MAAM,cAAc,GAAI,QAAQ,MAAM,EAAE,OAAO,OAAO,KAAG,MAEN,CAAC;AAE3D,eAAO,MAAM,iBAAiB,GAC5B,QAAQ,MAAM,EACd,MAAM,MAAM,GAAG,SAAS,KACvB,MAEuE,CAAC;AAE3E,eAAO,MAAM,eAAe,GAAI,QAAQ,MAAM,KAAG,MACW,CAAC;AAE7D,eAAO,MAAM,sBAAsB,GACjC,QAAQ,MAAM,EACd,QAAQ,MAAM,KACb,MAEe,CAAC;AAEnB,eAAO,MAAM,iBAAiB,GAAI,QAAQ,MAAM,KAAG,MAGX,CAAC;AAEzC,eAAO,MAAM,uBAAuB,GAAI,QAAQ,MAAM,KAAG,MACsB,CAAC;AAEhF,eAAO,MAAM,uBAAuB,GAClC,QAAQ,MAAM,EACd,QAAQ,MAAM,KACb,MAEsB,CAAC;AAE1B,eAAO,MAAM,wBAAwB,GACnC,QAAQ,MAAM,EACd,OAAO,MAAM,KACZ,MACyE,CAAC;AAE7E,eAAO,MAAM,WAAW,QAAO,MAAoC,CAAC;AAIpE,eAAO,MAAM,WAAW,GAAI,MAAM,MAAM,EAAE,OAAO,MAAM,EAAE,KAAG,MACa,CAAC;AAE1E,eAAO,MAAM,UAAU,GAAI,MAAM,MAAM,KAAG,MAEG,CAAC"}
|
package/dist/errors/messages.js
CHANGED
|
@@ -36,9 +36,10 @@ export const cannotInferSchema = (where, param, declared) => `${where}: cannot i
|
|
|
36
36
|
'Pass a `schema` to @ToolParam, or use string, number or boolean.';
|
|
37
37
|
export const schemaContradictsSignature = (where, param, declared, expected) => `${where}: the schema for "${param}" describes ${declared.join(' | ')} ` +
|
|
38
38
|
`but the signature declares ${expected}.`;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
'such as z.iso.datetime() for a date.';
|
|
39
|
+
// The advice of both messages on a schema with no JSON Schema form.
|
|
40
|
+
const jsonSchemaAdvice = 'Declare a schema JSON Schema can express and convert it with .transform(), ' +
|
|
41
|
+
'such as z.iso.date() or z.iso.datetime() for a date.';
|
|
42
|
+
export const noJsonSchemaForm = (where, param, reason) => `${where}: "${param}" has no JSON Schema form (${reason}). ${jsonSchemaAdvice}`;
|
|
42
43
|
export const duplicateParamName = (where, name, first, second) => `${where}: parameters ${first + 1} and ${second + 1} are both named "${name}". ` +
|
|
43
44
|
'Give each @ToolParam its own name.';
|
|
44
45
|
export const notAChatModel = (prefix) => `The ${prefix}agent's \`model\` is neither a LangChain chat model nor a ` +
|
|
@@ -63,5 +64,19 @@ export const agentRunFailed = (prefix, cause) => `The ${prefix}agent's run faile
|
|
|
63
64
|
export const modelNeverReplied = (prefix, last) => `The ${prefix}agent's loop ended before the model replied. ` +
|
|
64
65
|
`The last message was ${last ? `a ${last} message` : 'never produced'}.`;
|
|
65
66
|
export const modelReplyEmpty = (prefix) => `The ${prefix}agent's model replied with no text content.`;
|
|
67
|
+
export const noOutputJsonSchemaForm = (prefix, reason) => `The ${prefix}agent's \`output\` schema has no JSON Schema form (${reason}). ` +
|
|
68
|
+
jsonSchemaAdvice;
|
|
69
|
+
export const outputNotAnObject = (prefix) => `The ${prefix}agent's \`output\` schema is not an object with named fields: ` +
|
|
70
|
+
"the model fills it in as a tool's parameters. Wrap it, such as " +
|
|
71
|
+
'`z.object({ items: z.array(...) })`.';
|
|
72
|
+
export const structuredOutputMissing = (prefix) => `The ${prefix}agent's model replied without the requested structured output.`;
|
|
73
|
+
export const structuredOutputInvalid = (prefix, reason) => `The ${prefix}agent's model replied with an output that does not match ` +
|
|
74
|
+
`the schema: ${reason}`;
|
|
75
|
+
export const structuredOutputMultiple = (prefix, count) => `The ${prefix}agent's model replied with ${count} outputs instead of one.`;
|
|
66
76
|
export const unknownTool = () => 'not a tool of this agent';
|
|
77
|
+
// LangChain's answer to a tool the agent does not have, restated:
|
|
78
|
+
// `getInvalidToolError` is not exported. See #264.
|
|
79
|
+
export const invalidTool = (tool, tools) => `Error: ${tool} is not a valid tool, try one of [${tools.join(', ')}].`;
|
|
80
|
+
export const toolNotRun = (tool) => `Error: '${tool}' was not run: it came with the final answer. ` +
|
|
81
|
+
'Call it on its own first if it is needed.';
|
|
67
82
|
//# sourceMappingURL=messages.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../lib/errors/messages.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAElE,4EAA4E;AAC5E,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAa,EAAU,EAAE,CACnD,KAAK,KAAK,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC;AAE7C,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAAc,EAAE,QAAkB,EAAU,EAAE,CACzE,0BAA0B,QAAQ,CAAC,MAAM,GAAG;IAC5C,UAAU,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG;IAC7C,yBAAyB,MAAM,UAAU;IACzC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEzD,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAa,EAAU,EAAE,CACtD,GAAG,KAAK,mEAAmE;IAC3E,0EAA0E,CAAC;AAE7E,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,KAAa,EAAU,EAAE,CAC7D,GAAG,KAAK,qEAAqE;IAC7E,8DAA8D,CAAC;AAEjE,MAAM,CAAC,MAAM,0BAA0B,GAAG,CACxC,KAAa,EACb,KAAa,EACL,EAAE,CACV,GAAG,KAAK,uDAAuD,KAAK,GAAG;IACvE,2EAA2E;IAC3E,+CAA+C,CAAC;AAElD,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,KAAa,EAAU,EAAE,CAC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gEAAgE;IAC7E,iEAAiE;IACjE,sCAAsC,CAAC;AAEzC,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,MAAc,EAAU,EAAE,CAChE,OAAO,MAAM,gEAAgE,CAAC;AAEhF,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,MAAc,EACd,MAAc,EACN,EAAE,CACV,OAAO,MAAM,2DAA2D;IACxE,eAAe,MAAM,EAAE,CAAC;AAE1B,MAAM,CAAC,MAAM,wBAAwB,GAAG,CACtC,MAAc,EACd,KAAa,EACL,EAAE,CACV,OAAO,MAAM,8BAA8B,KAAK,0BAA0B,CAAC;AAE7E,MAAM,CAAC,MAAM,WAAW,GAAG,GAAW,EAAE,CAAC,0BAA0B,CAAC;AAEpE,kEAAkE;AAClE,mDAAmD;AACnD,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAY,EAAE,KAAe,EAAU,EAAE,CACnE,UAAU,IAAI,qCAAqC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;AAE1E,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAY,EAAU,EAAE,CACjD,WAAW,IAAI,gDAAgD;IAC/D,2CAA2C,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { AgentRunError } from './agent-run.error.js';
|
|
2
|
+
/**
|
|
3
|
+
* The model's answer to a run with an `output` schema never came, or does not
|
|
4
|
+
* match the schema. LangChain's or Zod's error, if any, is in `cause`.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* try {
|
|
9
|
+
* const { output } = await agent.run(ticket, { output: Classification });
|
|
10
|
+
* } catch (error) {
|
|
11
|
+
* if (error instanceof StructuredOutputError) {
|
|
12
|
+
* console.error(error.message, error.cause);
|
|
13
|
+
* }
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare class StructuredOutputError extends AgentRunError {
|
|
18
|
+
constructor(message: string, agent: string, options?: {
|
|
19
|
+
cause?: unknown;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=structured-output.error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"structured-output.error.d.ts","sourceRoot":"","sources":["../../lib/errors/structured-output.error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD;;;;;;;;;;;;;;GAcG;AACH,qBAAa,qBAAsB,SAAQ,aAAa;gBAC1C,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAI1E"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AgentRunError } from './agent-run.error.js';
|
|
2
|
+
/**
|
|
3
|
+
* The model's answer to a run with an `output` schema never came, or does not
|
|
4
|
+
* match the schema. LangChain's or Zod's error, if any, is in `cause`.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* try {
|
|
9
|
+
* const { output } = await agent.run(ticket, { output: Classification });
|
|
10
|
+
* } catch (error) {
|
|
11
|
+
* if (error instanceof StructuredOutputError) {
|
|
12
|
+
* console.error(error.message, error.cause);
|
|
13
|
+
* }
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export class StructuredOutputError extends AgentRunError {
|
|
18
|
+
constructor(message, agent, options) {
|
|
19
|
+
super(message, agent, options);
|
|
20
|
+
this.name = 'StructuredOutputError';
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=structured-output.error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"structured-output.error.js","sourceRoot":"","sources":["../../lib/errors/structured-output.error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,qBAAsB,SAAQ,aAAa;IACtD,YAAY,OAAe,EAAE,KAAa,EAAE,OAA6B;QACvE,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The error as thrown, without the `MiddlewareError` LangChain wraps it in at
|
|
3
|
+
* each `wrapModelCall` middleware it crosses, a provider error included.
|
|
4
|
+
*
|
|
5
|
+
* @internal
|
|
6
|
+
* @param error What the agent's graph threw.
|
|
7
|
+
* @returns The innermost error.
|
|
8
|
+
*/
|
|
9
|
+
export declare const unwrapMiddlewareError: (error: unknown) => unknown;
|
|
10
|
+
//# sourceMappingURL=unwrap-middleware-error.util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unwrap-middleware-error.util.d.ts","sourceRoot":"","sources":["../../lib/errors/unwrap-middleware-error.util.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,GAAI,OAAO,OAAO,KAAG,OAQtD,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { MiddlewareError } from 'langchain';
|
|
2
|
+
/**
|
|
3
|
+
* The error as thrown, without the `MiddlewareError` LangChain wraps it in at
|
|
4
|
+
* each `wrapModelCall` middleware it crosses, a provider error included.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
* @param error What the agent's graph threw.
|
|
8
|
+
* @returns The innermost error.
|
|
9
|
+
*/
|
|
10
|
+
export const unwrapMiddlewareError = (error) => {
|
|
11
|
+
let unwrapped = error;
|
|
12
|
+
while (MiddlewareError.isInstance(unwrapped) && unwrapped.cause) {
|
|
13
|
+
unwrapped = unwrapped.cause;
|
|
14
|
+
}
|
|
15
|
+
return unwrapped;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=unwrap-middleware-error.util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unwrap-middleware-error.util.js","sourceRoot":"","sources":["../../lib/errors/unwrap-middleware-error.util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAE5C;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,KAAc,EAAW,EAAE;IAC/D,IAAI,SAAS,GAAG,KAAK,CAAC;IAEtB,OAAO,eAAe,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,SAAS,CAAC,KAAK,EAAE,CAAC;QAChE,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC;IAC9B,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export { LangChainModule } from './langchain.module.js';
|
|
2
2
|
export { getAgentToken } from './langchain.module-definition.js';
|
|
3
3
|
export { Agent } from './agent.js';
|
|
4
|
-
export { AgentRunError, ToolConfigurationError } from './errors/index.js';
|
|
4
|
+
export { AgentRunError, StructuredOutputError, ToolConfigurationError, } from './errors/index.js';
|
|
5
5
|
export { InjectAgent, Tool, ToolParam } from './decorators/index.js';
|
|
6
6
|
export type { ToolOptions, ToolParamOptions } from './decorators/index.js';
|
|
7
7
|
export type { AgentObserver, ModelErrorEvent, RunErrorEvent, RunFinishEvent, ToolEndEvent, ToolErrorEvent, ToolStartEvent, } from './interfaces/agent-observer.interface.js';
|
|
8
8
|
export type { CompletedRun } from './interfaces/completed-run.interface.js';
|
|
9
|
+
export type { RunOptions } from './interfaces/run-options.interface.js';
|
|
9
10
|
export type { AgentCallback, LangChainModuleOptions, LangChainOptionsFactory, ModelConfig, ModelOption, ToolModule, } from './interfaces/langchain-module-options.interface.js';
|
|
10
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EACL,aAAa,EACb,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACrE,YAAY,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC3E,YAAY,EACV,aAAa,EACb,eAAe,EACf,aAAa,EACb,cAAc,EACd,YAAY,EACZ,cAAc,EACd,cAAc,GACf,MAAM,0CAA0C,CAAC;AAClD,YAAY,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC;AAC5E,YAAY,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AACxE,YAAY,EACV,aAAa,EACb,sBAAsB,EACtB,uBAAuB,EACvB,WAAW,EACX,WAAW,EACX,UAAU,GACX,MAAM,oDAAoD,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
export { LangChainModule } from './langchain.module.js';
|
|
4
4
|
export { getAgentToken } from './langchain.module-definition.js';
|
|
5
5
|
export { Agent } from './agent.js';
|
|
6
|
-
export { AgentRunError, ToolConfigurationError } from './errors/index.js';
|
|
6
|
+
export { AgentRunError, StructuredOutputError, ToolConfigurationError, } from './errors/index.js';
|
|
7
7
|
export { InjectAgent, Tool, ToolParam } from './decorators/index.js';
|
|
8
8
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,uBAAuB;AACvB,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,uBAAuB;AACvB,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EACL,aAAa,EACb,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -6,7 +6,7 @@ import type { RunSummary } from '../run/index.js';
|
|
|
6
6
|
export interface CompletedRun<TOutput = string> extends RunSummary {
|
|
7
7
|
/** Always `'completed'`: a run that fails throws instead. */
|
|
8
8
|
status: 'completed';
|
|
9
|
-
/** The model's text answer. */
|
|
9
|
+
/** The model's text answer, or the object the run's `output` schema parsed. */
|
|
10
10
|
output: TOutput;
|
|
11
11
|
/** How long the run took. */
|
|
12
12
|
durationMs: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"completed-run.interface.d.ts","sourceRoot":"","sources":["../../lib/interfaces/completed-run.interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD;;;GAGG;AACH,MAAM,WAAW,YAAY,CAAC,OAAO,GAAG,MAAM,CAAE,SAAQ,UAAU;IAChE,6DAA6D;IAC7D,MAAM,EAAE,WAAW,CAAC;IACpB,+
|
|
1
|
+
{"version":3,"file":"completed-run.interface.d.ts","sourceRoot":"","sources":["../../lib/interfaces/completed-run.interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD;;;GAGG;AACH,MAAM,WAAW,YAAY,CAAC,OAAO,GAAG,MAAM,CAAE,SAAQ,UAAU;IAChE,6DAA6D;IAC7D,MAAM,EAAE,WAAW,CAAC;IACpB,+EAA+E;IAC/E,MAAM,EAAE,OAAO,CAAC;IAChB,6BAA6B;IAC7B,UAAU,EAAE,MAAM,CAAC;CACpB"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ZodType } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* The options of one run. Passed inline, they type `output` from the schema;
|
|
4
|
+
* typed `RunOptions`, `output` is `unknown`.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* const { output } = await agent.run(email, { output: Ticket }); // a Ticket
|
|
9
|
+
*
|
|
10
|
+
* const ask = (question: string, options?: RunOptions) =>
|
|
11
|
+
* agent.run(question, options); // `output` is unknown
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export interface RunOptions {
|
|
15
|
+
/**
|
|
16
|
+
* The schema the answer must match. `output` is then the object it parses,
|
|
17
|
+
* typed from it, instead of the model's text.
|
|
18
|
+
*/
|
|
19
|
+
output?: ZodType;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=run-options.interface.d.ts.map
|