@librechat/agents 2.4.322 → 3.0.0-rc1
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/dist/cjs/agents/AgentContext.cjs +218 -0
- package/dist/cjs/agents/AgentContext.cjs.map +1 -0
- package/dist/cjs/common/enum.cjs +14 -5
- package/dist/cjs/common/enum.cjs.map +1 -1
- package/dist/cjs/events.cjs +10 -6
- package/dist/cjs/events.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +309 -212
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs +322 -0
- package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -0
- package/dist/cjs/llm/anthropic/index.cjs +54 -9
- package/dist/cjs/llm/anthropic/index.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/types.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +52 -6
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs +22 -2
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/tools.cjs +29 -0
- package/dist/cjs/llm/anthropic/utils/tools.cjs.map +1 -0
- package/dist/cjs/llm/google/index.cjs +144 -0
- package/dist/cjs/llm/google/index.cjs.map +1 -0
- package/dist/cjs/llm/google/utils/common.cjs +477 -0
- package/dist/cjs/llm/google/utils/common.cjs.map +1 -0
- package/dist/cjs/llm/ollama/index.cjs +67 -0
- package/dist/cjs/llm/ollama/index.cjs.map +1 -0
- package/dist/cjs/llm/ollama/utils.cjs +158 -0
- package/dist/cjs/llm/ollama/utils.cjs.map +1 -0
- package/dist/cjs/llm/openai/index.cjs +389 -3
- package/dist/cjs/llm/openai/index.cjs.map +1 -1
- package/dist/cjs/llm/openai/utils/index.cjs +672 -0
- package/dist/cjs/llm/openai/utils/index.cjs.map +1 -0
- package/dist/cjs/llm/providers.cjs +15 -15
- package/dist/cjs/llm/providers.cjs.map +1 -1
- package/dist/cjs/llm/text.cjs +14 -3
- package/dist/cjs/llm/text.cjs.map +1 -1
- package/dist/cjs/llm/vertexai/index.cjs +330 -0
- package/dist/cjs/llm/vertexai/index.cjs.map +1 -0
- package/dist/cjs/main.cjs +11 -0
- package/dist/cjs/main.cjs.map +1 -1
- package/dist/cjs/run.cjs +120 -81
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/stream.cjs +85 -51
- package/dist/cjs/stream.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +10 -4
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/handlers.cjs +119 -13
- package/dist/cjs/tools/handlers.cjs.map +1 -1
- package/dist/cjs/tools/search/anthropic.cjs +40 -0
- package/dist/cjs/tools/search/anthropic.cjs.map +1 -0
- package/dist/cjs/tools/search/firecrawl.cjs +55 -9
- package/dist/cjs/tools/search/firecrawl.cjs.map +1 -1
- package/dist/cjs/tools/search/format.cjs +6 -6
- package/dist/cjs/tools/search/format.cjs.map +1 -1
- package/dist/cjs/tools/search/rerankers.cjs +7 -29
- package/dist/cjs/tools/search/rerankers.cjs.map +1 -1
- package/dist/cjs/tools/search/search.cjs +86 -16
- package/dist/cjs/tools/search/search.cjs.map +1 -1
- package/dist/cjs/tools/search/tool.cjs +4 -2
- package/dist/cjs/tools/search/tool.cjs.map +1 -1
- package/dist/cjs/tools/search/utils.cjs +1 -1
- package/dist/cjs/tools/search/utils.cjs.map +1 -1
- package/dist/cjs/utils/events.cjs +31 -0
- package/dist/cjs/utils/events.cjs.map +1 -0
- package/dist/cjs/utils/title.cjs +57 -21
- package/dist/cjs/utils/title.cjs.map +1 -1
- package/dist/cjs/utils/tokens.cjs +54 -7
- package/dist/cjs/utils/tokens.cjs.map +1 -1
- package/dist/esm/agents/AgentContext.mjs +216 -0
- package/dist/esm/agents/AgentContext.mjs.map +1 -0
- package/dist/esm/common/enum.mjs +15 -6
- package/dist/esm/common/enum.mjs.map +1 -1
- package/dist/esm/events.mjs +10 -6
- package/dist/esm/events.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +311 -214
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs +320 -0
- package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -0
- package/dist/esm/llm/anthropic/index.mjs +54 -9
- package/dist/esm/llm/anthropic/index.mjs.map +1 -1
- package/dist/esm/llm/anthropic/types.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs +52 -6
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/message_outputs.mjs +22 -2
- package/dist/esm/llm/anthropic/utils/message_outputs.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/tools.mjs +27 -0
- package/dist/esm/llm/anthropic/utils/tools.mjs.map +1 -0
- package/dist/esm/llm/google/index.mjs +142 -0
- package/dist/esm/llm/google/index.mjs.map +1 -0
- package/dist/esm/llm/google/utils/common.mjs +471 -0
- package/dist/esm/llm/google/utils/common.mjs.map +1 -0
- package/dist/esm/llm/ollama/index.mjs +65 -0
- package/dist/esm/llm/ollama/index.mjs.map +1 -0
- package/dist/esm/llm/ollama/utils.mjs +155 -0
- package/dist/esm/llm/ollama/utils.mjs.map +1 -0
- package/dist/esm/llm/openai/index.mjs +388 -4
- package/dist/esm/llm/openai/index.mjs.map +1 -1
- package/dist/esm/llm/openai/utils/index.mjs +666 -0
- package/dist/esm/llm/openai/utils/index.mjs.map +1 -0
- package/dist/esm/llm/providers.mjs +5 -5
- package/dist/esm/llm/providers.mjs.map +1 -1
- package/dist/esm/llm/text.mjs +14 -3
- package/dist/esm/llm/text.mjs.map +1 -1
- package/dist/esm/llm/vertexai/index.mjs +328 -0
- package/dist/esm/llm/vertexai/index.mjs.map +1 -0
- package/dist/esm/main.mjs +6 -5
- package/dist/esm/main.mjs.map +1 -1
- package/dist/esm/run.mjs +121 -83
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/stream.mjs +87 -54
- package/dist/esm/stream.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +10 -4
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/handlers.mjs +119 -15
- package/dist/esm/tools/handlers.mjs.map +1 -1
- package/dist/esm/tools/search/anthropic.mjs +37 -0
- package/dist/esm/tools/search/anthropic.mjs.map +1 -0
- package/dist/esm/tools/search/firecrawl.mjs +55 -9
- package/dist/esm/tools/search/firecrawl.mjs.map +1 -1
- package/dist/esm/tools/search/format.mjs +7 -7
- package/dist/esm/tools/search/format.mjs.map +1 -1
- package/dist/esm/tools/search/rerankers.mjs +7 -29
- package/dist/esm/tools/search/rerankers.mjs.map +1 -1
- package/dist/esm/tools/search/search.mjs +86 -16
- package/dist/esm/tools/search/search.mjs.map +1 -1
- package/dist/esm/tools/search/tool.mjs +4 -2
- package/dist/esm/tools/search/tool.mjs.map +1 -1
- package/dist/esm/tools/search/utils.mjs +1 -1
- package/dist/esm/tools/search/utils.mjs.map +1 -1
- package/dist/esm/utils/events.mjs +29 -0
- package/dist/esm/utils/events.mjs.map +1 -0
- package/dist/esm/utils/title.mjs +57 -22
- package/dist/esm/utils/title.mjs.map +1 -1
- package/dist/esm/utils/tokens.mjs +54 -8
- package/dist/esm/utils/tokens.mjs.map +1 -1
- package/dist/types/agents/AgentContext.d.ts +91 -0
- package/dist/types/common/enum.d.ts +15 -6
- package/dist/types/events.d.ts +5 -4
- package/dist/types/graphs/Graph.d.ts +64 -67
- package/dist/types/graphs/MultiAgentGraph.d.ts +37 -0
- package/dist/types/graphs/index.d.ts +1 -0
- package/dist/types/llm/anthropic/index.d.ts +11 -0
- package/dist/types/llm/anthropic/types.d.ts +9 -3
- package/dist/types/llm/anthropic/utils/message_inputs.d.ts +1 -1
- package/dist/types/llm/anthropic/utils/output_parsers.d.ts +4 -4
- package/dist/types/llm/anthropic/utils/tools.d.ts +3 -0
- package/dist/types/llm/google/index.d.ts +13 -0
- package/dist/types/llm/google/types.d.ts +32 -0
- package/dist/types/llm/google/utils/common.d.ts +19 -0
- package/dist/types/llm/google/utils/tools.d.ts +10 -0
- package/dist/types/llm/google/utils/zod_to_genai_parameters.d.ts +14 -0
- package/dist/types/llm/ollama/index.d.ts +7 -0
- package/dist/types/llm/ollama/utils.d.ts +7 -0
- package/dist/types/llm/openai/index.d.ts +72 -3
- package/dist/types/llm/openai/types.d.ts +10 -0
- package/dist/types/llm/openai/utils/index.d.ts +20 -0
- package/dist/types/llm/text.d.ts +1 -1
- package/dist/types/llm/vertexai/index.d.ts +293 -0
- package/dist/types/messages/reducer.d.ts +9 -0
- package/dist/types/run.d.ts +19 -12
- package/dist/types/scripts/ant_web_search.d.ts +1 -0
- package/dist/types/scripts/args.d.ts +2 -1
- package/dist/types/scripts/handoff-test.d.ts +1 -0
- package/dist/types/scripts/multi-agent-conditional.d.ts +1 -0
- package/dist/types/scripts/multi-agent-parallel.d.ts +1 -0
- package/dist/types/scripts/multi-agent-sequence.d.ts +1 -0
- package/dist/types/scripts/multi-agent-test.d.ts +1 -0
- package/dist/types/stream.d.ts +10 -3
- package/dist/types/tools/CodeExecutor.d.ts +2 -2
- package/dist/types/tools/ToolNode.d.ts +1 -1
- package/dist/types/tools/handlers.d.ts +17 -4
- package/dist/types/tools/search/anthropic.d.ts +16 -0
- package/dist/types/tools/search/firecrawl.d.ts +15 -0
- package/dist/types/tools/search/rerankers.d.ts +0 -1
- package/dist/types/tools/search/types.d.ts +30 -9
- package/dist/types/types/graph.d.ts +95 -15
- package/dist/types/types/llm.d.ts +24 -10
- package/dist/types/types/run.d.ts +46 -8
- package/dist/types/types/stream.d.ts +16 -2
- package/dist/types/types/tools.d.ts +1 -1
- package/dist/types/utils/events.d.ts +6 -0
- package/dist/types/utils/title.d.ts +2 -1
- package/dist/types/utils/tokens.d.ts +24 -0
- package/package.json +33 -17
- package/src/agents/AgentContext.ts +315 -0
- package/src/common/enum.ts +14 -5
- package/src/events.ts +24 -13
- package/src/graphs/Graph.ts +495 -312
- package/src/graphs/MultiAgentGraph.ts +381 -0
- package/src/graphs/index.ts +2 -1
- package/src/llm/anthropic/Jacob_Lee_Resume_2023.pdf +0 -0
- package/src/llm/anthropic/index.ts +78 -13
- package/src/llm/anthropic/llm.spec.ts +491 -115
- package/src/llm/anthropic/types.ts +39 -3
- package/src/llm/anthropic/utils/message_inputs.ts +67 -11
- package/src/llm/anthropic/utils/message_outputs.ts +21 -2
- package/src/llm/anthropic/utils/output_parsers.ts +25 -6
- package/src/llm/anthropic/utils/tools.ts +29 -0
- package/src/llm/google/index.ts +218 -0
- package/src/llm/google/types.ts +43 -0
- package/src/llm/google/utils/common.ts +646 -0
- package/src/llm/google/utils/tools.ts +160 -0
- package/src/llm/google/utils/zod_to_genai_parameters.ts +86 -0
- package/src/llm/ollama/index.ts +89 -0
- package/src/llm/ollama/utils.ts +193 -0
- package/src/llm/openai/index.ts +600 -14
- package/src/llm/openai/types.ts +24 -0
- package/src/llm/openai/utils/index.ts +912 -0
- package/src/llm/openai/utils/isReasoningModel.test.ts +90 -0
- package/src/llm/providers.ts +10 -9
- package/src/llm/text.ts +26 -7
- package/src/llm/vertexai/index.ts +360 -0
- package/src/messages/reducer.ts +80 -0
- package/src/run.ts +181 -112
- package/src/scripts/ant_web_search.ts +158 -0
- package/src/scripts/args.ts +12 -8
- package/src/scripts/cli4.ts +29 -21
- package/src/scripts/cli5.ts +29 -21
- package/src/scripts/code_exec.ts +54 -23
- package/src/scripts/code_exec_files.ts +48 -17
- package/src/scripts/code_exec_simple.ts +46 -27
- package/src/scripts/handoff-test.ts +135 -0
- package/src/scripts/image.ts +52 -20
- package/src/scripts/multi-agent-conditional.ts +220 -0
- package/src/scripts/multi-agent-example-output.md +110 -0
- package/src/scripts/multi-agent-parallel.ts +337 -0
- package/src/scripts/multi-agent-sequence.ts +212 -0
- package/src/scripts/multi-agent-test.ts +186 -0
- package/src/scripts/search.ts +1 -9
- package/src/scripts/simple.ts +25 -10
- package/src/scripts/tools.ts +48 -18
- package/src/specs/anthropic.simple.test.ts +150 -34
- package/src/specs/azure.simple.test.ts +325 -0
- package/src/specs/openai.simple.test.ts +140 -33
- package/src/specs/openrouter.simple.test.ts +107 -0
- package/src/specs/prune.test.ts +4 -9
- package/src/specs/reasoning.test.ts +80 -44
- package/src/specs/token-memoization.test.ts +39 -0
- package/src/stream.test.ts +94 -0
- package/src/stream.ts +139 -60
- package/src/tools/ToolNode.ts +21 -7
- package/src/tools/handlers.ts +192 -18
- package/src/tools/search/anthropic.ts +51 -0
- package/src/tools/search/firecrawl.ts +69 -20
- package/src/tools/search/format.ts +6 -8
- package/src/tools/search/rerankers.ts +7 -40
- package/src/tools/search/search.ts +97 -16
- package/src/tools/search/tool.ts +5 -2
- package/src/tools/search/types.ts +30 -10
- package/src/tools/search/utils.ts +1 -1
- package/src/types/graph.ts +272 -103
- package/src/types/llm.ts +25 -12
- package/src/types/run.ts +51 -13
- package/src/types/stream.ts +22 -1
- package/src/types/tools.ts +16 -10
- package/src/utils/events.ts +32 -0
- package/src/utils/llmConfig.ts +19 -7
- package/src/utils/title.ts +104 -30
- package/src/utils/tokens.ts +69 -10
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { ChatGoogle } from '@langchain/google-gauth';
|
|
2
|
+
import type { GoogleAIModelRequestParams, GoogleAbstractedClient } from '@langchain/google-common';
|
|
3
|
+
import type { VertexAIClientOptions } from '@/types';
|
|
4
|
+
/**
|
|
5
|
+
* Integration with Google Vertex AI chat models.
|
|
6
|
+
*
|
|
7
|
+
* Setup:
|
|
8
|
+
* Install `@langchain/google-vertexai` and set your stringified
|
|
9
|
+
* Vertex AI credentials as an environment variable named `GOOGLE_APPLICATION_CREDENTIALS`.
|
|
10
|
+
*
|
|
11
|
+
* ```bash
|
|
12
|
+
* npm install @langchain/google-vertexai
|
|
13
|
+
* export GOOGLE_APPLICATION_CREDENTIALS="path/to/credentials"
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* ## [Constructor args](https://api.js.langchain.com/classes/_langchain_google_vertexai.index.ChatVertexAI.html#constructor.new_ChatVertexAI)
|
|
17
|
+
*
|
|
18
|
+
* ## [Runtime args](https://api.js.langchain.com/interfaces/langchain_google_common_types.GoogleAIBaseLanguageModelCallOptions.html)
|
|
19
|
+
*
|
|
20
|
+
* Runtime args can be passed as the second argument to any of the base runnable methods `.invoke`. `.stream`, `.batch`, etc.
|
|
21
|
+
* They can also be passed via `.withConfig`, or the second arg in `.bindTools`, like shown in the examples below:
|
|
22
|
+
*
|
|
23
|
+
* ```typescript
|
|
24
|
+
* // When calling `.withConfig`, call options should be passed via the first argument
|
|
25
|
+
* const llmWithArgsBound = llm.withConfig({
|
|
26
|
+
* stop: ["\n"],
|
|
27
|
+
* tools: [...],
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* // When calling `.bindTools`, call options should be passed via the second argument
|
|
31
|
+
* const llmWithTools = llm.bindTools(
|
|
32
|
+
* [...],
|
|
33
|
+
* {
|
|
34
|
+
* tool_choice: "auto",
|
|
35
|
+
* }
|
|
36
|
+
* );
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* ## Examples
|
|
40
|
+
*
|
|
41
|
+
* <details open>
|
|
42
|
+
* <summary><strong>Instantiate</strong></summary>
|
|
43
|
+
*
|
|
44
|
+
* ```typescript
|
|
45
|
+
* import { ChatVertexAI } from '@langchain/google-vertexai';
|
|
46
|
+
*
|
|
47
|
+
* const llm = new ChatVertexAI({
|
|
48
|
+
* model: "gemini-1.5-pro",
|
|
49
|
+
* temperature: 0,
|
|
50
|
+
* // other params...
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
53
|
+
* </details>
|
|
54
|
+
*
|
|
55
|
+
* <br />
|
|
56
|
+
*
|
|
57
|
+
* <details>
|
|
58
|
+
* <summary><strong>Invoking</strong></summary>
|
|
59
|
+
*
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const input = `Translate "I love programming" into French.`;
|
|
62
|
+
*
|
|
63
|
+
* // Models also accept a list of chat messages or a formatted prompt
|
|
64
|
+
* const result = await llm.invoke(input);
|
|
65
|
+
* console.log(result);
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* ```txt
|
|
69
|
+
* AIMessageChunk {
|
|
70
|
+
* "content": "\"J'adore programmer\" \n\nHere's why this is the best translation:\n\n* **J'adore** means \"I love\" and conveys a strong passion.\n* **Programmer** is the French verb for \"to program.\"\n\nThis translation is natural and idiomatic in French. \n",
|
|
71
|
+
* "additional_kwargs": {},
|
|
72
|
+
* "response_metadata": {},
|
|
73
|
+
* "tool_calls": [],
|
|
74
|
+
* "tool_call_chunks": [],
|
|
75
|
+
* "invalid_tool_calls": [],
|
|
76
|
+
* "usage_metadata": {
|
|
77
|
+
* "input_tokens": 9,
|
|
78
|
+
* "output_tokens": 63,
|
|
79
|
+
* "total_tokens": 72
|
|
80
|
+
* }
|
|
81
|
+
* }
|
|
82
|
+
* ```
|
|
83
|
+
* </details>
|
|
84
|
+
*
|
|
85
|
+
* <br />
|
|
86
|
+
*
|
|
87
|
+
* <details>
|
|
88
|
+
* <summary><strong>Streaming Chunks</strong></summary>
|
|
89
|
+
*
|
|
90
|
+
* ```typescript
|
|
91
|
+
* for await (const chunk of await llm.stream(input)) {
|
|
92
|
+
* console.log(chunk);
|
|
93
|
+
* }
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* ```txt
|
|
97
|
+
* AIMessageChunk {
|
|
98
|
+
* "content": "\"",
|
|
99
|
+
* "additional_kwargs": {},
|
|
100
|
+
* "response_metadata": {},
|
|
101
|
+
* "tool_calls": [],
|
|
102
|
+
* "tool_call_chunks": [],
|
|
103
|
+
* "invalid_tool_calls": []
|
|
104
|
+
* }
|
|
105
|
+
* AIMessageChunk {
|
|
106
|
+
* "content": "J'adore programmer\" \n",
|
|
107
|
+
* "additional_kwargs": {},
|
|
108
|
+
* "response_metadata": {},
|
|
109
|
+
* "tool_calls": [],
|
|
110
|
+
* "tool_call_chunks": [],
|
|
111
|
+
* "invalid_tool_calls": []
|
|
112
|
+
* }
|
|
113
|
+
* AIMessageChunk {
|
|
114
|
+
* "content": "",
|
|
115
|
+
* "additional_kwargs": {},
|
|
116
|
+
* "response_metadata": {},
|
|
117
|
+
* "tool_calls": [],
|
|
118
|
+
* "tool_call_chunks": [],
|
|
119
|
+
* "invalid_tool_calls": []
|
|
120
|
+
* }
|
|
121
|
+
* AIMessageChunk {
|
|
122
|
+
* "content": "",
|
|
123
|
+
* "additional_kwargs": {},
|
|
124
|
+
* "response_metadata": {
|
|
125
|
+
* "finishReason": "stop"
|
|
126
|
+
* },
|
|
127
|
+
* "tool_calls": [],
|
|
128
|
+
* "tool_call_chunks": [],
|
|
129
|
+
* "invalid_tool_calls": [],
|
|
130
|
+
* "usage_metadata": {
|
|
131
|
+
* "input_tokens": 9,
|
|
132
|
+
* "output_tokens": 8,
|
|
133
|
+
* "total_tokens": 17
|
|
134
|
+
* }
|
|
135
|
+
* }
|
|
136
|
+
* ```
|
|
137
|
+
* </details>
|
|
138
|
+
*
|
|
139
|
+
* <br />
|
|
140
|
+
*
|
|
141
|
+
* <details>
|
|
142
|
+
* <summary><strong>Aggregate Streamed Chunks</strong></summary>
|
|
143
|
+
*
|
|
144
|
+
* ```typescript
|
|
145
|
+
* import { AIMessageChunk } from '@langchain/core/messages';
|
|
146
|
+
* import { concat } from '@langchain/core/utils/stream';
|
|
147
|
+
*
|
|
148
|
+
* const stream = await llm.stream(input);
|
|
149
|
+
* let full: AIMessageChunk | undefined;
|
|
150
|
+
* for await (const chunk of stream) {
|
|
151
|
+
* full = !full ? chunk : concat(full, chunk);
|
|
152
|
+
* }
|
|
153
|
+
* console.log(full);
|
|
154
|
+
* ```
|
|
155
|
+
*
|
|
156
|
+
* ```txt
|
|
157
|
+
* AIMessageChunk {
|
|
158
|
+
* "content": "\"J'adore programmer\" \n",
|
|
159
|
+
* "additional_kwargs": {},
|
|
160
|
+
* "response_metadata": {
|
|
161
|
+
* "finishReason": "stop"
|
|
162
|
+
* },
|
|
163
|
+
* "tool_calls": [],
|
|
164
|
+
* "tool_call_chunks": [],
|
|
165
|
+
* "invalid_tool_calls": [],
|
|
166
|
+
* "usage_metadata": {
|
|
167
|
+
* "input_tokens": 9,
|
|
168
|
+
* "output_tokens": 8,
|
|
169
|
+
* "total_tokens": 17
|
|
170
|
+
* }
|
|
171
|
+
* }
|
|
172
|
+
* ```
|
|
173
|
+
* </details>
|
|
174
|
+
*
|
|
175
|
+
* <br />
|
|
176
|
+
*
|
|
177
|
+
* <details>
|
|
178
|
+
* <summary><strong>Bind tools</strong></summary>
|
|
179
|
+
*
|
|
180
|
+
* ```typescript
|
|
181
|
+
* import { z } from 'zod';
|
|
182
|
+
*
|
|
183
|
+
* const GetWeather = {
|
|
184
|
+
* name: "GetWeather",
|
|
185
|
+
* description: "Get the current weather in a given location",
|
|
186
|
+
* schema: z.object({
|
|
187
|
+
* location: z.string().describe("The city and state, e.g. San Francisco, CA")
|
|
188
|
+
* }),
|
|
189
|
+
* }
|
|
190
|
+
*
|
|
191
|
+
* const GetPopulation = {
|
|
192
|
+
* name: "GetPopulation",
|
|
193
|
+
* description: "Get the current population in a given location",
|
|
194
|
+
* schema: z.object({
|
|
195
|
+
* location: z.string().describe("The city and state, e.g. San Francisco, CA")
|
|
196
|
+
* }),
|
|
197
|
+
* }
|
|
198
|
+
*
|
|
199
|
+
* const llmWithTools = llm.bindTools([GetWeather, GetPopulation]);
|
|
200
|
+
* const aiMsg = await llmWithTools.invoke(
|
|
201
|
+
* "Which city is hotter today and which is bigger: LA or NY?"
|
|
202
|
+
* );
|
|
203
|
+
* console.log(aiMsg.tool_calls);
|
|
204
|
+
* ```
|
|
205
|
+
*
|
|
206
|
+
* ```txt
|
|
207
|
+
* [
|
|
208
|
+
* {
|
|
209
|
+
* name: 'GetPopulation',
|
|
210
|
+
* args: { location: 'New York City, NY' },
|
|
211
|
+
* id: '33c1c1f47e2f492799c77d2800a43912',
|
|
212
|
+
* type: 'tool_call'
|
|
213
|
+
* }
|
|
214
|
+
* ]
|
|
215
|
+
* ```
|
|
216
|
+
* </details>
|
|
217
|
+
*
|
|
218
|
+
* <br />
|
|
219
|
+
*
|
|
220
|
+
* <details>
|
|
221
|
+
* <summary><strong>Structured Output</strong></summary>
|
|
222
|
+
*
|
|
223
|
+
* ```typescript
|
|
224
|
+
* import { z } from 'zod';
|
|
225
|
+
*
|
|
226
|
+
* const Joke = z.object({
|
|
227
|
+
* setup: z.string().describe("The setup of the joke"),
|
|
228
|
+
* punchline: z.string().describe("The punchline to the joke"),
|
|
229
|
+
* rating: z.number().optional().describe("How funny the joke is, from 1 to 10")
|
|
230
|
+
* }).describe('Joke to tell user.');
|
|
231
|
+
*
|
|
232
|
+
* const structuredLlm = llm.withStructuredOutput(Joke, { name: "Joke" });
|
|
233
|
+
* const jokeResult = await structuredLlm.invoke("Tell me a joke about cats");
|
|
234
|
+
* console.log(jokeResult);
|
|
235
|
+
* ```
|
|
236
|
+
*
|
|
237
|
+
* ```txt
|
|
238
|
+
* {
|
|
239
|
+
* setup: 'What do you call a cat that loves to bowl?',
|
|
240
|
+
* punchline: 'An alley cat!'
|
|
241
|
+
* }
|
|
242
|
+
* ```
|
|
243
|
+
* </details>
|
|
244
|
+
*
|
|
245
|
+
* <br />
|
|
246
|
+
*
|
|
247
|
+
* <details>
|
|
248
|
+
* <summary><strong>Usage Metadata</strong></summary>
|
|
249
|
+
*
|
|
250
|
+
* ```typescript
|
|
251
|
+
* const aiMsgForMetadata = await llm.invoke(input);
|
|
252
|
+
* console.log(aiMsgForMetadata.usage_metadata);
|
|
253
|
+
* ```
|
|
254
|
+
*
|
|
255
|
+
* ```txt
|
|
256
|
+
* { input_tokens: 9, output_tokens: 8, total_tokens: 17 }
|
|
257
|
+
* ```
|
|
258
|
+
* </details>
|
|
259
|
+
*
|
|
260
|
+
* <br />
|
|
261
|
+
*
|
|
262
|
+
* <details>
|
|
263
|
+
* <summary><strong>Stream Usage Metadata</strong></summary>
|
|
264
|
+
*
|
|
265
|
+
* ```typescript
|
|
266
|
+
* const streamForMetadata = await llm.stream(
|
|
267
|
+
* input,
|
|
268
|
+
* {
|
|
269
|
+
* streamUsage: true
|
|
270
|
+
* }
|
|
271
|
+
* );
|
|
272
|
+
* let fullForMetadata: AIMessageChunk | undefined;
|
|
273
|
+
* for await (const chunk of streamForMetadata) {
|
|
274
|
+
* fullForMetadata = !fullForMetadata ? chunk : concat(fullForMetadata, chunk);
|
|
275
|
+
* }
|
|
276
|
+
* console.log(fullForMetadata?.usage_metadata);
|
|
277
|
+
* ```
|
|
278
|
+
*
|
|
279
|
+
* ```txt
|
|
280
|
+
* { input_tokens: 9, output_tokens: 8, total_tokens: 17 }
|
|
281
|
+
* ```
|
|
282
|
+
* </details>
|
|
283
|
+
*
|
|
284
|
+
* <br />
|
|
285
|
+
*/
|
|
286
|
+
export declare class ChatVertexAI extends ChatGoogle {
|
|
287
|
+
lc_namespace: string[];
|
|
288
|
+
dynamicThinkingBudget: boolean;
|
|
289
|
+
static lc_name(): 'ChatVertexAI';
|
|
290
|
+
constructor(fields?: VertexAIClientOptions);
|
|
291
|
+
invocationParams(options?: this['ParsedCallOptions'] | undefined): GoogleAIModelRequestParams;
|
|
292
|
+
buildConnection(fields: VertexAIClientOptions, client: GoogleAbstractedClient): void;
|
|
293
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BaseMessage, BaseMessageLike } from '@langchain/core/messages';
|
|
2
|
+
export declare const REMOVE_ALL_MESSAGES = "__remove_all__";
|
|
3
|
+
export type Messages = Array<BaseMessage | BaseMessageLike> | BaseMessage | BaseMessageLike;
|
|
4
|
+
/**
|
|
5
|
+
* Prebuilt reducer that combines returned messages.
|
|
6
|
+
* Can handle standard messages and special modifiers like {@link RemoveMessage}
|
|
7
|
+
* instances.
|
|
8
|
+
*/
|
|
9
|
+
export declare function messagesStateReducer(left: Messages, right: Messages): BaseMessage[];
|
package/dist/types/run.d.ts
CHANGED
|
@@ -1,28 +1,35 @@
|
|
|
1
1
|
import type { BaseMessage, MessageContentComplex } from '@langchain/core/messages';
|
|
2
|
-
import type { ClientCallbacks, SystemCallbacks } from '@/graphs/Graph';
|
|
3
2
|
import type { RunnableConfig } from '@langchain/core/runnables';
|
|
4
3
|
import type * as t from '@/types';
|
|
5
|
-
import {
|
|
4
|
+
import { MultiAgentGraph } from '@/graphs/MultiAgentGraph';
|
|
6
5
|
import { StandardGraph } from '@/graphs/Graph';
|
|
7
|
-
export declare
|
|
8
|
-
|
|
9
|
-
private handlerRegistry;
|
|
6
|
+
export declare const defaultOmitOptions: Set<string>;
|
|
7
|
+
export declare class Run<_T extends t.BaseGraphState> {
|
|
10
8
|
id: string;
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
private tokenCounter?;
|
|
10
|
+
private handlerRegistry;
|
|
11
|
+
private indexTokenCountMap?;
|
|
12
|
+
graphRunnable?: t.CompiledStateWorkflow;
|
|
13
|
+
Graph: StandardGraph | MultiAgentGraph | undefined;
|
|
13
14
|
returnContent: boolean;
|
|
14
15
|
private constructor();
|
|
15
|
-
private
|
|
16
|
+
private createLegacyGraph;
|
|
17
|
+
private createMultiAgentGraph;
|
|
16
18
|
static create<T extends t.BaseGraphState>(config: t.RunConfig): Promise<Run<T>>;
|
|
17
19
|
getRunMessages(): BaseMessage[] | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Creates a custom event callback handler that intercepts custom events
|
|
22
|
+
* and processes them through our handler registry instead of EventStreamCallbackHandler
|
|
23
|
+
*/
|
|
24
|
+
private createCustomEventCallback;
|
|
18
25
|
processStream(inputs: t.IState, config: Partial<RunnableConfig> & {
|
|
19
26
|
version: 'v1' | 'v2';
|
|
20
27
|
run_id?: string;
|
|
21
28
|
}, streamOptions?: t.EventStreamOptions): Promise<MessageContentComplex[] | undefined>;
|
|
22
29
|
private createSystemCallback;
|
|
23
|
-
getCallbacks(clientCallbacks: ClientCallbacks): SystemCallbacks;
|
|
24
|
-
generateTitle({ inputText, contentParts, titlePrompt, clientOptions, chainOptions, skipLanguage, }: t.RunTitleOptions): Promise<{
|
|
25
|
-
language
|
|
26
|
-
title
|
|
30
|
+
getCallbacks(clientCallbacks: t.ClientCallbacks): t.SystemCallbacks;
|
|
31
|
+
generateTitle({ provider, inputText, contentParts, titlePrompt, clientOptions, chainOptions, skipLanguage, titleMethod, titlePromptTemplate, }: t.RunTitleOptions): Promise<{
|
|
32
|
+
language?: string;
|
|
33
|
+
title?: string;
|
|
27
34
|
}>;
|
|
28
35
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types/stream.d.ts
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import type { AIMessageChunk } from '@langchain/core/messages';
|
|
2
|
-
import type {
|
|
2
|
+
import type { AgentContext } from '@/agents/AgentContext';
|
|
3
|
+
import type { StandardGraph } from '@/graphs';
|
|
3
4
|
import type * as t from '@/types';
|
|
5
|
+
import { Providers } from '@/common';
|
|
6
|
+
export declare function getChunkContent({ chunk, provider, reasoningKey, }: {
|
|
7
|
+
chunk?: Partial<AIMessageChunk>;
|
|
8
|
+
provider?: Providers;
|
|
9
|
+
reasoningKey: 'reasoning_content' | 'reasoning';
|
|
10
|
+
}): string | t.MessageContentComplex[] | undefined;
|
|
4
11
|
export declare class ChatModelStreamHandler implements t.EventHandler {
|
|
5
|
-
handle(event: string, data: t.StreamEventData, metadata?: Record<string, unknown>, graph?:
|
|
6
|
-
handleReasoning(chunk: Partial<AIMessageChunk>,
|
|
12
|
+
handle(event: string, data: t.StreamEventData, metadata?: Record<string, unknown>, graph?: StandardGraph): Promise<void>;
|
|
13
|
+
handleReasoning(chunk: Partial<AIMessageChunk>, agentContext: AgentContext): void;
|
|
7
14
|
}
|
|
8
15
|
export declare function createContentAggregator(): t.ContentAggregatorResult;
|
|
@@ -10,12 +10,12 @@ declare const CodeExecutionToolSchema: z.ZodObject<{
|
|
|
10
10
|
args: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
11
11
|
}, "strip", z.ZodTypeAny, {
|
|
12
12
|
code: string;
|
|
13
|
-
lang: "r" | "py" | "js" | "ts" | "c" | "cpp" | "java" | "php" | "rs" | "go" | "
|
|
13
|
+
lang: "r" | "d" | "py" | "js" | "ts" | "c" | "cpp" | "java" | "php" | "rs" | "go" | "f90";
|
|
14
14
|
args?: string[] | undefined;
|
|
15
15
|
session_id?: string | undefined;
|
|
16
16
|
}, {
|
|
17
17
|
code: string;
|
|
18
|
-
lang: "r" | "py" | "js" | "ts" | "c" | "cpp" | "java" | "php" | "rs" | "go" | "
|
|
18
|
+
lang: "r" | "d" | "py" | "js" | "ts" | "c" | "cpp" | "java" | "php" | "rs" | "go" | "f90";
|
|
19
19
|
args?: string[] | undefined;
|
|
20
20
|
session_id?: string | undefined;
|
|
21
21
|
}>;
|
|
@@ -19,4 +19,4 @@ export declare class ToolNode<T = any> extends RunnableCallable<T, T> {
|
|
|
19
19
|
getToolUsageCounts(): ReadonlyMap<string, number>;
|
|
20
20
|
protected run(input: any, config: RunnableConfig): Promise<T>;
|
|
21
21
|
}
|
|
22
|
-
export declare function toolsCondition(state: BaseMessage[] | typeof MessagesAnnotation.State):
|
|
22
|
+
export declare function toolsCondition<T extends string>(state: BaseMessage[] | typeof MessagesAnnotation.State, toolNode: T, invokedToolIds?: Set<string>): T | typeof END;
|
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
import type { ToolCall, ToolCallChunk } from '@langchain/core/messages/tool';
|
|
2
|
-
import type {
|
|
2
|
+
import type { MultiAgentGraph, StandardGraph } from '@/graphs';
|
|
3
|
+
import type { AgentContext } from '@/agents/AgentContext';
|
|
4
|
+
import type * as t from '@/types';
|
|
3
5
|
export declare function handleToolCallChunks({ graph, stepKey, toolCallChunks, }: {
|
|
4
|
-
graph:
|
|
6
|
+
graph: StandardGraph | MultiAgentGraph;
|
|
5
7
|
stepKey: string;
|
|
6
8
|
toolCallChunks: ToolCallChunk[];
|
|
7
|
-
}): void
|
|
8
|
-
export declare const handleToolCalls: (toolCalls?: ToolCall[], metadata?: Record<string, unknown>, graph?:
|
|
9
|
+
}): Promise<void>;
|
|
10
|
+
export declare const handleToolCalls: (toolCalls?: ToolCall[], metadata?: Record<string, unknown>, graph?: StandardGraph | MultiAgentGraph) => Promise<void>;
|
|
11
|
+
export declare const toolResultTypes: Set<string>;
|
|
12
|
+
/**
|
|
13
|
+
* Handles the result of a server tool call; in other words, a provider's built-in tool.
|
|
14
|
+
* As of 2025-07-06, only Anthropic handles server tool calls with this pattern.
|
|
15
|
+
*/
|
|
16
|
+
export declare function handleServerToolResult({ graph, content, metadata, agentContext, }: {
|
|
17
|
+
graph: StandardGraph | MultiAgentGraph;
|
|
18
|
+
content?: string | t.MessageContentComplex[];
|
|
19
|
+
metadata?: Record<string, unknown>;
|
|
20
|
+
agentContext?: AgentContext;
|
|
21
|
+
}): Promise<boolean>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AnthropicTextBlockParam, AnthropicWebSearchResultBlockParam } from '@/llm/anthropic/types';
|
|
2
|
+
import type { SearchResultData } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Coerces Anthropic web search results to the SearchResultData format
|
|
5
|
+
* @param results - Array of Anthropic web search results
|
|
6
|
+
* @param turn - The turn number to associate with these results
|
|
7
|
+
* @returns SearchResultData with minimal ProcessedOrganic items
|
|
8
|
+
*/
|
|
9
|
+
export declare function coerceAnthropicSearchResults({ results, turn, }: {
|
|
10
|
+
results: (AnthropicTextBlockParam | AnthropicWebSearchResultBlockParam)[];
|
|
11
|
+
turn?: number;
|
|
12
|
+
}): SearchResultData;
|
|
13
|
+
/**
|
|
14
|
+
* Helper function to check if an object is an Anthropic web search result
|
|
15
|
+
*/
|
|
16
|
+
export declare function isAnthropicWebSearchResult(obj: unknown): obj is AnthropicWebSearchResultBlockParam;
|
|
@@ -9,6 +9,21 @@ export declare class FirecrawlScraper {
|
|
|
9
9
|
private defaultFormats;
|
|
10
10
|
private timeout;
|
|
11
11
|
private logger;
|
|
12
|
+
private includeTags?;
|
|
13
|
+
private excludeTags?;
|
|
14
|
+
private waitFor?;
|
|
15
|
+
private maxAge?;
|
|
16
|
+
private mobile?;
|
|
17
|
+
private skipTlsVerification?;
|
|
18
|
+
private blockAds?;
|
|
19
|
+
private removeBase64Images?;
|
|
20
|
+
private parsePDF?;
|
|
21
|
+
private storeInCache?;
|
|
22
|
+
private zeroDataRetention?;
|
|
23
|
+
private headers?;
|
|
24
|
+
private location?;
|
|
25
|
+
private onlyMainContent?;
|
|
26
|
+
private changeTrackingOptions?;
|
|
12
27
|
constructor(config?: t.FirecrawlScraperConfig);
|
|
13
28
|
/**
|
|
14
29
|
* Scrape a single URL
|
|
@@ -5,7 +5,6 @@ export declare abstract class BaseReranker {
|
|
|
5
5
|
constructor(logger?: t.Logger);
|
|
6
6
|
abstract rerank(query: string, documents: string[], topK?: number): Promise<t.Highlight[]>;
|
|
7
7
|
protected getDefaultRanking(documents: string[], topK: number): t.Highlight[];
|
|
8
|
-
protected logDocumentSamples(documents: string[]): void;
|
|
9
8
|
}
|
|
10
9
|
export declare class JinaReranker extends BaseReranker {
|
|
11
10
|
constructor({ apiKey, logger, }: {
|
|
@@ -85,7 +85,7 @@ export interface ProcessSourcesConfig {
|
|
|
85
85
|
export interface FirecrawlConfig {
|
|
86
86
|
firecrawlApiKey?: string;
|
|
87
87
|
firecrawlApiUrl?: string;
|
|
88
|
-
|
|
88
|
+
firecrawlOptions?: FirecrawlScraperConfig;
|
|
89
89
|
}
|
|
90
90
|
export interface ScraperContentResult {
|
|
91
91
|
content: string;
|
|
@@ -132,6 +132,7 @@ export interface SearchToolConfig extends SearchConfig, ProcessSourcesConfig, Fi
|
|
|
132
132
|
jinaApiKey?: string;
|
|
133
133
|
cohereApiKey?: string;
|
|
134
134
|
rerankerType?: RerankerType;
|
|
135
|
+
scraperTimeout?: number;
|
|
135
136
|
onSearchResults?: (results: SearchResult, runnableConfig?: RunnableConfig) => void;
|
|
136
137
|
onGetHighlights?: (link: string) => void;
|
|
137
138
|
}
|
|
@@ -146,14 +147,7 @@ export type UsedReferences = {
|
|
|
146
147
|
reference: MediaReference;
|
|
147
148
|
}[];
|
|
148
149
|
/** Firecrawl */
|
|
149
|
-
export
|
|
150
|
-
formats?: string[];
|
|
151
|
-
includeTags?: string[];
|
|
152
|
-
excludeTags?: string[];
|
|
153
|
-
headers?: Record<string, string>;
|
|
154
|
-
waitFor?: number;
|
|
155
|
-
timeout?: number;
|
|
156
|
-
}
|
|
150
|
+
export type FirecrawlScrapeOptions = Omit<FirecrawlScraperConfig, 'apiKey' | 'apiUrl' | 'logger'>;
|
|
157
151
|
export interface ScrapeMetadata {
|
|
158
152
|
sourceURL?: string;
|
|
159
153
|
url?: string;
|
|
@@ -225,6 +219,24 @@ export interface FirecrawlScraperConfig {
|
|
|
225
219
|
formats?: string[];
|
|
226
220
|
timeout?: number;
|
|
227
221
|
logger?: Logger;
|
|
222
|
+
includeTags?: string[];
|
|
223
|
+
excludeTags?: string[];
|
|
224
|
+
waitFor?: number;
|
|
225
|
+
maxAge?: number;
|
|
226
|
+
mobile?: boolean;
|
|
227
|
+
skipTlsVerification?: boolean;
|
|
228
|
+
blockAds?: boolean;
|
|
229
|
+
removeBase64Images?: boolean;
|
|
230
|
+
parsePDF?: boolean;
|
|
231
|
+
storeInCache?: boolean;
|
|
232
|
+
zeroDataRetention?: boolean;
|
|
233
|
+
headers?: Record<string, string>;
|
|
234
|
+
location?: {
|
|
235
|
+
country?: string;
|
|
236
|
+
languages?: string[];
|
|
237
|
+
};
|
|
238
|
+
onlyMainContent?: boolean;
|
|
239
|
+
changeTrackingOptions?: object;
|
|
228
240
|
}
|
|
229
241
|
export type GetSourcesParams = {
|
|
230
242
|
query: string;
|
|
@@ -507,6 +519,15 @@ export interface SearXNGResult {
|
|
|
507
519
|
content?: string;
|
|
508
520
|
publishedDate?: string;
|
|
509
521
|
img_src?: string;
|
|
522
|
+
score?: number;
|
|
523
|
+
engine?: string;
|
|
524
|
+
category?: string;
|
|
525
|
+
thumbnail?: string;
|
|
526
|
+
priority?: string;
|
|
527
|
+
engines?: string[];
|
|
528
|
+
positions?: number[];
|
|
529
|
+
template?: string;
|
|
530
|
+
parsed_url?: string[];
|
|
510
531
|
}
|
|
511
532
|
export type ProcessSourcesFields = {
|
|
512
533
|
result: SearchResult;
|