@illuma-ai/agents 1.1.21 → 1.1.22
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/graphs/Graph.cjs +12 -1
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs +85 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
- package/dist/cjs/run.cjs +20 -9
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +12 -1
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs +85 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
- package/dist/esm/run.mjs +20 -9
- package/dist/esm/run.mjs.map +1 -1
- package/dist/types/graphs/MultiAgentGraph.d.ts +17 -0
- package/package.json +1 -1
- package/src/graphs/Graph.ts +12 -1
- package/src/graphs/MultiAgentGraph.ts +105 -1
- package/src/graphs/__tests__/multi-agent-delegate.test.ts +191 -0
- package/src/run.ts +20 -11
- package/src/scripts/test-bedrock-handoff-autonomous.ts +231 -0
- package/src/agents/AgentContext.js +0 -782
- package/src/agents/AgentContext.test.js +0 -421
- package/src/agents/__tests__/AgentContext.test.js +0 -678
- package/src/agents/__tests__/resolveStructuredOutputMode.test.js +0 -117
- package/src/common/enum.js +0 -192
- package/src/common/index.js +0 -3
- package/src/events.js +0 -166
- package/src/graphs/Graph.js +0 -1857
- package/src/graphs/MultiAgentGraph.js +0 -1092
- package/src/graphs/__tests__/structured-output.integration.test.js +0 -624
- package/src/graphs/__tests__/structured-output.test.js +0 -144
- package/src/graphs/contextManagement.e2e.test.js +0 -718
- package/src/graphs/contextManagement.test.js +0 -485
- package/src/graphs/handoffValidation.test.js +0 -276
- package/src/graphs/index.js +0 -3
- package/src/index.js +0 -28
- package/src/instrumentation.js +0 -21
- package/src/llm/anthropic/index.js +0 -319
- package/src/llm/anthropic/types.js +0 -46
- package/src/llm/anthropic/utils/message_inputs.js +0 -627
- package/src/llm/anthropic/utils/message_outputs.js +0 -290
- package/src/llm/anthropic/utils/output_parsers.js +0 -89
- package/src/llm/anthropic/utils/tools.js +0 -25
- package/src/llm/bedrock/__tests__/bedrock-caching.test.js +0 -392
- package/src/llm/bedrock/index.js +0 -303
- package/src/llm/bedrock/types.js +0 -2
- package/src/llm/bedrock/utils/index.js +0 -6
- package/src/llm/bedrock/utils/message_inputs.js +0 -463
- package/src/llm/bedrock/utils/message_outputs.js +0 -269
- package/src/llm/fake.js +0 -92
- package/src/llm/google/index.js +0 -215
- package/src/llm/google/types.js +0 -12
- package/src/llm/google/utils/common.js +0 -670
- package/src/llm/google/utils/tools.js +0 -111
- package/src/llm/google/utils/zod_to_genai_parameters.js +0 -47
- package/src/llm/openai/index.js +0 -1033
- package/src/llm/openai/types.js +0 -2
- package/src/llm/openai/utils/index.js +0 -756
- package/src/llm/openai/utils/isReasoningModel.test.js +0 -79
- package/src/llm/openrouter/index.js +0 -261
- package/src/llm/openrouter/reasoning.test.js +0 -181
- package/src/llm/providers.js +0 -36
- package/src/llm/text.js +0 -65
- package/src/llm/vertexai/index.js +0 -402
- package/src/messages/__tests__/tools.test.js +0 -392
- package/src/messages/cache.js +0 -404
- package/src/messages/cache.test.js +0 -1167
- package/src/messages/content.js +0 -48
- package/src/messages/content.test.js +0 -314
- package/src/messages/core.js +0 -359
- package/src/messages/ensureThinkingBlock.test.js +0 -997
- package/src/messages/format.js +0 -973
- package/src/messages/formatAgentMessages.test.js +0 -2278
- package/src/messages/formatAgentMessages.tools.test.js +0 -362
- package/src/messages/formatMessage.test.js +0 -608
- package/src/messages/ids.js +0 -18
- package/src/messages/index.js +0 -9
- package/src/messages/labelContentByAgent.test.js +0 -725
- package/src/messages/prune.js +0 -438
- package/src/messages/reducer.js +0 -60
- package/src/messages/shiftIndexTokenCountMap.test.js +0 -63
- package/src/messages/summarize.js +0 -146
- package/src/messages/summarize.test.js +0 -332
- package/src/messages/tools.js +0 -90
- package/src/mockStream.js +0 -81
- package/src/prompts/collab.js +0 -7
- package/src/prompts/index.js +0 -3
- package/src/prompts/taskmanager.js +0 -58
- package/src/run.js +0 -427
- package/src/schemas/index.js +0 -3
- package/src/schemas/schema-preparation.test.js +0 -370
- package/src/schemas/validate.js +0 -314
- package/src/schemas/validate.test.js +0 -264
- package/src/scripts/abort.js +0 -127
- package/src/scripts/ant_web_search.js +0 -130
- package/src/scripts/ant_web_search_edge_case.js +0 -133
- package/src/scripts/ant_web_search_error_edge_case.js +0 -119
- package/src/scripts/args.js +0 -41
- package/src/scripts/bedrock-cache-debug.js +0 -186
- package/src/scripts/bedrock-content-aggregation-test.js +0 -195
- package/src/scripts/bedrock-merge-test.js +0 -80
- package/src/scripts/bedrock-parallel-tools-test.js +0 -150
- package/src/scripts/caching.js +0 -106
- package/src/scripts/cli.js +0 -152
- package/src/scripts/cli2.js +0 -119
- package/src/scripts/cli3.js +0 -163
- package/src/scripts/cli4.js +0 -165
- package/src/scripts/cli5.js +0 -165
- package/src/scripts/code_exec.js +0 -171
- package/src/scripts/code_exec_files.js +0 -180
- package/src/scripts/code_exec_multi_session.js +0 -185
- package/src/scripts/code_exec_ptc.js +0 -265
- package/src/scripts/code_exec_session.js +0 -217
- package/src/scripts/code_exec_simple.js +0 -120
- package/src/scripts/content.js +0 -111
- package/src/scripts/empty_input.js +0 -125
- package/src/scripts/handoff-test.js +0 -96
- package/src/scripts/image.js +0 -138
- package/src/scripts/memory.js +0 -83
- package/src/scripts/multi-agent-chain.js +0 -271
- package/src/scripts/multi-agent-conditional.js +0 -185
- package/src/scripts/multi-agent-document-review-chain.js +0 -171
- package/src/scripts/multi-agent-hybrid-flow.js +0 -264
- package/src/scripts/multi-agent-parallel-start.js +0 -214
- package/src/scripts/multi-agent-parallel.js +0 -346
- package/src/scripts/multi-agent-sequence.js +0 -184
- package/src/scripts/multi-agent-supervisor.js +0 -324
- package/src/scripts/multi-agent-test.js +0 -147
- package/src/scripts/parallel-asymmetric-tools-test.js +0 -202
- package/src/scripts/parallel-full-metadata-test.js +0 -176
- package/src/scripts/parallel-tools-test.js +0 -256
- package/src/scripts/programmatic_exec.js +0 -277
- package/src/scripts/programmatic_exec_agent.js +0 -168
- package/src/scripts/search.js +0 -118
- package/src/scripts/sequential-full-metadata-test.js +0 -143
- package/src/scripts/simple.js +0 -174
- package/src/scripts/single-agent-metadata-test.js +0 -152
- package/src/scripts/stream.js +0 -113
- package/src/scripts/test-custom-prompt-key.js +0 -132
- package/src/scripts/test-handoff-input.js +0 -143
- package/src/scripts/test-handoff-preamble.js +0 -227
- package/src/scripts/test-handoff-steering.js +0 -353
- package/src/scripts/test-multi-agent-list-handoff.js +0 -318
- package/src/scripts/test-parallel-agent-labeling.js +0 -253
- package/src/scripts/test-parallel-handoffs.js +0 -229
- package/src/scripts/test-thinking-handoff-bedrock.js +0 -132
- package/src/scripts/test-thinking-handoff.js +0 -132
- package/src/scripts/test-thinking-to-thinking-handoff-bedrock.js +0 -140
- package/src/scripts/test-tool-before-handoff-role-order.js +0 -223
- package/src/scripts/test-tools-before-handoff.js +0 -187
- package/src/scripts/test_code_api.js +0 -263
- package/src/scripts/thinking-bedrock.js +0 -128
- package/src/scripts/thinking-vertexai.js +0 -130
- package/src/scripts/thinking.js +0 -134
- package/src/scripts/tool_search.js +0 -114
- package/src/scripts/tools.js +0 -125
- package/src/specs/agent-handoffs-bedrock.integration.test.js +0 -280
- package/src/specs/agent-handoffs.test.js +0 -924
- package/src/specs/anthropic.simple.test.js +0 -287
- package/src/specs/azure.simple.test.js +0 -381
- package/src/specs/cache.simple.test.js +0 -282
- package/src/specs/custom-event-await.test.js +0 -148
- package/src/specs/deepseek.simple.test.js +0 -189
- package/src/specs/emergency-prune.test.js +0 -308
- package/src/specs/moonshot.simple.test.js +0 -237
- package/src/specs/observability.integration.test.js +0 -1337
- package/src/specs/openai.simple.test.js +0 -233
- package/src/specs/openrouter.simple.test.js +0 -202
- package/src/specs/prune.test.js +0 -733
- package/src/specs/reasoning.test.js +0 -144
- package/src/specs/spec.utils.js +0 -4
- package/src/specs/thinking-handoff.test.js +0 -486
- package/src/specs/thinking-prune.test.js +0 -600
- package/src/specs/token-distribution-edge-case.test.js +0 -246
- package/src/specs/token-memoization.test.js +0 -32
- package/src/specs/tokens.test.js +0 -49
- package/src/specs/tool-error.test.js +0 -139
- package/src/splitStream.js +0 -204
- package/src/splitStream.test.js +0 -504
- package/src/stream.js +0 -650
- package/src/stream.test.js +0 -225
- package/src/test/mockTools.js +0 -340
- package/src/tools/BrowserTools.js +0 -245
- package/src/tools/Calculator.js +0 -38
- package/src/tools/Calculator.test.js +0 -225
- package/src/tools/CodeExecutor.js +0 -233
- package/src/tools/ProgrammaticToolCalling.js +0 -602
- package/src/tools/StreamingToolCallBuffer.js +0 -179
- package/src/tools/ToolNode.js +0 -930
- package/src/tools/ToolSearch.js +0 -904
- package/src/tools/__tests__/BrowserTools.test.js +0 -306
- package/src/tools/__tests__/ProgrammaticToolCalling.integration.test.js +0 -276
- package/src/tools/__tests__/ProgrammaticToolCalling.test.js +0 -807
- package/src/tools/__tests__/StreamingToolCallBuffer.test.js +0 -175
- package/src/tools/__tests__/ToolApproval.test.js +0 -675
- package/src/tools/__tests__/ToolNode.recovery.test.js +0 -200
- package/src/tools/__tests__/ToolNode.session.test.js +0 -319
- package/src/tools/__tests__/ToolSearch.integration.test.js +0 -125
- package/src/tools/__tests__/ToolSearch.test.js +0 -812
- package/src/tools/__tests__/handlers.test.js +0 -799
- package/src/tools/__tests__/truncation-recovery.integration.test.js +0 -362
- package/src/tools/handlers.js +0 -306
- package/src/tools/schema.js +0 -25
- package/src/tools/search/anthropic.js +0 -34
- package/src/tools/search/content.js +0 -116
- package/src/tools/search/content.test.js +0 -133
- package/src/tools/search/firecrawl.js +0 -173
- package/src/tools/search/format.js +0 -198
- package/src/tools/search/highlights.js +0 -241
- package/src/tools/search/index.js +0 -3
- package/src/tools/search/jina-reranker.test.js +0 -106
- package/src/tools/search/rerankers.js +0 -165
- package/src/tools/search/schema.js +0 -102
- package/src/tools/search/search.js +0 -561
- package/src/tools/search/serper-scraper.js +0 -126
- package/src/tools/search/test.js +0 -129
- package/src/tools/search/tool.js +0 -453
- package/src/tools/search/types.js +0 -2
- package/src/tools/search/utils.js +0 -59
- package/src/types/graph.js +0 -24
- package/src/types/graph.test.js +0 -192
- package/src/types/index.js +0 -7
- package/src/types/llm.js +0 -2
- package/src/types/messages.js +0 -2
- package/src/types/run.js +0 -2
- package/src/types/stream.js +0 -2
- package/src/types/tools.js +0 -2
- package/src/utils/contextAnalytics.js +0 -79
- package/src/utils/contextAnalytics.test.js +0 -166
- package/src/utils/events.js +0 -26
- package/src/utils/graph.js +0 -11
- package/src/utils/handlers.js +0 -65
- package/src/utils/index.js +0 -10
- package/src/utils/llm.js +0 -21
- package/src/utils/llmConfig.js +0 -205
- package/src/utils/logging.js +0 -37
- package/src/utils/misc.js +0 -51
- package/src/utils/run.js +0 -69
- package/src/utils/schema.js +0 -21
- package/src/utils/title.js +0 -119
- package/src/utils/tokens.js +0 -92
- package/src/utils/toonFormat.js +0 -379
|
@@ -1,402 +0,0 @@
|
|
|
1
|
-
import { ChatGoogle } from '@langchain/google-gauth';
|
|
2
|
-
import { ChatConnection } from '@langchain/google-common';
|
|
3
|
-
import { isAIMessage } from '@langchain/core/messages';
|
|
4
|
-
/**
|
|
5
|
-
* Fixes thought signatures on functionCall parts in the formatted Gemini request.
|
|
6
|
-
*
|
|
7
|
-
* `@langchain/google-common` stores signatures as a flat array in
|
|
8
|
-
* `additional_kwargs.signatures` (one per response part) and re-attaches them
|
|
9
|
-
* by index only when `signatures.length === parts.length`. This fails when:
|
|
10
|
-
* - The API omits a signature (length mismatch)
|
|
11
|
-
* - Streaming chunks merge with different part counts
|
|
12
|
-
* - The signature for a functionCall part is an empty string
|
|
13
|
-
*
|
|
14
|
-
* This function correlates each "model" content block in the formatted request
|
|
15
|
-
* back to its originating AI message, then re-attaches non-empty signatures
|
|
16
|
-
* that the library failed to apply.
|
|
17
|
-
*/
|
|
18
|
-
function fixThoughtSignatures(contents, input) {
|
|
19
|
-
// Collect AI messages that have signatures, in order
|
|
20
|
-
const aiMessages = input.filter((msg) => isAIMessage(msg) &&
|
|
21
|
-
Array.isArray(msg.additional_kwargs?.signatures) &&
|
|
22
|
-
msg.additional_kwargs.signatures.length > 0);
|
|
23
|
-
// Collect "model" content blocks from the formatted request, in order
|
|
24
|
-
const modelContents = contents.filter((c) => c.role === 'model');
|
|
25
|
-
// They should correspond 1:1 in order (both derived from the same input sequence)
|
|
26
|
-
const count = Math.min(aiMessages.length, modelContents.length);
|
|
27
|
-
for (let i = 0; i < count; i++) {
|
|
28
|
-
const msg = aiMessages[i];
|
|
29
|
-
const content = modelContents[i];
|
|
30
|
-
const signatures = msg.additional_kwargs?.signatures;
|
|
31
|
-
// Collect non-empty signatures that aren't already attached to any part
|
|
32
|
-
const attachedSignatures = new Set(content.parts
|
|
33
|
-
.map((p) => p.thoughtSignature)
|
|
34
|
-
.filter((s) => s != null && s !== ''));
|
|
35
|
-
const availableSignatures = signatures?.filter((s) => s != null && s !== '' && !attachedSignatures.has(s));
|
|
36
|
-
// Assign available signatures to functionCall parts missing one, in order
|
|
37
|
-
let sigIdx = 0;
|
|
38
|
-
for (const part of content.parts) {
|
|
39
|
-
if ('functionCall' in part &&
|
|
40
|
-
(part.thoughtSignature == null || part.thoughtSignature === '') &&
|
|
41
|
-
sigIdx < (availableSignatures?.length ?? 0)) {
|
|
42
|
-
part.thoughtSignature = availableSignatures?.[sigIdx];
|
|
43
|
-
sigIdx++;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
class CustomChatConnection extends ChatConnection {
|
|
49
|
-
thinkingConfig;
|
|
50
|
-
async formatData(input, parameters) {
|
|
51
|
-
const formattedData = (await super.formatData(input, parameters));
|
|
52
|
-
if (formattedData.generationConfig?.thinkingConfig?.thinkingBudget === -1) {
|
|
53
|
-
// -1 means "let the model decide" - delete the property so the API doesn't receive an invalid value
|
|
54
|
-
if (formattedData.generationConfig.thinkingConfig.includeThoughts === false) {
|
|
55
|
-
formattedData.generationConfig.thinkingConfig.includeThoughts = true;
|
|
56
|
-
}
|
|
57
|
-
delete formattedData.generationConfig.thinkingConfig.thinkingBudget;
|
|
58
|
-
}
|
|
59
|
-
if (this.thinkingConfig?.thinkingLevel != null &&
|
|
60
|
-
this.thinkingConfig.thinkingLevel !== '') {
|
|
61
|
-
formattedData.generationConfig ??= {};
|
|
62
|
-
// thinkingLevel and thinkingBudget cannot coexist — the API rejects the request.
|
|
63
|
-
// Remove thinkingBudget when thinkingLevel is set.
|
|
64
|
-
const { thinkingBudget: _, ...existingThinkingConfig } = formattedData.generationConfig.thinkingConfig ?? {};
|
|
65
|
-
formattedData.generationConfig.thinkingConfig = {
|
|
66
|
-
...existingThinkingConfig,
|
|
67
|
-
thinkingLevel: this.thinkingConfig.thinkingLevel,
|
|
68
|
-
...(this.thinkingConfig.includeThoughts != null && {
|
|
69
|
-
includeThoughts: this.thinkingConfig.includeThoughts,
|
|
70
|
-
}),
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
if (formattedData.contents) {
|
|
74
|
-
fixThoughtSignatures(formattedData.contents, input);
|
|
75
|
-
// gemini-3.1+ models reject role="function"; convert to role="user"
|
|
76
|
-
for (const content of formattedData.contents) {
|
|
77
|
-
if (content.role === 'function') {
|
|
78
|
-
content.role = 'user';
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return formattedData;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Integration with Google Vertex AI chat models.
|
|
87
|
-
*
|
|
88
|
-
* Setup:
|
|
89
|
-
* Install `@langchain/google-vertexai` and set your stringified
|
|
90
|
-
* Vertex AI credentials as an environment variable named `GOOGLE_APPLICATION_CREDENTIALS`.
|
|
91
|
-
*
|
|
92
|
-
* ```bash
|
|
93
|
-
* npm install @langchain/google-vertexai
|
|
94
|
-
* export GOOGLE_APPLICATION_CREDENTIALS="path/to/credentials"
|
|
95
|
-
* ```
|
|
96
|
-
*
|
|
97
|
-
* ## [Constructor args](https://api.js.langchain.com/classes/_langchain_google_vertexai.index.ChatVertexAI.html#constructor.new_ChatVertexAI)
|
|
98
|
-
*
|
|
99
|
-
* ## [Runtime args](https://api.js.langchain.com/interfaces/langchain_google_common_types.GoogleAIBaseLanguageModelCallOptions.html)
|
|
100
|
-
*
|
|
101
|
-
* Runtime args can be passed as the second argument to any of the base runnable methods `.invoke`. `.stream`, `.batch`, etc.
|
|
102
|
-
* They can also be passed via `.withConfig`, or the second arg in `.bindTools`, like shown in the examples below:
|
|
103
|
-
*
|
|
104
|
-
* ```typescript
|
|
105
|
-
* // When calling `.withConfig`, call options should be passed via the first argument
|
|
106
|
-
* const llmWithArgsBound = llm.withConfig({
|
|
107
|
-
* stop: ["\n"],
|
|
108
|
-
* tools: [...],
|
|
109
|
-
* });
|
|
110
|
-
*
|
|
111
|
-
* // When calling `.bindTools`, call options should be passed via the second argument
|
|
112
|
-
* const llmWithTools = llm.bindTools(
|
|
113
|
-
* [...],
|
|
114
|
-
* {
|
|
115
|
-
* tool_choice: "auto",
|
|
116
|
-
* }
|
|
117
|
-
* );
|
|
118
|
-
* ```
|
|
119
|
-
*
|
|
120
|
-
* ## Examples
|
|
121
|
-
*
|
|
122
|
-
* <details open>
|
|
123
|
-
* <summary><strong>Instantiate</strong></summary>
|
|
124
|
-
*
|
|
125
|
-
* ```typescript
|
|
126
|
-
* import { ChatVertexAI } from '@langchain/google-vertexai';
|
|
127
|
-
*
|
|
128
|
-
* const llm = new ChatVertexAI({
|
|
129
|
-
* model: "gemini-1.5-pro",
|
|
130
|
-
* temperature: 0,
|
|
131
|
-
* // other params...
|
|
132
|
-
* });
|
|
133
|
-
* ```
|
|
134
|
-
* </details>
|
|
135
|
-
*
|
|
136
|
-
* <br />
|
|
137
|
-
*
|
|
138
|
-
* <details>
|
|
139
|
-
* <summary><strong>Invoking</strong></summary>
|
|
140
|
-
*
|
|
141
|
-
* ```typescript
|
|
142
|
-
* const input = `Translate "I love programming" into French.`;
|
|
143
|
-
*
|
|
144
|
-
* // Models also accept a list of chat messages or a formatted prompt
|
|
145
|
-
* const result = await llm.invoke(input);
|
|
146
|
-
* console.log(result);
|
|
147
|
-
* ```
|
|
148
|
-
*
|
|
149
|
-
* ```txt
|
|
150
|
-
* AIMessageChunk {
|
|
151
|
-
* "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",
|
|
152
|
-
* "additional_kwargs": {},
|
|
153
|
-
* "response_metadata": {},
|
|
154
|
-
* "tool_calls": [],
|
|
155
|
-
* "tool_call_chunks": [],
|
|
156
|
-
* "invalid_tool_calls": [],
|
|
157
|
-
* "usage_metadata": {
|
|
158
|
-
* "input_tokens": 9,
|
|
159
|
-
* "output_tokens": 63,
|
|
160
|
-
* "total_tokens": 72
|
|
161
|
-
* }
|
|
162
|
-
* }
|
|
163
|
-
* ```
|
|
164
|
-
* </details>
|
|
165
|
-
*
|
|
166
|
-
* <br />
|
|
167
|
-
*
|
|
168
|
-
* <details>
|
|
169
|
-
* <summary><strong>Streaming Chunks</strong></summary>
|
|
170
|
-
*
|
|
171
|
-
* ```typescript
|
|
172
|
-
* for await (const chunk of await llm.stream(input)) {
|
|
173
|
-
* console.log(chunk);
|
|
174
|
-
* }
|
|
175
|
-
* ```
|
|
176
|
-
*
|
|
177
|
-
* ```txt
|
|
178
|
-
* AIMessageChunk {
|
|
179
|
-
* "content": "\"",
|
|
180
|
-
* "additional_kwargs": {},
|
|
181
|
-
* "response_metadata": {},
|
|
182
|
-
* "tool_calls": [],
|
|
183
|
-
* "tool_call_chunks": [],
|
|
184
|
-
* "invalid_tool_calls": []
|
|
185
|
-
* }
|
|
186
|
-
* AIMessageChunk {
|
|
187
|
-
* "content": "J'adore programmer\" \n",
|
|
188
|
-
* "additional_kwargs": {},
|
|
189
|
-
* "response_metadata": {},
|
|
190
|
-
* "tool_calls": [],
|
|
191
|
-
* "tool_call_chunks": [],
|
|
192
|
-
* "invalid_tool_calls": []
|
|
193
|
-
* }
|
|
194
|
-
* AIMessageChunk {
|
|
195
|
-
* "content": "",
|
|
196
|
-
* "additional_kwargs": {},
|
|
197
|
-
* "response_metadata": {},
|
|
198
|
-
* "tool_calls": [],
|
|
199
|
-
* "tool_call_chunks": [],
|
|
200
|
-
* "invalid_tool_calls": []
|
|
201
|
-
* }
|
|
202
|
-
* AIMessageChunk {
|
|
203
|
-
* "content": "",
|
|
204
|
-
* "additional_kwargs": {},
|
|
205
|
-
* "response_metadata": {
|
|
206
|
-
* "finishReason": "stop"
|
|
207
|
-
* },
|
|
208
|
-
* "tool_calls": [],
|
|
209
|
-
* "tool_call_chunks": [],
|
|
210
|
-
* "invalid_tool_calls": [],
|
|
211
|
-
* "usage_metadata": {
|
|
212
|
-
* "input_tokens": 9,
|
|
213
|
-
* "output_tokens": 8,
|
|
214
|
-
* "total_tokens": 17
|
|
215
|
-
* }
|
|
216
|
-
* }
|
|
217
|
-
* ```
|
|
218
|
-
* </details>
|
|
219
|
-
*
|
|
220
|
-
* <br />
|
|
221
|
-
*
|
|
222
|
-
* <details>
|
|
223
|
-
* <summary><strong>Aggregate Streamed Chunks</strong></summary>
|
|
224
|
-
*
|
|
225
|
-
* ```typescript
|
|
226
|
-
* import { AIMessageChunk } from '@langchain/core/messages';
|
|
227
|
-
* import { concat } from '@langchain/core/utils/stream';
|
|
228
|
-
*
|
|
229
|
-
* const stream = await llm.stream(input);
|
|
230
|
-
* let full: AIMessageChunk | undefined;
|
|
231
|
-
* for await (const chunk of stream) {
|
|
232
|
-
* full = !full ? chunk : concat(full, chunk);
|
|
233
|
-
* }
|
|
234
|
-
* console.log(full);
|
|
235
|
-
* ```
|
|
236
|
-
*
|
|
237
|
-
* ```txt
|
|
238
|
-
* AIMessageChunk {
|
|
239
|
-
* "content": "\"J'adore programmer\" \n",
|
|
240
|
-
* "additional_kwargs": {},
|
|
241
|
-
* "response_metadata": {
|
|
242
|
-
* "finishReason": "stop"
|
|
243
|
-
* },
|
|
244
|
-
* "tool_calls": [],
|
|
245
|
-
* "tool_call_chunks": [],
|
|
246
|
-
* "invalid_tool_calls": [],
|
|
247
|
-
* "usage_metadata": {
|
|
248
|
-
* "input_tokens": 9,
|
|
249
|
-
* "output_tokens": 8,
|
|
250
|
-
* "total_tokens": 17
|
|
251
|
-
* }
|
|
252
|
-
* }
|
|
253
|
-
* ```
|
|
254
|
-
* </details>
|
|
255
|
-
*
|
|
256
|
-
* <br />
|
|
257
|
-
*
|
|
258
|
-
* <details>
|
|
259
|
-
* <summary><strong>Bind tools</strong></summary>
|
|
260
|
-
*
|
|
261
|
-
* ```typescript
|
|
262
|
-
* import { z } from 'zod';
|
|
263
|
-
*
|
|
264
|
-
* const GetWeather = {
|
|
265
|
-
* name: "GetWeather",
|
|
266
|
-
* description: "Get the current weather in a given location",
|
|
267
|
-
* schema: z.object({
|
|
268
|
-
* location: z.string().describe("The city and state, e.g. San Francisco, CA")
|
|
269
|
-
* }),
|
|
270
|
-
* }
|
|
271
|
-
*
|
|
272
|
-
* const GetPopulation = {
|
|
273
|
-
* name: "GetPopulation",
|
|
274
|
-
* description: "Get the current population in a given location",
|
|
275
|
-
* schema: z.object({
|
|
276
|
-
* location: z.string().describe("The city and state, e.g. San Francisco, CA")
|
|
277
|
-
* }),
|
|
278
|
-
* }
|
|
279
|
-
*
|
|
280
|
-
* const llmWithTools = llm.bindTools([GetWeather, GetPopulation]);
|
|
281
|
-
* const aiMsg = await llmWithTools.invoke(
|
|
282
|
-
* "Which city is hotter today and which is bigger: LA or NY?"
|
|
283
|
-
* );
|
|
284
|
-
* console.log(aiMsg.tool_calls);
|
|
285
|
-
* ```
|
|
286
|
-
*
|
|
287
|
-
* ```txt
|
|
288
|
-
* [
|
|
289
|
-
* {
|
|
290
|
-
* name: 'GetPopulation',
|
|
291
|
-
* args: { location: 'New York City, NY' },
|
|
292
|
-
* id: '33c1c1f47e2f492799c77d2800a43912',
|
|
293
|
-
* type: 'tool_call'
|
|
294
|
-
* }
|
|
295
|
-
* ]
|
|
296
|
-
* ```
|
|
297
|
-
* </details>
|
|
298
|
-
*
|
|
299
|
-
* <br />
|
|
300
|
-
*
|
|
301
|
-
* <details>
|
|
302
|
-
* <summary><strong>Structured Output</strong></summary>
|
|
303
|
-
*
|
|
304
|
-
* ```typescript
|
|
305
|
-
* import { z } from 'zod';
|
|
306
|
-
*
|
|
307
|
-
* const Joke = z.object({
|
|
308
|
-
* setup: z.string().describe("The setup of the joke"),
|
|
309
|
-
* punchline: z.string().describe("The punchline to the joke"),
|
|
310
|
-
* rating: z.number().optional().describe("How funny the joke is, from 1 to 10")
|
|
311
|
-
* }).describe('Joke to tell user.');
|
|
312
|
-
*
|
|
313
|
-
* const structuredLlm = llm.withStructuredOutput(Joke, { name: "Joke" });
|
|
314
|
-
* const jokeResult = await structuredLlm.invoke("Tell me a joke about cats");
|
|
315
|
-
* console.log(jokeResult);
|
|
316
|
-
* ```
|
|
317
|
-
*
|
|
318
|
-
* ```txt
|
|
319
|
-
* {
|
|
320
|
-
* setup: 'What do you call a cat that loves to bowl?',
|
|
321
|
-
* punchline: 'An alley cat!'
|
|
322
|
-
* }
|
|
323
|
-
* ```
|
|
324
|
-
* </details>
|
|
325
|
-
*
|
|
326
|
-
* <br />
|
|
327
|
-
*
|
|
328
|
-
* <details>
|
|
329
|
-
* <summary><strong>Usage Metadata</strong></summary>
|
|
330
|
-
*
|
|
331
|
-
* ```typescript
|
|
332
|
-
* const aiMsgForMetadata = await llm.invoke(input);
|
|
333
|
-
* console.log(aiMsgForMetadata.usage_metadata);
|
|
334
|
-
* ```
|
|
335
|
-
*
|
|
336
|
-
* ```txt
|
|
337
|
-
* { input_tokens: 9, output_tokens: 8, total_tokens: 17 }
|
|
338
|
-
* ```
|
|
339
|
-
* </details>
|
|
340
|
-
*
|
|
341
|
-
* <br />
|
|
342
|
-
*
|
|
343
|
-
* <details>
|
|
344
|
-
* <summary><strong>Stream Usage Metadata</strong></summary>
|
|
345
|
-
*
|
|
346
|
-
* ```typescript
|
|
347
|
-
* const streamForMetadata = await llm.stream(
|
|
348
|
-
* input,
|
|
349
|
-
* {
|
|
350
|
-
* streamUsage: true
|
|
351
|
-
* }
|
|
352
|
-
* );
|
|
353
|
-
* let fullForMetadata: AIMessageChunk | undefined;
|
|
354
|
-
* for await (const chunk of streamForMetadata) {
|
|
355
|
-
* fullForMetadata = !fullForMetadata ? chunk : concat(fullForMetadata, chunk);
|
|
356
|
-
* }
|
|
357
|
-
* console.log(fullForMetadata?.usage_metadata);
|
|
358
|
-
* ```
|
|
359
|
-
*
|
|
360
|
-
* ```txt
|
|
361
|
-
* { input_tokens: 9, output_tokens: 8, total_tokens: 17 }
|
|
362
|
-
* ```
|
|
363
|
-
* </details>
|
|
364
|
-
*
|
|
365
|
-
* <br />
|
|
366
|
-
*/
|
|
367
|
-
export class ChatVertexAI extends ChatGoogle {
|
|
368
|
-
lc_namespace = ['langchain', 'chat_models', 'vertexai'];
|
|
369
|
-
dynamicThinkingBudget = false;
|
|
370
|
-
thinkingConfig;
|
|
371
|
-
static lc_name() {
|
|
372
|
-
return 'IllumaVertexAI';
|
|
373
|
-
}
|
|
374
|
-
constructor(fields) {
|
|
375
|
-
const dynamicThinkingBudget = fields?.thinkingBudget === -1;
|
|
376
|
-
super({
|
|
377
|
-
...fields,
|
|
378
|
-
platformType: 'gcp',
|
|
379
|
-
});
|
|
380
|
-
this.dynamicThinkingBudget = dynamicThinkingBudget;
|
|
381
|
-
this.thinkingConfig = fields?.thinkingConfig;
|
|
382
|
-
}
|
|
383
|
-
invocationParams(options) {
|
|
384
|
-
const params = super.invocationParams(options);
|
|
385
|
-
if (this.dynamicThinkingBudget) {
|
|
386
|
-
params.maxReasoningTokens = -1;
|
|
387
|
-
}
|
|
388
|
-
return params;
|
|
389
|
-
}
|
|
390
|
-
buildConnection(fields, client) {
|
|
391
|
-
// Note: buildConnection is called from super() BEFORE this.thinkingConfig is set,
|
|
392
|
-
// so we must read thinkingConfig from `fields` directly.
|
|
393
|
-
const thinkingConfig = fields?.thinkingConfig ?? this.thinkingConfig;
|
|
394
|
-
const connection = new CustomChatConnection({ ...fields, ...this }, this.caller, client, false);
|
|
395
|
-
connection.thinkingConfig = thinkingConfig;
|
|
396
|
-
this.connection = connection;
|
|
397
|
-
const streamedConnection = new CustomChatConnection({ ...fields, ...this }, this.caller, client, true);
|
|
398
|
-
streamedConnection.thinkingConfig = thinkingConfig;
|
|
399
|
-
this.streamedConnection = streamedConnection;
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
//# sourceMappingURL=index.js.map
|