illuma-agents 1.0.10 → 1.0.12
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/LICENSE +1 -1
- package/dist/cjs/agents/AgentContext.cjs +236 -27
- package/dist/cjs/agents/AgentContext.cjs.map +1 -1
- package/dist/cjs/common/enum.cjs +2 -0
- package/dist/cjs/common/enum.cjs.map +1 -1
- package/dist/cjs/events.cjs +3 -11
- package/dist/cjs/events.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +44 -18
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/instrumentation.cjs +1 -3
- package/dist/cjs/instrumentation.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/index.cjs +121 -6
- package/dist/cjs/llm/bedrock/index.cjs.map +1 -1
- package/dist/cjs/main.cjs +18 -0
- package/dist/cjs/main.cjs.map +1 -1
- package/dist/cjs/messages/cache.cjs +149 -54
- package/dist/cjs/messages/cache.cjs.map +1 -1
- package/dist/cjs/messages/tools.cjs +85 -0
- package/dist/cjs/messages/tools.cjs.map +1 -0
- package/dist/cjs/run.cjs +0 -8
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/tools/CodeExecutor.cjs +4 -0
- package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs +438 -0
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -0
- package/dist/cjs/tools/ToolNode.cjs +53 -15
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/ToolSearchRegex.cjs +455 -0
- package/dist/cjs/tools/ToolSearchRegex.cjs.map +1 -0
- package/dist/cjs/tools/search/schema.cjs +7 -9
- package/dist/cjs/tools/search/schema.cjs.map +1 -1
- package/dist/cjs/utils/run.cjs +5 -1
- package/dist/cjs/utils/run.cjs.map +1 -1
- package/dist/esm/agents/AgentContext.mjs +236 -27
- package/dist/esm/agents/AgentContext.mjs.map +1 -1
- package/dist/esm/common/enum.mjs +2 -0
- package/dist/esm/common/enum.mjs.map +1 -1
- package/dist/esm/events.mjs +4 -12
- package/dist/esm/events.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +45 -19
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/instrumentation.mjs +1 -3
- package/dist/esm/instrumentation.mjs.map +1 -1
- package/dist/esm/llm/bedrock/index.mjs +121 -6
- package/dist/esm/llm/bedrock/index.mjs.map +1 -1
- package/dist/esm/main.mjs +3 -0
- package/dist/esm/main.mjs.map +1 -1
- package/dist/esm/messages/cache.mjs +149 -54
- package/dist/esm/messages/cache.mjs.map +1 -1
- package/dist/esm/messages/tools.mjs +82 -0
- package/dist/esm/messages/tools.mjs.map +1 -0
- package/dist/esm/run.mjs +0 -8
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/tools/CodeExecutor.mjs +4 -0
- package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
- package/dist/esm/tools/ProgrammaticToolCalling.mjs +430 -0
- package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -0
- package/dist/esm/tools/ToolNode.mjs +53 -15
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/ToolSearchRegex.mjs +448 -0
- package/dist/esm/tools/ToolSearchRegex.mjs.map +1 -0
- package/dist/esm/tools/search/schema.mjs +7 -9
- package/dist/esm/tools/search/schema.mjs.map +1 -1
- package/dist/esm/utils/run.mjs +5 -1
- package/dist/esm/utils/run.mjs.map +1 -1
- package/dist/types/agents/AgentContext.d.ts +72 -5
- package/dist/types/common/enum.d.ts +2 -0
- package/dist/types/graphs/Graph.d.ts +3 -2
- package/dist/types/index.d.ts +2 -0
- package/dist/types/llm/bedrock/index.d.ts +31 -4
- package/dist/types/messages/cache.d.ts +23 -8
- package/dist/types/messages/index.d.ts +1 -0
- package/dist/types/messages/tools.d.ts +17 -0
- package/dist/types/test/mockTools.d.ts +28 -0
- package/dist/types/tools/ProgrammaticToolCalling.d.ts +91 -0
- package/dist/types/tools/ToolNode.d.ts +10 -2
- package/dist/types/tools/ToolSearchRegex.d.ts +80 -0
- package/dist/types/types/graph.d.ts +14 -1
- package/dist/types/types/tools.d.ts +138 -0
- package/package.json +7 -8
- package/src/agents/AgentContext.ts +278 -27
- package/src/agents/__tests__/AgentContext.test.ts +805 -0
- package/src/common/enum.ts +2 -0
- package/src/events.ts +5 -12
- package/src/graphs/Graph.ts +57 -19
- package/src/index.ts +2 -0
- package/src/instrumentation.ts +1 -4
- package/src/llm/bedrock/__tests__/bedrock-caching.test.ts +473 -0
- package/src/llm/bedrock/index.ts +149 -12
- package/src/messages/__tests__/tools.test.ts +473 -0
- package/src/messages/cache.ts +163 -61
- package/src/messages/index.ts +1 -0
- package/src/messages/tools.ts +99 -0
- package/src/run.ts +0 -9
- package/src/scripts/code_exec_ptc.ts +334 -0
- package/src/scripts/image.ts +178 -0
- package/src/scripts/programmatic_exec.ts +396 -0
- package/src/scripts/programmatic_exec_agent.ts +231 -0
- package/src/scripts/test-tools-before-handoff.ts +5 -1
- package/src/scripts/tool_search_regex.ts +162 -0
- package/src/scripts/tools.ts +4 -1
- package/src/specs/thinking-prune.test.ts +52 -118
- package/src/test/mockTools.ts +366 -0
- package/src/tools/CodeExecutor.ts +4 -0
- package/src/tools/ProgrammaticToolCalling.ts +558 -0
- package/src/tools/ToolNode.ts +59 -18
- package/src/tools/ToolSearchRegex.ts +535 -0
- package/src/tools/__tests__/ProgrammaticToolCalling.integration.test.ts +318 -0
- package/src/tools/__tests__/ProgrammaticToolCalling.test.ts +853 -0
- package/src/tools/__tests__/ToolSearchRegex.integration.test.ts +161 -0
- package/src/tools/__tests__/ToolSearchRegex.test.ts +232 -0
- package/src/tools/search/jina-reranker.test.ts +16 -16
- package/src/tools/search/schema.ts +7 -9
- package/src/types/graph.ts +14 -1
- package/src/types/tools.ts +166 -0
- package/src/utils/run.ts +5 -1
- package/src/tools/search/direct-url.test.ts +0 -530
|
@@ -13,7 +13,7 @@ class AgentContext {
|
|
|
13
13
|
* Create an AgentContext from configuration with token accounting initialization
|
|
14
14
|
*/
|
|
15
15
|
static fromConfig(agentConfig, tokenCounter, indexTokenCountMap) {
|
|
16
|
-
const { agentId, provider, clientOptions, tools, toolMap, toolEnd, instructions, additional_instructions, streamBuffer, maxContextTokens, reasoningKey, useLegacyContent, } = agentConfig;
|
|
16
|
+
const { agentId, provider, clientOptions, tools, toolMap, toolEnd, toolRegistry, instructions, additional_instructions, streamBuffer, maxContextTokens, reasoningKey, useLegacyContent, dynamicContext, } = agentConfig;
|
|
17
17
|
const agentContext = new AgentContext({
|
|
18
18
|
agentId,
|
|
19
19
|
provider,
|
|
@@ -22,6 +22,7 @@ class AgentContext {
|
|
|
22
22
|
streamBuffer,
|
|
23
23
|
tools,
|
|
24
24
|
toolMap,
|
|
25
|
+
toolRegistry,
|
|
25
26
|
instructions,
|
|
26
27
|
additionalInstructions: additional_instructions,
|
|
27
28
|
reasoningKey,
|
|
@@ -29,14 +30,19 @@ class AgentContext {
|
|
|
29
30
|
instructionTokens: 0,
|
|
30
31
|
tokenCounter,
|
|
31
32
|
useLegacyContent,
|
|
33
|
+
dynamicContext,
|
|
32
34
|
});
|
|
33
35
|
if (tokenCounter) {
|
|
36
|
+
// Initialize system runnable BEFORE async tool token calculation
|
|
37
|
+
// This ensures system message tokens are in instructionTokens before
|
|
38
|
+
// updateTokenMapWithInstructions is called
|
|
39
|
+
agentContext.initializeSystemRunnable();
|
|
34
40
|
const tokenMap = indexTokenCountMap || {};
|
|
35
41
|
agentContext.indexTokenCountMap = tokenMap;
|
|
36
42
|
agentContext.tokenCalculationPromise = agentContext
|
|
37
43
|
.calculateInstructionTokens(tokenCounter)
|
|
38
44
|
.then(() => {
|
|
39
|
-
// Update token map with instruction tokens
|
|
45
|
+
// Update token map with instruction tokens (includes system + tool tokens)
|
|
40
46
|
agentContext.updateTokenMapWithInstructions(tokenMap);
|
|
41
47
|
})
|
|
42
48
|
.catch((err) => {
|
|
@@ -74,10 +80,23 @@ class AgentContext {
|
|
|
74
80
|
tools;
|
|
75
81
|
/** Tool map for this agent */
|
|
76
82
|
toolMap;
|
|
83
|
+
/**
|
|
84
|
+
* Tool definitions registry (includes deferred and programmatic tool metadata).
|
|
85
|
+
* Used for tool search and programmatic tool calling.
|
|
86
|
+
*/
|
|
87
|
+
toolRegistry;
|
|
88
|
+
/** Set of tool names discovered via tool search (to be loaded) */
|
|
89
|
+
discoveredToolNames = new Set();
|
|
77
90
|
/** Instructions for this agent */
|
|
78
91
|
instructions;
|
|
79
92
|
/** Additional instructions for this agent */
|
|
80
93
|
additionalInstructions;
|
|
94
|
+
/**
|
|
95
|
+
* Dynamic context that changes per-request (e.g., current time, user info).
|
|
96
|
+
* This is NOT included in the system message to preserve cache.
|
|
97
|
+
* Instead, it's injected as a user message at the start of the conversation.
|
|
98
|
+
*/
|
|
99
|
+
dynamicContext;
|
|
81
100
|
/** Reasoning key for this agent */
|
|
82
101
|
reasoningKey = 'reasoning_content';
|
|
83
102
|
/** Last token for reasoning detection */
|
|
@@ -88,13 +107,17 @@ class AgentContext {
|
|
|
88
107
|
currentTokenType = ContentTypes.TEXT;
|
|
89
108
|
/** Whether tools should end the workflow */
|
|
90
109
|
toolEnd = false;
|
|
91
|
-
/**
|
|
92
|
-
|
|
110
|
+
/** Cached system runnable (created lazily) */
|
|
111
|
+
cachedSystemRunnable;
|
|
112
|
+
/** Whether system runnable needs rebuild (set when discovered tools change) */
|
|
113
|
+
systemRunnableStale = true;
|
|
114
|
+
/** Cached system message token count (separate from tool tokens) */
|
|
115
|
+
systemMessageTokens = 0;
|
|
93
116
|
/** Promise for token calculation initialization */
|
|
94
117
|
tokenCalculationPromise;
|
|
95
118
|
/** Format content blocks as strings (for legacy compatibility) */
|
|
96
119
|
useLegacyContent = false;
|
|
97
|
-
constructor({ agentId, provider, clientOptions, maxContextTokens, streamBuffer, tokenCounter, tools, toolMap, instructions, additionalInstructions, reasoningKey, toolEnd, instructionTokens, useLegacyContent, }) {
|
|
120
|
+
constructor({ agentId, provider, clientOptions, maxContextTokens, streamBuffer, tokenCounter, tools, toolMap, toolRegistry, instructions, additionalInstructions, dynamicContext, reasoningKey, toolEnd, instructionTokens, useLegacyContent, }) {
|
|
98
121
|
this.agentId = agentId;
|
|
99
122
|
this.provider = provider;
|
|
100
123
|
this.clientOptions = clientOptions;
|
|
@@ -103,8 +126,10 @@ class AgentContext {
|
|
|
103
126
|
this.tokenCounter = tokenCounter;
|
|
104
127
|
this.tools = tools;
|
|
105
128
|
this.toolMap = toolMap;
|
|
129
|
+
this.toolRegistry = toolRegistry;
|
|
106
130
|
this.instructions = instructions;
|
|
107
131
|
this.additionalInstructions = additionalInstructions;
|
|
132
|
+
this.dynamicContext = dynamicContext;
|
|
108
133
|
if (reasoningKey) {
|
|
109
134
|
this.reasoningKey = reasoningKey;
|
|
110
135
|
}
|
|
@@ -115,24 +140,112 @@ class AgentContext {
|
|
|
115
140
|
this.instructionTokens = instructionTokens;
|
|
116
141
|
}
|
|
117
142
|
this.useLegacyContent = useLegacyContent ?? false;
|
|
118
|
-
this.systemRunnable = this.createSystemRunnable();
|
|
119
143
|
}
|
|
120
144
|
/**
|
|
121
|
-
*
|
|
145
|
+
* Builds instructions text for tools that are ONLY callable via programmatic code execution.
|
|
146
|
+
* These tools cannot be called directly by the LLM but are available through the
|
|
147
|
+
* run_tools_with_code tool.
|
|
148
|
+
*
|
|
149
|
+
* Includes:
|
|
150
|
+
* - Code_execution-only tools that are NOT deferred
|
|
151
|
+
* - Code_execution-only tools that ARE deferred but have been discovered via tool search
|
|
152
|
+
*/
|
|
153
|
+
buildProgrammaticOnlyToolsInstructions() {
|
|
154
|
+
if (!this.toolRegistry)
|
|
155
|
+
return '';
|
|
156
|
+
const programmaticOnlyTools = [];
|
|
157
|
+
for (const [name, toolDef] of this.toolRegistry) {
|
|
158
|
+
const allowedCallers = toolDef.allowed_callers ?? ['direct'];
|
|
159
|
+
const isCodeExecutionOnly = allowedCallers.includes('code_execution') &&
|
|
160
|
+
!allowedCallers.includes('direct');
|
|
161
|
+
if (!isCodeExecutionOnly)
|
|
162
|
+
continue;
|
|
163
|
+
// Include if: not deferred OR deferred but discovered
|
|
164
|
+
const isDeferred = toolDef.defer_loading === true;
|
|
165
|
+
const isDiscovered = this.discoveredToolNames.has(name);
|
|
166
|
+
if (!isDeferred || isDiscovered) {
|
|
167
|
+
programmaticOnlyTools.push(toolDef);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (programmaticOnlyTools.length === 0)
|
|
171
|
+
return '';
|
|
172
|
+
const toolDescriptions = programmaticOnlyTools
|
|
173
|
+
.map((tool) => {
|
|
174
|
+
let desc = `- **${tool.name}**`;
|
|
175
|
+
if (tool.description != null && tool.description !== '') {
|
|
176
|
+
desc += `: ${tool.description}`;
|
|
177
|
+
}
|
|
178
|
+
if (tool.parameters) {
|
|
179
|
+
desc += `\n Parameters: ${JSON.stringify(tool.parameters, null, 2).replace(/\n/g, '\n ')}`;
|
|
180
|
+
}
|
|
181
|
+
return desc;
|
|
182
|
+
})
|
|
183
|
+
.join('\n\n');
|
|
184
|
+
return ('\n\n## Programmatic-Only Tools\n\n' +
|
|
185
|
+
'The following tools are available exclusively through the `run_tools_with_code` tool. ' +
|
|
186
|
+
'You cannot call these tools directly; instead, use `run_tools_with_code` with Python code that invokes them.\n\n' +
|
|
187
|
+
toolDescriptions);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Gets the system runnable, creating it lazily if needed.
|
|
191
|
+
* Includes instructions, additional instructions, and programmatic-only tools documentation.
|
|
192
|
+
* Only rebuilds when marked stale (via markToolsAsDiscovered).
|
|
193
|
+
*/
|
|
194
|
+
get systemRunnable() {
|
|
195
|
+
// Return cached if not stale
|
|
196
|
+
if (!this.systemRunnableStale && this.cachedSystemRunnable !== undefined) {
|
|
197
|
+
return this.cachedSystemRunnable;
|
|
198
|
+
}
|
|
199
|
+
// Stale or first access - rebuild
|
|
200
|
+
const instructionsString = this.buildInstructionsString();
|
|
201
|
+
this.cachedSystemRunnable = this.buildSystemRunnable(instructionsString);
|
|
202
|
+
this.systemRunnableStale = false;
|
|
203
|
+
return this.cachedSystemRunnable;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Explicitly initializes the system runnable.
|
|
207
|
+
* Call this before async token calculation to ensure system message tokens are counted first.
|
|
122
208
|
*/
|
|
123
|
-
|
|
124
|
-
|
|
209
|
+
initializeSystemRunnable() {
|
|
210
|
+
if (this.systemRunnableStale || this.cachedSystemRunnable === undefined) {
|
|
211
|
+
const instructionsString = this.buildInstructionsString();
|
|
212
|
+
this.cachedSystemRunnable = this.buildSystemRunnable(instructionsString);
|
|
213
|
+
this.systemRunnableStale = false;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Builds the raw instructions string (without creating SystemMessage).
|
|
218
|
+
*/
|
|
219
|
+
buildInstructionsString() {
|
|
220
|
+
let result = this.instructions ?? '';
|
|
125
221
|
if (this.additionalInstructions != null &&
|
|
126
222
|
this.additionalInstructions !== '') {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
223
|
+
result = result
|
|
224
|
+
? `${result}\n\n${this.additionalInstructions}`
|
|
225
|
+
: this.additionalInstructions;
|
|
226
|
+
}
|
|
227
|
+
const programmaticToolsDoc = this.buildProgrammaticOnlyToolsInstructions();
|
|
228
|
+
if (programmaticToolsDoc) {
|
|
229
|
+
result = result
|
|
230
|
+
? `${result}${programmaticToolsDoc}`
|
|
231
|
+
: programmaticToolsDoc;
|
|
232
|
+
}
|
|
233
|
+
return result;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Build system runnable from pre-built instructions string.
|
|
237
|
+
* Only called when content has actually changed.
|
|
238
|
+
*/
|
|
239
|
+
buildSystemRunnable(instructionsString) {
|
|
240
|
+
if (!instructionsString) {
|
|
241
|
+
// Remove previous tokens if we had a system message before
|
|
242
|
+
this.instructionTokens -= this.systemMessageTokens;
|
|
243
|
+
this.systemMessageTokens = 0;
|
|
244
|
+
return undefined;
|
|
245
|
+
}
|
|
246
|
+
let finalInstructions = instructionsString;
|
|
247
|
+
// Handle Anthropic prompt caching (Direct API)
|
|
248
|
+
if (this.provider === Providers.ANTHROPIC) {
|
|
136
249
|
const anthropicOptions = this.clientOptions;
|
|
137
250
|
const defaultHeaders = anthropicOptions?.clientOptions?.defaultHeaders;
|
|
138
251
|
const anthropicBeta = defaultHeaders?.['anthropic-beta'];
|
|
@@ -142,29 +255,56 @@ class AgentContext {
|
|
|
142
255
|
content: [
|
|
143
256
|
{
|
|
144
257
|
type: 'text',
|
|
145
|
-
text:
|
|
258
|
+
text: instructionsString,
|
|
146
259
|
cache_control: { type: 'ephemeral' },
|
|
147
260
|
},
|
|
148
261
|
],
|
|
149
262
|
};
|
|
150
263
|
}
|
|
151
264
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
265
|
+
// Handle Bedrock prompt caching (Converse API)
|
|
266
|
+
// Adds cachePoint block after text content for system message caching
|
|
267
|
+
// NOTE: Both Claude and Nova models support cachePoint in system and messages
|
|
268
|
+
// (Nova does NOT support cachePoint in tools - that check is in bedrock/index.ts)
|
|
269
|
+
if (this.provider === Providers.BEDROCK) {
|
|
270
|
+
const bedrockOptions = this.clientOptions;
|
|
271
|
+
const modelId = bedrockOptions?.model?.toLowerCase() ?? '';
|
|
272
|
+
const supportsCaching = modelId.includes('claude') || modelId.includes('anthropic') || modelId.includes('nova');
|
|
273
|
+
if (bedrockOptions?.promptCache === true && supportsCaching) {
|
|
274
|
+
// Always log system cache structure
|
|
275
|
+
console.log(`[Cache] 📝 System | chars=${instructionsString.length} | tokens=${this.systemMessageTokens} | model=${modelId}`);
|
|
276
|
+
finalInstructions = {
|
|
277
|
+
content: [
|
|
278
|
+
{
|
|
279
|
+
type: 'text',
|
|
280
|
+
text: instructionsString,
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
cachePoint: { type: 'default' },
|
|
284
|
+
},
|
|
285
|
+
],
|
|
286
|
+
};
|
|
156
287
|
}
|
|
157
|
-
return RunnableLambda.from((messages) => {
|
|
158
|
-
return [systemMessage, ...messages];
|
|
159
|
-
}).withConfig({ runName: 'prompt' });
|
|
160
288
|
}
|
|
161
|
-
|
|
289
|
+
const systemMessage = new SystemMessage(finalInstructions);
|
|
290
|
+
// Update token counts (subtract old, add new)
|
|
291
|
+
if (this.tokenCounter) {
|
|
292
|
+
this.instructionTokens -= this.systemMessageTokens;
|
|
293
|
+
this.systemMessageTokens = this.tokenCounter(systemMessage);
|
|
294
|
+
this.instructionTokens += this.systemMessageTokens;
|
|
295
|
+
}
|
|
296
|
+
return RunnableLambda.from((messages) => {
|
|
297
|
+
return [systemMessage, ...messages];
|
|
298
|
+
}).withConfig({ runName: 'prompt' });
|
|
162
299
|
}
|
|
163
300
|
/**
|
|
164
301
|
* Reset context for a new run
|
|
165
302
|
*/
|
|
166
303
|
reset() {
|
|
167
304
|
this.instructionTokens = 0;
|
|
305
|
+
this.systemMessageTokens = 0;
|
|
306
|
+
this.cachedSystemRunnable = undefined;
|
|
307
|
+
this.systemRunnableStale = true;
|
|
168
308
|
this.lastToken = undefined;
|
|
169
309
|
this.indexTokenCountMap = {};
|
|
170
310
|
this.currentUsage = undefined;
|
|
@@ -172,6 +312,7 @@ class AgentContext {
|
|
|
172
312
|
this.lastStreamCall = undefined;
|
|
173
313
|
this.tokenTypeSwitch = undefined;
|
|
174
314
|
this.currentTokenType = ContentTypes.TEXT;
|
|
315
|
+
this.discoveredToolNames.clear();
|
|
175
316
|
}
|
|
176
317
|
/**
|
|
177
318
|
* Update the token count map with instruction tokens
|
|
@@ -214,6 +355,74 @@ class AgentContext {
|
|
|
214
355
|
// Add tool tokens to existing instruction tokens (which may already include system message tokens)
|
|
215
356
|
this.instructionTokens += toolTokens;
|
|
216
357
|
}
|
|
358
|
+
/**
|
|
359
|
+
* Gets the tool registry for deferred tools (for tool search).
|
|
360
|
+
* @param onlyDeferred If true, only returns tools with defer_loading=true
|
|
361
|
+
* @returns LCToolRegistry with tool definitions
|
|
362
|
+
*/
|
|
363
|
+
getDeferredToolRegistry(onlyDeferred = true) {
|
|
364
|
+
const registry = new Map();
|
|
365
|
+
if (!this.toolRegistry) {
|
|
366
|
+
return registry;
|
|
367
|
+
}
|
|
368
|
+
for (const [name, toolDef] of this.toolRegistry) {
|
|
369
|
+
if (!onlyDeferred || toolDef.defer_loading === true) {
|
|
370
|
+
registry.set(name, toolDef);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
return registry;
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Marks tools as discovered via tool search.
|
|
377
|
+
* Discovered tools will be included in the next model binding.
|
|
378
|
+
* Only marks system runnable stale if NEW tools were actually added.
|
|
379
|
+
* @param toolNames - Array of discovered tool names
|
|
380
|
+
* @returns true if any new tools were discovered
|
|
381
|
+
*/
|
|
382
|
+
markToolsAsDiscovered(toolNames) {
|
|
383
|
+
let hasNewDiscoveries = false;
|
|
384
|
+
for (const name of toolNames) {
|
|
385
|
+
if (!this.discoveredToolNames.has(name)) {
|
|
386
|
+
this.discoveredToolNames.add(name);
|
|
387
|
+
hasNewDiscoveries = true;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
if (hasNewDiscoveries) {
|
|
391
|
+
this.systemRunnableStale = true;
|
|
392
|
+
}
|
|
393
|
+
return hasNewDiscoveries;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Gets tools that should be bound to the LLM.
|
|
397
|
+
* Includes:
|
|
398
|
+
* 1. Non-deferred tools with allowed_callers: ['direct']
|
|
399
|
+
* 2. Discovered tools (from tool search)
|
|
400
|
+
* @returns Array of tools to bind to model
|
|
401
|
+
*/
|
|
402
|
+
getToolsForBinding() {
|
|
403
|
+
if (!this.tools || !this.toolRegistry) {
|
|
404
|
+
return this.tools;
|
|
405
|
+
}
|
|
406
|
+
const toolsToInclude = this.tools.filter((tool) => {
|
|
407
|
+
if (!('name' in tool)) {
|
|
408
|
+
return true; // No name, include by default
|
|
409
|
+
}
|
|
410
|
+
const toolDef = this.toolRegistry?.get(tool.name);
|
|
411
|
+
if (!toolDef) {
|
|
412
|
+
return true; // Not in registry, include by default
|
|
413
|
+
}
|
|
414
|
+
// Check if discovered (overrides defer_loading)
|
|
415
|
+
if (this.discoveredToolNames.has(tool.name)) {
|
|
416
|
+
// Discovered tools must still have allowed_callers: ['direct']
|
|
417
|
+
const allowedCallers = toolDef.allowed_callers ?? ['direct'];
|
|
418
|
+
return allowedCallers.includes('direct');
|
|
419
|
+
}
|
|
420
|
+
// Not discovered: must be direct-callable AND not deferred
|
|
421
|
+
const allowedCallers = toolDef.allowed_callers ?? ['direct'];
|
|
422
|
+
return (allowedCallers.includes('direct') && toolDef.defer_loading !== true);
|
|
423
|
+
});
|
|
424
|
+
return toolsToInclude;
|
|
425
|
+
}
|
|
217
426
|
}
|
|
218
427
|
|
|
219
428
|
export { AgentContext };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentContext.mjs","sources":["../../../src/agents/AgentContext.ts"],"sourcesContent":["/* eslint-disable no-console */\n// src/agents/AgentContext.ts\nimport { zodToJsonSchema } from 'zod-to-json-schema';\nimport { SystemMessage } from '@langchain/core/messages';\nimport { RunnableLambda } from '@langchain/core/runnables';\nimport type {\n UsageMetadata,\n BaseMessage,\n BaseMessageFields,\n} from '@langchain/core/messages';\nimport type { RunnableConfig, Runnable } from '@langchain/core/runnables';\nimport type * as t from '@/types';\nimport type { createPruneMessages } from '@/messages';\nimport { ContentTypes, Providers } from '@/common';\n\n/**\n * Encapsulates agent-specific state that can vary between agents in a multi-agent system\n */\nexport class AgentContext {\n /**\n * Create an AgentContext from configuration with token accounting initialization\n */\n static fromConfig(\n agentConfig: t.AgentInputs,\n tokenCounter?: t.TokenCounter,\n indexTokenCountMap?: Record<string, number>\n ): AgentContext {\n const {\n agentId,\n provider,\n clientOptions,\n tools,\n toolMap,\n toolEnd,\n instructions,\n additional_instructions,\n streamBuffer,\n maxContextTokens,\n reasoningKey,\n useLegacyContent,\n } = agentConfig;\n\n const agentContext = new AgentContext({\n agentId,\n provider,\n clientOptions,\n maxContextTokens,\n streamBuffer,\n tools,\n toolMap,\n instructions,\n additionalInstructions: additional_instructions,\n reasoningKey,\n toolEnd,\n instructionTokens: 0,\n tokenCounter,\n useLegacyContent,\n });\n\n if (tokenCounter) {\n const tokenMap = indexTokenCountMap || {};\n agentContext.indexTokenCountMap = tokenMap;\n agentContext.tokenCalculationPromise = agentContext\n .calculateInstructionTokens(tokenCounter)\n .then(() => {\n // Update token map with instruction tokens\n agentContext.updateTokenMapWithInstructions(tokenMap);\n })\n .catch((err) => {\n console.error('Error calculating instruction tokens:', err);\n });\n } else if (indexTokenCountMap) {\n agentContext.indexTokenCountMap = indexTokenCountMap;\n }\n\n return agentContext;\n }\n\n /** Agent identifier */\n agentId: string;\n /** Provider for this specific agent */\n provider: Providers;\n /** Client options for this agent */\n clientOptions?: t.ClientOptions;\n /** Token count map indexed by message position */\n indexTokenCountMap: Record<string, number | undefined> = {};\n /** Maximum context tokens for this agent */\n maxContextTokens?: number;\n /** Current usage metadata for this agent */\n currentUsage?: Partial<UsageMetadata>;\n /** Prune messages function configured for this agent */\n pruneMessages?: ReturnType<typeof createPruneMessages>;\n /** Token counter function for this agent */\n tokenCounter?: t.TokenCounter;\n /** Instructions/system message token count */\n instructionTokens: number = 0;\n /** The amount of time that should pass before another consecutive API call */\n streamBuffer?: number;\n /** Last stream call timestamp for rate limiting */\n lastStreamCall?: number;\n /** Tools available to this agent */\n tools?: t.GraphTools;\n /** Tool map for this agent */\n toolMap?: t.ToolMap;\n /** Instructions for this agent */\n instructions?: string;\n /** Additional instructions for this agent */\n additionalInstructions?: string;\n /** Reasoning key for this agent */\n reasoningKey: 'reasoning_content' | 'reasoning' = 'reasoning_content';\n /** Last token for reasoning detection */\n lastToken?: string;\n /** Token type switch state */\n tokenTypeSwitch?: 'reasoning' | 'content';\n /** Current token type being processed */\n currentTokenType: ContentTypes.TEXT | ContentTypes.THINK | 'think_and_text' =\n ContentTypes.TEXT;\n /** Whether tools should end the workflow */\n toolEnd: boolean = false;\n /** System runnable for this agent */\n systemRunnable?: Runnable<\n BaseMessage[],\n (BaseMessage | SystemMessage)[],\n RunnableConfig<Record<string, unknown>>\n >;\n /** Promise for token calculation initialization */\n tokenCalculationPromise?: Promise<void>;\n /** Format content blocks as strings (for legacy compatibility) */\n useLegacyContent: boolean = false;\n\n constructor({\n agentId,\n provider,\n clientOptions,\n maxContextTokens,\n streamBuffer,\n tokenCounter,\n tools,\n toolMap,\n instructions,\n additionalInstructions,\n reasoningKey,\n toolEnd,\n instructionTokens,\n useLegacyContent,\n }: {\n agentId: string;\n provider: Providers;\n clientOptions?: t.ClientOptions;\n maxContextTokens?: number;\n streamBuffer?: number;\n tokenCounter?: t.TokenCounter;\n tools?: t.GraphTools;\n toolMap?: t.ToolMap;\n instructions?: string;\n additionalInstructions?: string;\n reasoningKey?: 'reasoning_content' | 'reasoning';\n toolEnd?: boolean;\n instructionTokens?: number;\n useLegacyContent?: boolean;\n }) {\n this.agentId = agentId;\n this.provider = provider;\n this.clientOptions = clientOptions;\n this.maxContextTokens = maxContextTokens;\n this.streamBuffer = streamBuffer;\n this.tokenCounter = tokenCounter;\n this.tools = tools;\n this.toolMap = toolMap;\n this.instructions = instructions;\n this.additionalInstructions = additionalInstructions;\n if (reasoningKey) {\n this.reasoningKey = reasoningKey;\n }\n if (toolEnd !== undefined) {\n this.toolEnd = toolEnd;\n }\n if (instructionTokens !== undefined) {\n this.instructionTokens = instructionTokens;\n }\n\n this.useLegacyContent = useLegacyContent ?? false;\n\n this.systemRunnable = this.createSystemRunnable();\n }\n\n /**\n * Create system runnable from instructions and calculate tokens if tokenCounter is available\n */\n private createSystemRunnable():\n | Runnable<\n BaseMessage[],\n (BaseMessage | SystemMessage)[],\n RunnableConfig<Record<string, unknown>>\n >\n | undefined {\n let finalInstructions: string | BaseMessageFields | undefined =\n this.instructions;\n\n if (\n this.additionalInstructions != null &&\n this.additionalInstructions !== ''\n ) {\n finalInstructions =\n finalInstructions != null && finalInstructions\n ? `${finalInstructions}\\n\\n${this.additionalInstructions}`\n : this.additionalInstructions;\n }\n\n // Handle Anthropic prompt caching\n if (\n finalInstructions != null &&\n finalInstructions !== '' &&\n this.provider === Providers.ANTHROPIC\n ) {\n const anthropicOptions = this.clientOptions as\n | t.AnthropicClientOptions\n | undefined;\n const defaultHeaders = anthropicOptions?.clientOptions?.defaultHeaders as\n | Record<string, string>\n | undefined;\n const anthropicBeta = defaultHeaders?.['anthropic-beta'];\n if (\n typeof anthropicBeta === 'string' &&\n anthropicBeta.includes('prompt-caching')\n ) {\n finalInstructions = {\n content: [\n {\n type: 'text',\n text: this.instructions,\n cache_control: { type: 'ephemeral' },\n },\n ],\n };\n }\n }\n\n if (finalInstructions != null && finalInstructions !== '') {\n const systemMessage = new SystemMessage(finalInstructions);\n\n if (this.tokenCounter) {\n this.instructionTokens += this.tokenCounter(systemMessage);\n }\n\n return RunnableLambda.from((messages: BaseMessage[]) => {\n return [systemMessage, ...messages];\n }).withConfig({ runName: 'prompt' });\n }\n\n return undefined;\n }\n\n /**\n * Reset context for a new run\n */\n reset(): void {\n this.instructionTokens = 0;\n this.lastToken = undefined;\n this.indexTokenCountMap = {};\n this.currentUsage = undefined;\n this.pruneMessages = undefined;\n this.lastStreamCall = undefined;\n this.tokenTypeSwitch = undefined;\n this.currentTokenType = ContentTypes.TEXT;\n }\n\n /**\n * Update the token count map with instruction tokens\n */\n updateTokenMapWithInstructions(baseTokenMap: Record<string, number>): void {\n if (this.instructionTokens > 0) {\n // Shift all indices by the instruction token count\n const shiftedMap: Record<string, number> = {};\n for (const [key, value] of Object.entries(baseTokenMap)) {\n const index = parseInt(key, 10);\n if (!isNaN(index)) {\n shiftedMap[String(index)] =\n value + (index === 0 ? this.instructionTokens : 0);\n }\n }\n this.indexTokenCountMap = shiftedMap;\n } else {\n this.indexTokenCountMap = { ...baseTokenMap };\n }\n }\n\n /**\n * Calculate tool tokens and add to instruction tokens\n * Note: System message tokens are calculated during systemRunnable creation\n */\n async calculateInstructionTokens(\n tokenCounter: t.TokenCounter\n ): Promise<void> {\n let toolTokens = 0;\n if (this.tools && this.tools.length > 0) {\n for (const tool of this.tools) {\n const genericTool = tool as Record<string, unknown>;\n if (\n genericTool.schema != null &&\n typeof genericTool.schema === 'object'\n ) {\n const schema = genericTool.schema as {\n describe: (desc: string) => unknown;\n };\n const describedSchema = schema.describe(\n (genericTool.description as string) || ''\n );\n const jsonSchema = zodToJsonSchema(\n describedSchema as Parameters<typeof zodToJsonSchema>[0],\n (genericTool.name as string) || ''\n );\n toolTokens += tokenCounter(\n new SystemMessage(JSON.stringify(jsonSchema))\n );\n }\n }\n }\n\n // Add tool tokens to existing instruction tokens (which may already include system message tokens)\n this.instructionTokens += toolTokens;\n }\n}\n"],"names":[],"mappings":";;;;;AAAA;AACA;AAcA;;AAEG;MACU,YAAY,CAAA;AACvB;;AAEG;AACH,IAAA,OAAO,UAAU,CACf,WAA0B,EAC1B,YAA6B,EAC7B,kBAA2C,EAAA;QAE3C,MAAM,EACJ,OAAO,EACP,QAAQ,EACR,aAAa,EACb,KAAK,EACL,OAAO,EACP,OAAO,EACP,YAAY,EACZ,uBAAuB,EACvB,YAAY,EACZ,gBAAgB,EAChB,YAAY,EACZ,gBAAgB,GACjB,GAAG,WAAW;AAEf,QAAA,MAAM,YAAY,GAAG,IAAI,YAAY,CAAC;YACpC,OAAO;YACP,QAAQ;YACR,aAAa;YACb,gBAAgB;YAChB,YAAY;YACZ,KAAK;YACL,OAAO;YACP,YAAY;AACZ,YAAA,sBAAsB,EAAE,uBAAuB;YAC/C,YAAY;YACZ,OAAO;AACP,YA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M,MAAM,GAAG,WAAW,CAAC,MAE1B;AACD,oBAAA,MAAM,eAAe,GAAG,MAAM,CAAC,QAAQ,CACpC,WAAW,CAAC,WAAsB,IAAI,EAAE,CAC1C;AACD,oBAAA,MAAM,UAAU,GAAG,eAAe,CAChC,eAAwD,EACvD,WAAW,CAAC,IAAe,IAAI,EAAE,CACnC;AACD,oBAAA,UAAU,IAAI,YAAY,CACxB,IAAI,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAC9C;;;;;AAMP,QAAA,IAAI,CAAC,iBAAiB,IAAI,UAAU;;AAEvC;;;;"}
|
|
1
|
+
{"version":3,"file":"AgentContext.mjs","sources":["../../../src/agents/AgentContext.ts"],"sourcesContent":["/* eslint-disable no-console */\n// src/agents/AgentContext.ts\nimport { zodToJsonSchema } from 'zod-to-json-schema';\nimport { SystemMessage } from '@langchain/core/messages';\nimport { RunnableLambda } from '@langchain/core/runnables';\nimport type {\n UsageMetadata,\n BaseMessage,\n BaseMessageFields,\n} from '@langchain/core/messages';\nimport type { RunnableConfig, Runnable } from '@langchain/core/runnables';\nimport type * as t from '@/types';\nimport type { createPruneMessages } from '@/messages';\nimport { ContentTypes, Providers } from '@/common';\n\n/**\n * Encapsulates agent-specific state that can vary between agents in a multi-agent system\n */\nexport class AgentContext {\n /**\n * Create an AgentContext from configuration with token accounting initialization\n */\n static fromConfig(\n agentConfig: t.AgentInputs,\n tokenCounter?: t.TokenCounter,\n indexTokenCountMap?: Record<string, number>\n ): AgentContext {\n const {\n agentId,\n provider,\n clientOptions,\n tools,\n toolMap,\n toolEnd,\n toolRegistry,\n instructions,\n additional_instructions,\n streamBuffer,\n maxContextTokens,\n reasoningKey,\n useLegacyContent,\n dynamicContext,\n } = agentConfig;\n\n const agentContext = new AgentContext({\n agentId,\n provider,\n clientOptions,\n maxContextTokens,\n streamBuffer,\n tools,\n toolMap,\n toolRegistry,\n instructions,\n additionalInstructions: additional_instructions,\n reasoningKey,\n toolEnd,\n instructionTokens: 0,\n tokenCounter,\n useLegacyContent,\n dynamicContext,\n });\n\n if (tokenCounter) {\n // Initialize system runnable BEFORE async tool token calculation\n // This ensures system message tokens are in instructionTokens before\n // updateTokenMapWithInstructions is called\n agentContext.initializeSystemRunnable();\n\n const tokenMap = indexTokenCountMap || {};\n agentContext.indexTokenCountMap = tokenMap;\n agentContext.tokenCalculationPromise = agentContext\n .calculateInstructionTokens(tokenCounter)\n .then(() => {\n // Update token map with instruction tokens (includes system + tool tokens)\n agentContext.updateTokenMapWithInstructions(tokenMap);\n })\n .catch((err) => {\n console.error('Error calculating instruction tokens:', err);\n });\n } else if (indexTokenCountMap) {\n agentContext.indexTokenCountMap = indexTokenCountMap;\n }\n\n return agentContext;\n }\n\n /** Agent identifier */\n agentId: string;\n /** Provider for this specific agent */\n provider: Providers;\n /** Client options for this agent */\n clientOptions?: t.ClientOptions;\n /** Token count map indexed by message position */\n indexTokenCountMap: Record<string, number | undefined> = {};\n /** Maximum context tokens for this agent */\n maxContextTokens?: number;\n /** Current usage metadata for this agent */\n currentUsage?: Partial<UsageMetadata>;\n /** Prune messages function configured for this agent */\n pruneMessages?: ReturnType<typeof createPruneMessages>;\n /** Token counter function for this agent */\n tokenCounter?: t.TokenCounter;\n /** Instructions/system message token count */\n instructionTokens: number = 0;\n /** The amount of time that should pass before another consecutive API call */\n streamBuffer?: number;\n /** Last stream call timestamp for rate limiting */\n lastStreamCall?: number;\n /** Tools available to this agent */\n tools?: t.GraphTools;\n /** Tool map for this agent */\n toolMap?: t.ToolMap;\n /**\n * Tool definitions registry (includes deferred and programmatic tool metadata).\n * Used for tool search and programmatic tool calling.\n */\n toolRegistry?: t.LCToolRegistry;\n /** Set of tool names discovered via tool search (to be loaded) */\n discoveredToolNames: Set<string> = new Set();\n /** Instructions for this agent */\n instructions?: string;\n /** Additional instructions for this agent */\n additionalInstructions?: string;\n /**\n * Dynamic context that changes per-request (e.g., current time, user info).\n * This is NOT included in the system message to preserve cache.\n * Instead, it's injected as a user message at the start of the conversation.\n */\n dynamicContext?: string;\n /** Reasoning key for this agent */\n reasoningKey: 'reasoning_content' | 'reasoning' = 'reasoning_content';\n /** Last token for reasoning detection */\n lastToken?: string;\n /** Token type switch state */\n tokenTypeSwitch?: 'reasoning' | 'content';\n /** Current token type being processed */\n currentTokenType: ContentTypes.TEXT | ContentTypes.THINK | 'think_and_text' =\n ContentTypes.TEXT;\n /** Whether tools should end the workflow */\n toolEnd: boolean = false;\n /** Cached system runnable (created lazily) */\n private cachedSystemRunnable?: Runnable<\n BaseMessage[],\n (BaseMessage | SystemMessage)[],\n RunnableConfig<Record<string, unknown>>\n >;\n /** Whether system runnable needs rebuild (set when discovered tools change) */\n private systemRunnableStale: boolean = true;\n /** Cached system message token count (separate from tool tokens) */\n private systemMessageTokens: number = 0;\n /** Promise for token calculation initialization */\n tokenCalculationPromise?: Promise<void>;\n /** Format content blocks as strings (for legacy compatibility) */\n useLegacyContent: boolean = false;\n\n constructor({\n agentId,\n provider,\n clientOptions,\n maxContextTokens,\n streamBuffer,\n tokenCounter,\n tools,\n toolMap,\n toolRegistry,\n instructions,\n additionalInstructions,\n dynamicContext,\n reasoningKey,\n toolEnd,\n instructionTokens,\n useLegacyContent,\n }: {\n agentId: string;\n provider: Providers;\n clientOptions?: t.ClientOptions;\n maxContextTokens?: number;\n streamBuffer?: number;\n tokenCounter?: t.TokenCounter;\n tools?: t.GraphTools;\n toolMap?: t.ToolMap;\n toolRegistry?: t.LCToolRegistry;\n instructions?: string;\n additionalInstructions?: string;\n dynamicContext?: string;\n reasoningKey?: 'reasoning_content' | 'reasoning';\n toolEnd?: boolean;\n instructionTokens?: number;\n useLegacyContent?: boolean;\n }) {\n this.agentId = agentId;\n this.provider = provider;\n this.clientOptions = clientOptions;\n this.maxContextTokens = maxContextTokens;\n this.streamBuffer = streamBuffer;\n this.tokenCounter = tokenCounter;\n this.tools = tools;\n this.toolMap = toolMap;\n this.toolRegistry = toolRegistry;\n this.instructions = instructions;\n this.additionalInstructions = additionalInstructions;\n this.dynamicContext = dynamicContext;\n if (reasoningKey) {\n this.reasoningKey = reasoningKey;\n }\n if (toolEnd !== undefined) {\n this.toolEnd = toolEnd;\n }\n if (instructionTokens !== undefined) {\n this.instructionTokens = instructionTokens;\n }\n\n this.useLegacyContent = useLegacyContent ?? false;\n }\n\n /**\n * Builds instructions text for tools that are ONLY callable via programmatic code execution.\n * These tools cannot be called directly by the LLM but are available through the\n * run_tools_with_code tool.\n *\n * Includes:\n * - Code_execution-only tools that are NOT deferred\n * - Code_execution-only tools that ARE deferred but have been discovered via tool search\n */\n private buildProgrammaticOnlyToolsInstructions(): string {\n if (!this.toolRegistry) return '';\n\n const programmaticOnlyTools: t.LCTool[] = [];\n for (const [name, toolDef] of this.toolRegistry) {\n const allowedCallers = toolDef.allowed_callers ?? ['direct'];\n const isCodeExecutionOnly =\n allowedCallers.includes('code_execution') &&\n !allowedCallers.includes('direct');\n\n if (!isCodeExecutionOnly) continue;\n\n // Include if: not deferred OR deferred but discovered\n const isDeferred = toolDef.defer_loading === true;\n const isDiscovered = this.discoveredToolNames.has(name);\n if (!isDeferred || isDiscovered) {\n programmaticOnlyTools.push(toolDef);\n }\n }\n\n if (programmaticOnlyTools.length === 0) return '';\n\n const toolDescriptions = programmaticOnlyTools\n .map((tool) => {\n let desc = `- **${tool.name}**`;\n if (tool.description != null && tool.description !== '') {\n desc += `: ${tool.description}`;\n }\n if (tool.parameters) {\n desc += `\\n Parameters: ${JSON.stringify(tool.parameters, null, 2).replace(/\\n/g, '\\n ')}`;\n }\n return desc;\n })\n .join('\\n\\n');\n\n return (\n '\\n\\n## Programmatic-Only Tools\\n\\n' +\n 'The following tools are available exclusively through the `run_tools_with_code` tool. ' +\n 'You cannot call these tools directly; instead, use `run_tools_with_code` with Python code that invokes them.\\n\\n' +\n toolDescriptions\n );\n }\n\n /**\n * Gets the system runnable, creating it lazily if needed.\n * Includes instructions, additional instructions, and programmatic-only tools documentation.\n * Only rebuilds when marked stale (via markToolsAsDiscovered).\n */\n get systemRunnable():\n | Runnable<\n BaseMessage[],\n (BaseMessage | SystemMessage)[],\n RunnableConfig<Record<string, unknown>>\n >\n | undefined {\n // Return cached if not stale\n if (!this.systemRunnableStale && this.cachedSystemRunnable !== undefined) {\n return this.cachedSystemRunnable;\n }\n\n // Stale or first access - rebuild\n const instructionsString = this.buildInstructionsString();\n this.cachedSystemRunnable = this.buildSystemRunnable(instructionsString);\n this.systemRunnableStale = false;\n return this.cachedSystemRunnable;\n }\n\n /**\n * Explicitly initializes the system runnable.\n * Call this before async token calculation to ensure system message tokens are counted first.\n */\n initializeSystemRunnable(): void {\n if (this.systemRunnableStale || this.cachedSystemRunnable === undefined) {\n const instructionsString = this.buildInstructionsString();\n this.cachedSystemRunnable = this.buildSystemRunnable(instructionsString);\n this.systemRunnableStale = false;\n }\n }\n\n /**\n * Builds the raw instructions string (without creating SystemMessage).\n */\n private buildInstructionsString(): string {\n let result = this.instructions ?? '';\n\n if (\n this.additionalInstructions != null &&\n this.additionalInstructions !== ''\n ) {\n result = result\n ? `${result}\\n\\n${this.additionalInstructions}`\n : this.additionalInstructions;\n }\n\n const programmaticToolsDoc = this.buildProgrammaticOnlyToolsInstructions();\n if (programmaticToolsDoc) {\n result = result\n ? `${result}${programmaticToolsDoc}`\n : programmaticToolsDoc;\n }\n\n return result;\n }\n\n /**\n * Build system runnable from pre-built instructions string.\n * Only called when content has actually changed.\n */\n private buildSystemRunnable(\n instructionsString: string\n ):\n | Runnable<\n BaseMessage[],\n (BaseMessage | SystemMessage)[],\n RunnableConfig<Record<string, unknown>>\n >\n | undefined {\n if (!instructionsString) {\n // Remove previous tokens if we had a system message before\n this.instructionTokens -= this.systemMessageTokens;\n this.systemMessageTokens = 0;\n return undefined;\n }\n\n let finalInstructions: string | BaseMessageFields = instructionsString;\n\n // Handle Anthropic prompt caching (Direct API)\n if (this.provider === Providers.ANTHROPIC) {\n const anthropicOptions = this.clientOptions as\n | t.AnthropicClientOptions\n | undefined;\n const defaultHeaders = anthropicOptions?.clientOptions?.defaultHeaders as\n | Record<string, string>\n | undefined;\n const anthropicBeta = defaultHeaders?.['anthropic-beta'];\n if (\n typeof anthropicBeta === 'string' &&\n anthropicBeta.includes('prompt-caching')\n ) {\n finalInstructions = {\n content: [\n {\n type: 'text',\n text: instructionsString,\n cache_control: { type: 'ephemeral' },\n },\n ],\n };\n }\n }\n\n // Handle Bedrock prompt caching (Converse API)\n // Adds cachePoint block after text content for system message caching\n // NOTE: Both Claude and Nova models support cachePoint in system and messages\n // (Nova does NOT support cachePoint in tools - that check is in bedrock/index.ts)\n if (this.provider === Providers.BEDROCK) {\n const bedrockOptions = this.clientOptions as\n | t.BedrockAnthropicInput\n | undefined;\n const modelId = bedrockOptions?.model?.toLowerCase() ?? '';\n const supportsCaching = modelId.includes('claude') || modelId.includes('anthropic') || modelId.includes('nova');\n\n if (bedrockOptions?.promptCache === true && supportsCaching) {\n // Always log system cache structure\n console.log(`[Cache] 📝 System | chars=${instructionsString.length} | tokens=${this.systemMessageTokens} | model=${modelId}`);\n \n finalInstructions = {\n content: [\n {\n type: 'text',\n text: instructionsString,\n },\n {\n cachePoint: { type: 'default' },\n },\n ],\n };\n }\n }\n\n const systemMessage = new SystemMessage(finalInstructions);\n\n // Update token counts (subtract old, add new)\n if (this.tokenCounter) {\n this.instructionTokens -= this.systemMessageTokens;\n this.systemMessageTokens = this.tokenCounter(systemMessage);\n this.instructionTokens += this.systemMessageTokens;\n }\n\n return RunnableLambda.from((messages: BaseMessage[]) => {\n return [systemMessage, ...messages];\n }).withConfig({ runName: 'prompt' });\n }\n\n /**\n * Reset context for a new run\n */\n reset(): void {\n this.instructionTokens = 0;\n this.systemMessageTokens = 0;\n this.cachedSystemRunnable = undefined;\n this.systemRunnableStale = true;\n this.lastToken = undefined;\n this.indexTokenCountMap = {};\n this.currentUsage = undefined;\n this.pruneMessages = undefined;\n this.lastStreamCall = undefined;\n this.tokenTypeSwitch = undefined;\n this.currentTokenType = ContentTypes.TEXT;\n this.discoveredToolNames.clear();\n }\n\n /**\n * Update the token count map with instruction tokens\n */\n updateTokenMapWithInstructions(baseTokenMap: Record<string, number>): void {\n if (this.instructionTokens > 0) {\n // Shift all indices by the instruction token count\n const shiftedMap: Record<string, number> = {};\n for (const [key, value] of Object.entries(baseTokenMap)) {\n const index = parseInt(key, 10);\n if (!isNaN(index)) {\n shiftedMap[String(index)] =\n value + (index === 0 ? this.instructionTokens : 0);\n }\n }\n this.indexTokenCountMap = shiftedMap;\n } else {\n this.indexTokenCountMap = { ...baseTokenMap };\n }\n }\n\n /**\n * Calculate tool tokens and add to instruction tokens\n * Note: System message tokens are calculated during systemRunnable creation\n */\n async calculateInstructionTokens(\n tokenCounter: t.TokenCounter\n ): Promise<void> {\n let toolTokens = 0;\n if (this.tools && this.tools.length > 0) {\n for (const tool of this.tools) {\n const genericTool = tool as Record<string, unknown>;\n if (\n genericTool.schema != null &&\n typeof genericTool.schema === 'object'\n ) {\n const schema = genericTool.schema as {\n describe: (desc: string) => unknown;\n };\n const describedSchema = schema.describe(\n (genericTool.description as string) || ''\n );\n const jsonSchema = zodToJsonSchema(\n describedSchema as Parameters<typeof zodToJsonSchema>[0],\n (genericTool.name as string) || ''\n );\n toolTokens += tokenCounter(\n new SystemMessage(JSON.stringify(jsonSchema))\n );\n }\n }\n }\n\n // Add tool tokens to existing instruction tokens (which may already include system message tokens)\n this.instructionTokens += toolTokens;\n }\n\n /**\n * Gets the tool registry for deferred tools (for tool search).\n * @param onlyDeferred If true, only returns tools with defer_loading=true\n * @returns LCToolRegistry with tool definitions\n */\n getDeferredToolRegistry(onlyDeferred: boolean = true): t.LCToolRegistry {\n const registry: t.LCToolRegistry = new Map();\n\n if (!this.toolRegistry) {\n return registry;\n }\n\n for (const [name, toolDef] of this.toolRegistry) {\n if (!onlyDeferred || toolDef.defer_loading === true) {\n registry.set(name, toolDef);\n }\n }\n\n return registry;\n }\n\n /**\n * Marks tools as discovered via tool search.\n * Discovered tools will be included in the next model binding.\n * Only marks system runnable stale if NEW tools were actually added.\n * @param toolNames - Array of discovered tool names\n * @returns true if any new tools were discovered\n */\n markToolsAsDiscovered(toolNames: string[]): boolean {\n let hasNewDiscoveries = false;\n for (const name of toolNames) {\n if (!this.discoveredToolNames.has(name)) {\n this.discoveredToolNames.add(name);\n hasNewDiscoveries = true;\n }\n }\n if (hasNewDiscoveries) {\n this.systemRunnableStale = true;\n }\n return hasNewDiscoveries;\n }\n\n /**\n * Gets tools that should be bound to the LLM.\n * Includes:\n * 1. Non-deferred tools with allowed_callers: ['direct']\n * 2. Discovered tools (from tool search)\n * @returns Array of tools to bind to model\n */\n getToolsForBinding(): t.GraphTools | undefined {\n if (!this.tools || !this.toolRegistry) {\n return this.tools;\n }\n\n const toolsToInclude = this.tools.filter((tool) => {\n if (!('name' in tool)) {\n return true; // No name, include by default\n }\n\n const toolDef = this.toolRegistry?.get(tool.name);\n if (!toolDef) {\n return true; // Not in registry, include by default\n }\n\n // Check if discovered (overrides defer_loading)\n if (this.discoveredToolNames.has(tool.name)) {\n // Discovered tools must still have allowed_callers: ['direct']\n const allowedCallers = toolDef.allowed_callers ?? ['direct'];\n return allowedCallers.includes('direct');\n }\n\n // Not discovered: must be direct-callable AND not deferred\n const allowedCallers = toolDef.allowed_callers ?? ['direct'];\n return (\n allowedCallers.includes('direct') && toolDef.defer_loading !== true\n );\n });\n\n return toolsToInclude;\n }\n}\n"],"names":[],"mappings":";;;;;AAAA;AACA;AAcA;;AAEG;MACU,YAAY,CAAA;AACvB;;AAEG;AACH,IAAA,OAAO,UAAU,CACf,WAA0B,EAC1B,YAA6B,EAC7B,kBAA2C,EAAA;AAE3C,QAAA,MAAM,EACJ,OAAO,EACP,QAAQ,EACR,aAAa,EACb,KAAK,EACL,OAAO,EACP,OAAO,EACP,YAAY,EACZ,YAAY,EACZ,uBAAuB,EACvB,YAAY,EACZ,gBAAgB,EAChB,YAAY,EACZ,gBAAgB,EAChB,cAAc,GACf,GAAG,WAAW;AAE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IAL_CODE_BASEURL"] = "https://api.illuma.ai/v1";
|
|
145
145
|
Constants["EXECUTE_CODE"] = "execute_code";
|
|
146
|
+
Constants["TOOL_SEARCH_REGEX"] = "tool_search_regex";
|
|
147
|
+
Constants["PROGRAMMATIC_TOOL_CALLING"] = "run_tools_with_code";
|
|
146
148
|
Constants["WEB_SEARCH"] = "web_search";
|
|
147
149
|
Constants["CONTENT_AND_ARTIFACT"] = "content_and_artifact";
|
|
148
150
|
Constants["LC_TRANSFER_TO_"] = "lc_transfer_to_";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum.mjs","sources":["../../../src/common/enum.ts"],"sourcesContent":["/**\n * Enum representing the various event types emitted during the execution of runnables.\n * These events provide real-time information about the progress and state of different components.\n *\n * @enum {string}\n */\nexport enum GraphEvents {\n /* Custom Events */\n\n /** [Custom] Agent update event in multi-agent graph/workflow */\n ON_AGENT_UPDATE = 'on_agent_update',\n /** [Custom] Delta event for run steps (message creation and tool calls) */\n ON_RUN_STEP = 'on_run_step',\n /** [Custom] Delta event for run steps (tool calls) */\n ON_RUN_STEP_DELTA = 'on_run_step_delta',\n /** [Custom] Completed event for run steps (tool calls) */\n ON_RUN_STEP_COMPLETED = 'on_run_step_completed',\n /** [Custom] Delta events for messages */\n ON_MESSAGE_DELTA = 'on_message_delta',\n /** [Custom] Reasoning Delta events for messages */\n ON_REASONING_DELTA = 'on_reasoning_delta',\n\n /* Official Events */\n\n /** Custom event, emitted by system */\n ON_CUSTOM_EVENT = 'on_custom_event',\n /** Emitted when a chat model starts processing. */\n CHAT_MODEL_START = 'on_chat_model_start',\n\n /** Emitted when a chat model streams a chunk of its response. */\n CHAT_MODEL_STREAM = 'on_chat_model_stream',\n\n /** Emitted when a chat model completes its processing. */\n CHAT_MODEL_END = 'on_chat_model_end',\n\n /** Emitted when a language model starts processing. */\n LLM_START = 'on_llm_start',\n\n /** Emitted when a language model streams a chunk of its response. */\n LLM_STREAM = 'on_llm_stream',\n\n /** Emitted when a language model completes its processing. */\n LLM_END = 'on_llm_end',\n\n /** Emitted when a chain starts processing. */\n CHAIN_START = 'on_chain_start',\n\n /** Emitted when a chain streams a chunk of its output. */\n CHAIN_STREAM = 'on_chain_stream',\n\n /** Emitted when a chain completes its processing. */\n CHAIN_END = 'on_chain_end',\n\n /** Emitted when a tool starts its operation. */\n TOOL_START = 'on_tool_start',\n\n /** Emitted when a tool completes its operation. */\n TOOL_END = 'on_tool_end',\n\n /** Emitted when a retriever starts its operation. */\n RETRIEVER_START = 'on_retriever_start',\n\n /** Emitted when a retriever completes its operation. */\n RETRIEVER_END = 'on_retriever_end',\n\n /** Emitted when a prompt starts processing. */\n PROMPT_START = 'on_prompt_start',\n\n /** Emitted when a prompt completes its processing. */\n PROMPT_END = 'on_prompt_end',\n}\n\nexport enum Providers {\n OPENAI = 'openAI',\n VERTEXAI = 'vertexai',\n BEDROCK = 'bedrock',\n ANTHROPIC = 'anthropic',\n MISTRALAI = 'mistralai',\n MISTRAL = 'mistral',\n GOOGLE = 'google',\n AZURE = 'azureOpenAI',\n DEEPSEEK = 'deepseek',\n OPENROUTER = 'openrouter',\n XAI = 'xai',\n}\n\nexport enum GraphNodeKeys {\n TOOLS = 'tools=',\n AGENT = 'agent=',\n ROUTER = 'router',\n PRE_TOOLS = 'pre_tools',\n POST_TOOLS = 'post_tools',\n}\n\nexport enum GraphNodeActions {\n TOOL_NODE = 'tool_node',\n CALL_MODEL = 'call_model',\n ROUTE_MESSAGE = 'route_message',\n}\n\nexport enum CommonEvents {\n LANGGRAPH = 'LangGraph',\n}\n\nexport enum StepTypes {\n TOOL_CALLS = 'tool_calls',\n MESSAGE_CREATION = 'message_creation',\n}\n\nexport enum ContentTypes {\n TEXT = 'text',\n ERROR = 'error',\n THINK = 'think',\n TOOL_CALL = 'tool_call',\n IMAGE_URL = 'image_url',\n IMAGE_FILE = 'image_file',\n /** Anthropic */\n THINKING = 'thinking',\n /** Vertex AI / Google Common */\n REASONING = 'reasoning',\n /** Multi-Agent Switch */\n AGENT_UPDATE = 'agent_update',\n /** Bedrock */\n REASONING_CONTENT = 'reasoning_content',\n}\n\nexport enum ToolCallTypes {\n FUNCTION = 'function',\n RETRIEVAL = 'retrieval',\n FILE_SEARCH = 'file_search',\n CODE_INTERPRETER = 'code_interpreter',\n /* Agents Tool Call */\n TOOL_CALL = 'tool_call',\n}\n\nexport enum Callback {\n TOOL_ERROR = 'handleToolError',\n TOOL_START = 'handleToolStart',\n TOOL_END = 'handleToolEnd',\n CUSTOM_EVENT = 'handleCustomEvent',\n /*\n LLM_START = 'handleLLMStart',\n LLM_NEW_TOKEN = 'handleLLMNewToken',\n LLM_ERROR = 'handleLLMError',\n LLM_END = 'handleLLMEnd',\n CHAT_MODEL_START = 'handleChatModelStart',\n CHAIN_START = 'handleChainStart',\n CHAIN_ERROR = 'handleChainError',\n CHAIN_END = 'handleChainEnd',\n TEXT = 'handleText',\n AGENT_ACTION = 'handleAgentAction',\n AGENT_END = 'handleAgentEnd',\n RETRIEVER_START = 'handleRetrieverStart',\n RETRIEVER_END = 'handleRetrieverEnd',\n RETRIEVER_ERROR = 'handleRetrieverError',\n */\n}\n\nexport enum Constants {\n OFFICIAL_CODE_BASEURL = 'https://api.illuma.ai/v1',\n EXECUTE_CODE = 'execute_code',\n WEB_SEARCH = 'web_search',\n CONTENT_AND_ARTIFACT = 'content_and_artifact',\n LC_TRANSFER_TO_ = 'lc_transfer_to_',\n}\n\nexport enum TitleMethod {\n STRUCTURED = 'structured',\n FUNCTIONS = 'functions',\n COMPLETION = 'completion',\n}\n\nexport enum EnvVar {\n CODE_API_KEY = 'CODE_EXECUTOR_API_KEY',\n CODE_BASEURL = 'CODE_EXECUTOR_BASEURL',\n}\n"],"names":[],"mappings":"AAAA;;;;;AAKG;IACS;AAAZ,CAAA,UAAY,WAAW,EAAA;;;AAIrB,IAAA,WAAA,CAAA,iBAAA,CAAA,GAAA,iBAAmC;;AAEnC,IAAA,WAAA,CAAA,aAAA,CAAA,GAAA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Y,QAAQ,EAAA;AAClB,IAAA,QAAA,CAAA,YAAA,CAAA,GAAA,iBAA8B;AAC9B,IAAA,QAAA,CAAA,YAAA,CAAA,GAAA,iBAA8B;AAC9B,IAAA,QAAA,CAAA,UAAA,CAAA,GAAA,eAA0B;AAC1B,IAAA,QAAA,CAAA,cAAA,CAAA,GAAA,mBAAkC;AAClC;;;;;;;;;;;;;;;AAeE;AACJ,CAAC,EArBW,QAAQ,KAAR,QAAQ,GAqBnB,EAAA,CAAA,CAAA;IAEW;AAAZ,CAAA,UAAY,SAAS,EAAA;AACnB,IAAA,SAAA,CAAA,uBAAA,CAAA,GAAA,0BAAkD;AAClD,IAAA,SAAA,CAAA,cAAA,CAAA,GAAA,cAA6B;AAC7B,IAAA,SAAA,CAAA,YAAA,CAAA,GAAA,YAAyB;AACzB,IAAA,SAAA,CAAA,sBAAA,CAAA,GAAA,sBAA6C;AAC7C,IAAA,SAAA,CAAA,iBAAA,CAAA,GAAA,iBAAmC;AACrC,CAAC,
|
|
1
|
+
{"version":3,"file":"enum.mjs","sources":["../../../src/common/enum.ts"],"sourcesContent":["/**\n * Enum representing the various event types emitted during the execution of runnables.\n * These events provide real-time information about the progress and state of different components.\n *\n * @enum {string}\n */\nexport enum GraphEvents {\n /* Custom Events */\n\n /** [Custom] Agent update event in multi-agent graph/workflow */\n ON_AGENT_UPDATE = 'on_agent_update',\n /** [Custom] Delta event for run steps (message creation and tool calls) */\n ON_RUN_STEP = 'on_run_step',\n /** [Custom] Delta event for run steps (tool calls) */\n ON_RUN_STEP_DELTA = 'on_run_step_delta',\n /** [Custom] Completed event for run steps (tool calls) */\n ON_RUN_STEP_COMPLETED = 'on_run_step_completed',\n /** [Custom] Delta events for messages */\n ON_MESSAGE_DELTA = 'on_message_delta',\n /** [Custom] Reasoning Delta events for messages */\n ON_REASONING_DELTA = 'on_reasoning_delta',\n\n /* Official Events */\n\n /** Custom event, emitted by system */\n ON_CUSTOM_EVENT = 'on_custom_event',\n /** Emitted when a chat model starts processing. */\n CHAT_MODEL_START = 'on_chat_model_start',\n\n /** Emitted when a chat model streams a chunk of its response. */\n CHAT_MODEL_STREAM = 'on_chat_model_stream',\n\n /** Emitted when a chat model completes its processing. */\n CHAT_MODEL_END = 'on_chat_model_end',\n\n /** Emitted when a language model starts processing. */\n LLM_START = 'on_llm_start',\n\n /** Emitted when a language model streams a chunk of its response. */\n LLM_STREAM = 'on_llm_stream',\n\n /** Emitted when a language model completes its processing. */\n LLM_END = 'on_llm_end',\n\n /** Emitted when a chain starts processing. */\n CHAIN_START = 'on_chain_start',\n\n /** Emitted when a chain streams a chunk of its output. */\n CHAIN_STREAM = 'on_chain_stream',\n\n /** Emitted when a chain completes its processing. */\n CHAIN_END = 'on_chain_end',\n\n /** Emitted when a tool starts its operation. */\n TOOL_START = 'on_tool_start',\n\n /** Emitted when a tool completes its operation. */\n TOOL_END = 'on_tool_end',\n\n /** Emitted when a retriever starts its operation. */\n RETRIEVER_START = 'on_retriever_start',\n\n /** Emitted when a retriever completes its operation. */\n RETRIEVER_END = 'on_retriever_end',\n\n /** Emitted when a prompt starts processing. */\n PROMPT_START = 'on_prompt_start',\n\n /** Emitted when a prompt completes its processing. */\n PROMPT_END = 'on_prompt_end',\n}\n\nexport enum Providers {\n OPENAI = 'openAI',\n VERTEXAI = 'vertexai',\n BEDROCK = 'bedrock',\n ANTHROPIC = 'anthropic',\n MISTRALAI = 'mistralai',\n MISTRAL = 'mistral',\n GOOGLE = 'google',\n AZURE = 'azureOpenAI',\n DEEPSEEK = 'deepseek',\n OPENROUTER = 'openrouter',\n XAI = 'xai',\n}\n\nexport enum GraphNodeKeys {\n TOOLS = 'tools=',\n AGENT = 'agent=',\n ROUTER = 'router',\n PRE_TOOLS = 'pre_tools',\n POST_TOOLS = 'post_tools',\n}\n\nexport enum GraphNodeActions {\n TOOL_NODE = 'tool_node',\n CALL_MODEL = 'call_model',\n ROUTE_MESSAGE = 'route_message',\n}\n\nexport enum CommonEvents {\n LANGGRAPH = 'LangGraph',\n}\n\nexport enum StepTypes {\n TOOL_CALLS = 'tool_calls',\n MESSAGE_CREATION = 'message_creation',\n}\n\nexport enum ContentTypes {\n TEXT = 'text',\n ERROR = 'error',\n THINK = 'think',\n TOOL_CALL = 'tool_call',\n IMAGE_URL = 'image_url',\n IMAGE_FILE = 'image_file',\n /** Anthropic */\n THINKING = 'thinking',\n /** Vertex AI / Google Common */\n REASONING = 'reasoning',\n /** Multi-Agent Switch */\n AGENT_UPDATE = 'agent_update',\n /** Bedrock */\n REASONING_CONTENT = 'reasoning_content',\n}\n\nexport enum ToolCallTypes {\n FUNCTION = 'function',\n RETRIEVAL = 'retrieval',\n FILE_SEARCH = 'file_search',\n CODE_INTERPRETER = 'code_interpreter',\n /* Agents Tool Call */\n TOOL_CALL = 'tool_call',\n}\n\nexport enum Callback {\n TOOL_ERROR = 'handleToolError',\n TOOL_START = 'handleToolStart',\n TOOL_END = 'handleToolEnd',\n CUSTOM_EVENT = 'handleCustomEvent',\n /*\n LLM_START = 'handleLLMStart',\n LLM_NEW_TOKEN = 'handleLLMNewToken',\n LLM_ERROR = 'handleLLMError',\n LLM_END = 'handleLLMEnd',\n CHAT_MODEL_START = 'handleChatModelStart',\n CHAIN_START = 'handleChainStart',\n CHAIN_ERROR = 'handleChainError',\n CHAIN_END = 'handleChainEnd',\n TEXT = 'handleText',\n AGENT_ACTION = 'handleAgentAction',\n AGENT_END = 'handleAgentEnd',\n RETRIEVER_START = 'handleRetrieverStart',\n RETRIEVER_END = 'handleRetrieverEnd',\n RETRIEVER_ERROR = 'handleRetrieverError',\n */\n}\n\nexport enum Constants {\n OFFICIAL_CODE_BASEURL = 'https://api.illuma.ai/v1',\n EXECUTE_CODE = 'execute_code',\n TOOL_SEARCH_REGEX = 'tool_search_regex',\n PROGRAMMATIC_TOOL_CALLING = 'run_tools_with_code',\n WEB_SEARCH = 'web_search',\n CONTENT_AND_ARTIFACT = 'content_and_artifact',\n LC_TRANSFER_TO_ = 'lc_transfer_to_',\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,CAAA,GAAA,WAAuB;AACvB,IAAA,WAAA,CAAA,YAAA,CAAA,GAAA,YAAyB;AAC3B,CAAC,EAJW,WAAW,KAAX,WAAW,GAItB,EAAA,CAAA,CAAA;IAEW;AAAZ,CAAA,UAAY,MAAM,EAAA;AAChB,IAAA,MAAA,CAAA,cAAA,CAAA,GAAA,uBAAsC;AACtC,IAAA,MAAA,CAAA,cAAA,CAAA,GAAA,uBAAsC;AACxC,CAAC,EAHW,MAAM,KAAN,MAAM,GAGjB,EAAA,CAAA,CAAA;;;;"}
|
package/dist/esm/events.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { handleToolCalls } from './tools/handlers.mjs';
|
|
2
|
-
import { Providers } from './common/enum.mjs';
|
|
2
|
+
import { Providers, Constants } from './common/enum.mjs';
|
|
3
3
|
|
|
4
4
|
class HandlerRegistry {
|
|
5
5
|
handlers = new Map();
|
|
@@ -52,17 +52,6 @@ class ToolEndHandler {
|
|
|
52
52
|
this.omitOutput = omitOutput;
|
|
53
53
|
}
|
|
54
54
|
async handle(event, data, metadata, graph) {
|
|
55
|
-
const toolData = data;
|
|
56
|
-
const output = toolData?.output;
|
|
57
|
-
console.log('[ToolEndHandler] handle called', {
|
|
58
|
-
event,
|
|
59
|
-
hasData: !!data,
|
|
60
|
-
hasGraph: !!graph,
|
|
61
|
-
hasMetadata: !!metadata,
|
|
62
|
-
hasCallback: !!this.callback,
|
|
63
|
-
outputName: output?.name,
|
|
64
|
-
hasArtifact: !!output?.artifact,
|
|
65
|
-
});
|
|
66
55
|
try {
|
|
67
56
|
if (!graph || !metadata) {
|
|
68
57
|
if (this.logger) {
|
|
@@ -83,6 +72,9 @@ class ToolEndHandler {
|
|
|
83
72
|
}
|
|
84
73
|
return;
|
|
85
74
|
}
|
|
75
|
+
if (metadata[Constants.PROGRAMMATIC_TOOL_CALLING] === true) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
86
78
|
if (this.callback) {
|
|
87
79
|
await this.callback(toolEndData, metadata);
|
|
88
80
|
}
|
package/dist/esm/events.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.mjs","sources":["../../src/events.ts"],"sourcesContent":["/* eslint-disable no-console */\n// src/events.ts\nimport type {\n ToolMessage,\n UsageMetadata,\n BaseMessageFields,\n} from '@langchain/core/messages';\nimport type { MultiAgentGraph, StandardGraph } from '@/graphs';\nimport type { Logger } from 'winston';\nimport type * as t from '@/types';\nimport { handleToolCalls } from '@/tools/handlers';\nimport { Providers } from '@/common';\n\nexport class HandlerRegistry {\n private handlers: Map<string, t.EventHandler> = new Map();\n\n register(eventType: string, handler: t.EventHandler): void {\n this.handlers.set(eventType, handler);\n }\n\n getHandler(eventType: string): t.EventHandler | undefined {\n return this.handlers.get(eventType);\n }\n}\n\nexport class ModelEndHandler implements t.EventHandler {\n collectedUsage?: UsageMetadata[];\n constructor(collectedUsage?: UsageMetadata[]) {\n if (collectedUsage && !Array.isArray(collectedUsage)) {\n throw new Error('collectedUsage must be an array');\n }\n this.collectedUsage = collectedUsage;\n }\n\n async handle(\n event: string,\n data: t.ModelEndData,\n metadata?: Record<string, unknown>,\n graph?: StandardGraph | MultiAgentGraph\n ): Promise<void> {\n if (!graph || !metadata) {\n console.warn(`Graph or metadata not found in ${event} event`);\n return;\n }\n\n const usage = data?.output?.usage_metadata;\n if (usage != null && this.collectedUsage != null) {\n this.collectedUsage.push(usage);\n }\n\n if (metadata.ls_provider === 'FakeListChatModel') {\n return handleToolCalls(data?.output?.tool_calls, metadata, graph);\n }\n\n console.log(`====== ${event.toUpperCase()} ======`);\n console.dir(\n {\n usage,\n },\n { depth: null }\n );\n\n const agentContext = graph.getAgentContext(metadata);\n\n if (\n agentContext.provider !== Providers.GOOGLE &&\n agentContext.provider !== Providers.BEDROCK\n ) {\n return;\n }\n\n await handleToolCalls(data?.output?.tool_calls, metadata, graph);\n }\n}\n\nexport class ToolEndHandler implements t.EventHandler {\n private callback?: t.ToolEndCallback;\n private logger?: Logger;\n private omitOutput?: (name?: string) => boolean;\n constructor(\n callback?: t.ToolEndCallback,\n logger?: Logger,\n omitOutput?: (name?: string) => boolean\n ) {\n this.callback = callback;\n this.logger = logger;\n this.omitOutput = omitOutput;\n }\n async handle(\n event: string,\n data: t.StreamEventData | undefined,\n metadata?: Record<string, unknown>,\n graph?: StandardGraph | MultiAgentGraph\n ): Promise<void> {\n const toolData = data as t.ToolEndData;\n const output = toolData?.output as ToolMessage | undefined;\n console.log('[ToolEndHandler] handle called', { \n event, \n hasData: !!data,\n hasGraph: !!graph,\n hasMetadata: !!metadata,\n hasCallback: !!this.callback,\n outputName: output?.name,\n hasArtifact: !!output?.artifact,\n });\n try {\n if (!graph || !metadata) {\n if (this.logger) {\n this.logger.warn(`Graph or metadata not found in ${event} event`);\n } else {\n console.warn(`Graph or metadata not found in ${event} event`);\n }\n return;\n }\n\n const toolEndData = data as t.ToolEndData | undefined;\n if (!toolEndData?.output) {\n if (this.logger) {\n this.logger.warn('No output found in tool_end event');\n } else {\n console.warn('No output found in tool_end event');\n }\n return;\n }\n\n if (this.callback) {\n await this.callback(toolEndData, metadata);\n }\n await graph.handleToolCallCompleted(\n { input: toolEndData.input, output: toolEndData.output },\n metadata,\n this.omitOutput?.((toolEndData.output as ToolMessage | undefined)?.name)\n );\n } catch (error) {\n if (this.logger) {\n this.logger.error('Error handling tool_end event:', error);\n } else {\n console.error('Error handling tool_end event:', error);\n }\n }\n }\n}\n\nexport class TestLLMStreamHandler implements t.EventHandler {\n handle(event: string, data: t.StreamEventData | undefined): void {\n const chunk = data?.chunk;\n const isMessageChunk = !!(chunk && 'message' in chunk);\n const msg = isMessageChunk ? chunk.message : undefined;\n if (msg && msg.tool_call_chunks && msg.tool_call_chunks.length > 0) {\n console.log(msg.tool_call_chunks);\n } else if (msg && msg.content) {\n if (typeof msg.content === 'string') {\n process.stdout.write(msg.content);\n }\n }\n }\n}\n\nexport class TestChatStreamHandler implements t.EventHandler {\n handle(event: string, data: t.StreamEventData | undefined): void {\n const chunk = data?.chunk;\n const isContentChunk = !!(chunk && 'content' in chunk);\n const content = isContentChunk && chunk.content;\n\n if (!content || !isContentChunk) {\n return;\n }\n\n if (chunk.tool_call_chunks && chunk.tool_call_chunks.length > 0) {\n console.dir(chunk.tool_call_chunks, { depth: null });\n }\n\n if (typeof content === 'string') {\n process.stdout.write(content);\n } else {\n console.dir(content, { depth: null });\n }\n }\n}\n\nexport class LLMStreamHandler implements t.EventHandler {\n handle(\n event: string,\n data: t.StreamEventData | undefined,\n metadata?: Record<string, unknown>\n ): void {\n const chunk = data?.chunk;\n const isMessageChunk = !!(chunk && 'message' in chunk);\n const msg = isMessageChunk && chunk.message;\n if (metadata) {\n console.log(metadata);\n }\n if (msg && msg.tool_call_chunks && msg.tool_call_chunks.length > 0) {\n console.log(msg.tool_call_chunks);\n } else if (msg && msg.content) {\n if (typeof msg.content === 'string') {\n // const text_delta = msg.content;\n // dispatchCustomEvent(GraphEvents.CHAT_MODEL_STREAM, { chunk }, config);\n process.stdout.write(msg.content);\n }\n }\n }\n}\n\nexport const createMetadataAggregator = (\n _collected?: Record<\n string,\n NonNullable<BaseMessageFields['response_metadata']>\n >[]\n): t.MetadataAggregatorResult => {\n const collected = _collected || [];\n\n const handleLLMEnd: t.HandleLLMEnd = (output) => {\n const { generations } = output;\n const lastMessageOutput = (\n generations[generations.length - 1] as\n | (t.StreamGeneration | undefined)[]\n | undefined\n )?.[0];\n if (!lastMessageOutput) {\n return;\n }\n const { message } = lastMessageOutput;\n if (message?.response_metadata) {\n collected.push(message.response_metadata);\n }\n };\n\n return { handleLLMEnd, collected };\n};\n"],"names":[],"mappings":";;;MAaa,eAAe,CAAA;AAClB,IAAA,QAAQ,GAAgC,IAAI,GAAG,EAAE;IAEzD,QAAQ,CAAC,SAAiB,EAAE,OAAuB,EAAA;QACjD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC;;AAGvC,IAAA,UAAU,C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IAAI,GAAG,CAAC,gBAAgB,IAAI,GAAG,CAAC,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE;AAClE,YAAA,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,gBAAgB,CAAC;;AAC5B,aAAA,IAAI,GAAG,IAAI,GAAG,CAAC,OAAO,EAAE;AAC7B,YAAA,IAAI,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ,EAAE;;;gBAGnC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC;;;;AAIxC;AAEY,MAAA,wBAAwB,GAAG,CACtC,UAGG,KAC2B;AAC9B,IAAA,MAAM,SAAS,GAAG,UAAU,IAAI,EAAE;AAElC,IAAA,MAAM,YAAY,GAAmB,CAAC,MAAM,KAAI;AAC9C,QAAA,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM;AAC9B,QAAA,MAAM,iBAAiB,GACrB,WAAW,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAGnC,GAAG,CAAC,CAAC;QACN,IAAI,CAAC,iBAAiB,EAAE;YACtB;;AAEF,QAAA,MAAM,EAAE,OAAO,EAAE,GAAG,iBAAiB;AACrC,QAAA,IAAI,OAAO,EAAE,iBAAiB,EAAE;AAC9B,YAAA,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC;;AAE7C,KAAC;AAED,IAAA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE;AACpC;;;;"}
|
|
1
|
+
{"version":3,"file":"events.mjs","sources":["../../src/events.ts"],"sourcesContent":["/* eslint-disable no-console */\n// src/events.ts\nimport type {\n ToolMessage,\n UsageMetadata,\n BaseMessageFields,\n} from '@langchain/core/messages';\nimport type { MultiAgentGraph, StandardGraph } from '@/graphs';\nimport type { Logger } from 'winston';\nimport type * as t from '@/types';\nimport { handleToolCalls } from '@/tools/handlers';\nimport { Constants, Providers } from '@/common';\n\nexport class HandlerRegistry {\n private handlers: Map<string, t.EventHandler> = new Map();\n\n register(eventType: string, handler: t.EventHandler): void {\n this.handlers.set(eventType, handler);\n }\n\n getHandler(eventType: string): t.EventHandler | undefined {\n return this.handlers.get(eventType);\n }\n}\n\nexport class ModelEndHandler implements t.EventHandler {\n collectedUsage?: UsageMetadata[];\n constructor(collectedUsage?: UsageMetadata[]) {\n if (collectedUsage && !Array.isArray(collectedUsage)) {\n throw new Error('collectedUsage must be an array');\n }\n this.collectedUsage = collectedUsage;\n }\n\n async handle(\n event: string,\n data: t.ModelEndData,\n metadata?: Record<string, unknown>,\n graph?: StandardGraph | MultiAgentGraph\n ): Promise<void> {\n if (!graph || !metadata) {\n console.warn(`Graph or metadata not found in ${event} event`);\n return;\n }\n\n const usage = data?.output?.usage_metadata;\n if (usage != null && this.collectedUsage != null) {\n this.collectedUsage.push(usage);\n }\n\n if (metadata.ls_provider === 'FakeListChatModel') {\n return handleToolCalls(data?.output?.tool_calls, metadata, graph);\n }\n\n console.log(`====== ${event.toUpperCase()} ======`);\n console.dir(\n {\n usage,\n },\n { depth: null }\n );\n\n const agentContext = graph.getAgentContext(metadata);\n\n if (\n agentContext.provider !== Providers.GOOGLE &&\n agentContext.provider !== Providers.BEDROCK\n ) {\n return;\n }\n\n await handleToolCalls(data?.output?.tool_calls, metadata, graph);\n }\n}\n\nexport class ToolEndHandler implements t.EventHandler {\n private callback?: t.ToolEndCallback;\n private logger?: Logger;\n private omitOutput?: (name?: string) => boolean;\n constructor(\n callback?: t.ToolEndCallback,\n logger?: Logger,\n omitOutput?: (name?: string) => boolean\n ) {\n this.callback = callback;\n this.logger = logger;\n this.omitOutput = omitOutput;\n }\n async handle(\n event: string,\n data: t.StreamEventData | undefined,\n metadata?: Record<string, unknown>,\n graph?: StandardGraph | MultiAgentGraph\n ): Promise<void> {\n try {\n if (!graph || !metadata) {\n if (this.logger) {\n this.logger.warn(`Graph or metadata not found in ${event} event`);\n } else {\n console.warn(`Graph or metadata not found in ${event} event`);\n }\n return;\n }\n\n const toolEndData = data as t.ToolEndData | undefined;\n if (!toolEndData?.output) {\n if (this.logger) {\n this.logger.warn('No output found in tool_end event');\n } else {\n console.warn('No output found in tool_end event');\n }\n return;\n }\n\n if (metadata[Constants.PROGRAMMATIC_TOOL_CALLING] === true) {\n return;\n }\n\n if (this.callback) {\n await this.callback(toolEndData, metadata);\n }\n await graph.handleToolCallCompleted(\n { input: toolEndData.input, output: toolEndData.output },\n metadata,\n this.omitOutput?.((toolEndData.output as ToolMessage | undefined)?.name)\n );\n } catch (error) {\n if (this.logger) {\n this.logger.error('Error handling tool_end event:', error);\n } else {\n console.error('Error handling tool_end event:', error);\n }\n }\n }\n}\n\nexport class TestLLMStreamHandler implements t.EventHandler {\n handle(event: string, data: t.StreamEventData | undefined): void {\n const chunk = data?.chunk;\n const isMessageChunk = !!(chunk && 'message' in chunk);\n const msg = isMessageChunk ? chunk.message : undefined;\n if (msg && msg.tool_call_chunks && msg.tool_call_chunks.length > 0) {\n console.log(msg.tool_call_chunks);\n } else if (msg && msg.content) {\n if (typeof msg.content === 'string') {\n process.stdout.write(msg.content);\n }\n }\n }\n}\n\nexport class TestChatStreamHandler implements t.EventHandler {\n handle(event: string, data: t.StreamEventData | undefined): void {\n const chunk = data?.chunk;\n const isContentChunk = !!(chunk && 'content' in chunk);\n const content = isContentChunk && chunk.content;\n\n if (!content || !isContentChunk) {\n return;\n }\n\n if (chunk.tool_call_chunks && chunk.tool_call_chunks.length > 0) {\n console.dir(chunk.tool_call_chunks, { depth: null });\n }\n\n if (typeof content === 'string') {\n process.stdout.write(content);\n } else {\n console.dir(content, { depth: null });\n }\n }\n}\n\nexport class LLMStreamHandler implements t.EventHandler {\n handle(\n event: string,\n data: t.StreamEventData | undefined,\n metadata?: Record<string, unknown>\n ): void {\n const chunk = data?.chunk;\n const isMessageChunk = !!(chunk && 'message' in chunk);\n const msg = isMessageChunk && chunk.message;\n if (metadata) {\n console.log(metadata);\n }\n if (msg && msg.tool_call_chunks && msg.tool_call_chunks.length > 0) {\n console.log(msg.tool_call_chunks);\n } else if (msg && msg.content) {\n if (typeof msg.content === 'string') {\n // const text_delta = msg.content;\n // dispatchCustomEvent(GraphEvents.CHAT_MODEL_STREAM, { chunk }, config);\n process.stdout.write(msg.content);\n }\n }\n }\n}\n\nexport const createMetadataAggregator = (\n _collected?: Record<\n string,\n NonNullable<BaseMessageFields['response_metadata']>\n >[]\n): t.MetadataAggregatorResult => {\n const collected = _collected || [];\n\n const handleLLMEnd: t.HandleLLMEnd = (output) => {\n const { generations } = output;\n const lastMessageOutput = (\n generations[generations.length - 1] as\n | (t.StreamGeneration | undefined)[]\n | undefined\n )?.[0];\n if (!lastMessageOutput) {\n return;\n }\n const { message } = lastMessageOutput;\n if (message?.response_metadata) {\n collected.push(message.response_metadata);\n }\n };\n\n return { handleLLMEnd, collected };\n};\n"],"names":[],"mappings":";;;MAaa,eAAe,CAAA;AAClB,IAAA,QAAQ,GAAgC,IAAI,GAAG,EAAE;IAEzD,QAAQ,CAAC,SAAiB,EAAE,OAAuB,EAAA;QACjD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC;;AAGvC,IAAA,UAAU,CAAC,SAAiB,EAAA;QAC1B,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC;;AAEtC;MAEY,eAAe,CAAA;AAC1B,IAAA,cAAc;AACd,IAAA,WAAA,CAAY,cAAgC,EAAA;QAC1C,IAAI,cAAc,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE;AACpD,YAAA,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC;;AAEpD,QAAA,IAAI,CAAC,cAAc,GAAG,cAAc;;IAGtC,MAAM,MAAM,CACV,KAAa,EACb,IAAoB,EACpB,QAAkC,EAClC,KAAuC,EAAA;AAEvC,QAAA,IAAI,CAAC,KAAK,IAAI,CAAC,QAAQ,EAAE;AACvB,YAAA,OAAO,CAAC,IAAI,CAAC,kCAAkC,KAAK,CAA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