@illuma-ai/agents 1.1.28 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/agents/AgentContext.cjs.map +1 -1
- package/dist/cjs/common/spawnPath.cjs +104 -0
- package/dist/cjs/common/spawnPath.cjs.map +1 -0
- package/dist/cjs/graphs/Graph.cjs +84 -33
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/graphs/HandoffRegistry.cjs +47 -8
- package/dist/cjs/graphs/HandoffRegistry.cjs.map +1 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs +493 -267
- package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
- package/dist/cjs/graphs/phases/flushLoop.cjs +214 -0
- package/dist/cjs/graphs/phases/flushLoop.cjs.map +1 -0
- package/dist/cjs/graphs/phases/memoryFlushPhase.cjs +102 -0
- package/dist/cjs/graphs/phases/memoryFlushPhase.cjs.map +1 -0
- package/dist/cjs/llm/bedrock/index.cjs +4 -3
- package/dist/cjs/llm/bedrock/index.cjs.map +1 -1
- package/dist/cjs/main.cjs +113 -0
- package/dist/cjs/main.cjs.map +1 -1
- package/dist/cjs/memory/citations.cjs +69 -0
- package/dist/cjs/memory/citations.cjs.map +1 -0
- package/dist/cjs/memory/compositeBackend.cjs +60 -0
- package/dist/cjs/memory/compositeBackend.cjs.map +1 -0
- package/dist/cjs/memory/constants.cjs +232 -0
- package/dist/cjs/memory/constants.cjs.map +1 -0
- package/dist/cjs/memory/embeddings.cjs +151 -0
- package/dist/cjs/memory/embeddings.cjs.map +1 -0
- package/dist/cjs/memory/factory.cjs +95 -0
- package/dist/cjs/memory/factory.cjs.map +1 -0
- package/dist/cjs/memory/migrate.cjs +81 -0
- package/dist/cjs/memory/migrate.cjs.map +1 -0
- package/dist/cjs/memory/mmr.cjs +138 -0
- package/dist/cjs/memory/mmr.cjs.map +1 -0
- package/dist/cjs/memory/paths.cjs +217 -0
- package/dist/cjs/memory/paths.cjs.map +1 -0
- package/dist/cjs/memory/pgvectorStore.cjs +225 -0
- package/dist/cjs/memory/pgvectorStore.cjs.map +1 -0
- package/dist/cjs/memory/recallTracking.cjs +98 -0
- package/dist/cjs/memory/recallTracking.cjs.map +1 -0
- package/dist/cjs/memory/schema.sql +51 -0
- package/dist/cjs/memory/temporalDecay.cjs +118 -0
- package/dist/cjs/memory/temporalDecay.cjs.map +1 -0
- package/dist/cjs/nodes/ApprovalGateNode.cjs +1 -1
- package/dist/cjs/nodes/ApprovalGateNode.cjs.map +1 -1
- package/dist/cjs/prompts/memoryFlushPrompt.cjs +49 -0
- package/dist/cjs/prompts/memoryFlushPrompt.cjs.map +1 -0
- package/dist/cjs/run.cjs +16 -3
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/tools/AskUser.cjs +6 -1
- package/dist/cjs/tools/AskUser.cjs.map +1 -1
- package/dist/cjs/tools/BrowserTools.cjs +1 -1
- package/dist/cjs/tools/BrowserTools.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +127 -10
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/approval/constants.cjs +2 -2
- package/dist/cjs/tools/approval/constants.cjs.map +1 -1
- package/dist/cjs/tools/memory/index.cjs +58 -0
- package/dist/cjs/tools/memory/index.cjs.map +1 -0
- package/dist/cjs/tools/memory/memoryAppendTool.cjs +69 -0
- package/dist/cjs/tools/memory/memoryAppendTool.cjs.map +1 -0
- package/dist/cjs/tools/memory/memoryGetTool.cjs +49 -0
- package/dist/cjs/tools/memory/memoryGetTool.cjs.map +1 -0
- package/dist/cjs/tools/memory/memorySearchTool.cjs +65 -0
- package/dist/cjs/tools/memory/memorySearchTool.cjs.map +1 -0
- package/dist/cjs/tools/memory/shared.cjs +106 -0
- package/dist/cjs/tools/memory/shared.cjs.map +1 -0
- package/dist/cjs/types/graph.cjs.map +1 -1
- package/dist/cjs/utils/childAgentContext.cjs +242 -0
- package/dist/cjs/utils/childAgentContext.cjs.map +1 -0
- package/dist/cjs/utils/events.cjs +36 -7
- package/dist/cjs/utils/events.cjs.map +1 -1
- package/dist/cjs/utils/finishReasons.cjs +44 -0
- package/dist/cjs/utils/finishReasons.cjs.map +1 -0
- package/dist/cjs/utils/llm.cjs.map +1 -1
- package/dist/cjs/utils/logging.cjs +34 -0
- package/dist/cjs/utils/logging.cjs.map +1 -0
- package/dist/cjs/utils/toolCallNormalization.cjs +250 -0
- package/dist/cjs/utils/toolCallNormalization.cjs.map +1 -0
- package/dist/esm/agents/AgentContext.mjs.map +1 -1
- package/dist/esm/common/spawnPath.mjs +95 -0
- package/dist/esm/common/spawnPath.mjs.map +1 -0
- package/dist/esm/graphs/Graph.mjs +84 -33
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/graphs/HandoffRegistry.mjs +47 -8
- package/dist/esm/graphs/HandoffRegistry.mjs.map +1 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs +493 -267
- package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
- package/dist/esm/graphs/phases/flushLoop.mjs +209 -0
- package/dist/esm/graphs/phases/flushLoop.mjs.map +1 -0
- package/dist/esm/graphs/phases/memoryFlushPhase.mjs +99 -0
- package/dist/esm/graphs/phases/memoryFlushPhase.mjs.map +1 -0
- package/dist/esm/llm/bedrock/index.mjs +4 -3
- package/dist/esm/llm/bedrock/index.mjs.map +1 -1
- package/dist/esm/main.mjs +20 -0
- package/dist/esm/main.mjs.map +1 -1
- package/dist/esm/memory/citations.mjs +64 -0
- package/dist/esm/memory/citations.mjs.map +1 -0
- package/dist/esm/memory/compositeBackend.mjs +58 -0
- package/dist/esm/memory/compositeBackend.mjs.map +1 -0
- package/dist/esm/memory/constants.mjs +198 -0
- package/dist/esm/memory/constants.mjs.map +1 -0
- package/dist/esm/memory/embeddings.mjs +148 -0
- package/dist/esm/memory/embeddings.mjs.map +1 -0
- package/dist/esm/memory/factory.mjs +93 -0
- package/dist/esm/memory/factory.mjs.map +1 -0
- package/dist/esm/memory/migrate.mjs +78 -0
- package/dist/esm/memory/migrate.mjs.map +1 -0
- package/dist/esm/memory/mmr.mjs +130 -0
- package/dist/esm/memory/mmr.mjs.map +1 -0
- package/dist/esm/memory/paths.mjs +207 -0
- package/dist/esm/memory/paths.mjs.map +1 -0
- package/dist/esm/memory/pgvectorStore.mjs +223 -0
- package/dist/esm/memory/pgvectorStore.mjs.map +1 -0
- package/dist/esm/memory/recallTracking.mjs +94 -0
- package/dist/esm/memory/recallTracking.mjs.map +1 -0
- package/dist/esm/memory/schema.sql +51 -0
- package/dist/esm/memory/temporalDecay.mjs +110 -0
- package/dist/esm/memory/temporalDecay.mjs.map +1 -0
- package/dist/esm/nodes/ApprovalGateNode.mjs +1 -1
- package/dist/esm/nodes/ApprovalGateNode.mjs.map +1 -1
- package/dist/esm/prompts/memoryFlushPrompt.mjs +44 -0
- package/dist/esm/prompts/memoryFlushPrompt.mjs.map +1 -0
- package/dist/esm/run.mjs +16 -3
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/tools/AskUser.mjs +6 -1
- package/dist/esm/tools/AskUser.mjs.map +1 -1
- package/dist/esm/tools/BrowserTools.mjs +1 -1
- package/dist/esm/tools/BrowserTools.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +128 -11
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/approval/constants.mjs +2 -2
- package/dist/esm/tools/approval/constants.mjs.map +1 -1
- package/dist/esm/tools/memory/index.mjs +46 -0
- package/dist/esm/tools/memory/index.mjs.map +1 -0
- package/dist/esm/tools/memory/memoryAppendTool.mjs +67 -0
- package/dist/esm/tools/memory/memoryAppendTool.mjs.map +1 -0
- package/dist/esm/tools/memory/memoryGetTool.mjs +47 -0
- package/dist/esm/tools/memory/memoryGetTool.mjs.map +1 -0
- package/dist/esm/tools/memory/memorySearchTool.mjs +63 -0
- package/dist/esm/tools/memory/memorySearchTool.mjs.map +1 -0
- package/dist/esm/tools/memory/shared.mjs +98 -0
- package/dist/esm/tools/memory/shared.mjs.map +1 -0
- package/dist/esm/types/graph.mjs.map +1 -1
- package/dist/esm/utils/childAgentContext.mjs +237 -0
- package/dist/esm/utils/childAgentContext.mjs.map +1 -0
- package/dist/esm/utils/events.mjs +36 -8
- package/dist/esm/utils/events.mjs.map +1 -1
- package/dist/esm/utils/finishReasons.mjs +41 -0
- package/dist/esm/utils/finishReasons.mjs.map +1 -0
- package/dist/esm/utils/llm.mjs.map +1 -1
- package/dist/esm/utils/logging.mjs +31 -0
- package/dist/esm/utils/logging.mjs.map +1 -0
- package/dist/esm/utils/toolCallNormalization.mjs +247 -0
- package/dist/esm/utils/toolCallNormalization.mjs.map +1 -0
- package/dist/types/common/index.d.ts +1 -0
- package/dist/types/common/spawnPath.d.ts +59 -0
- package/dist/types/graphs/HandoffRegistry.d.ts +24 -7
- package/dist/types/graphs/MultiAgentGraph.d.ts +43 -23
- package/dist/types/graphs/phases/flushLoop.d.ts +106 -0
- package/dist/types/graphs/phases/memoryFlushPhase.d.ts +100 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/memory/__tests__/mockBackend.d.ts +40 -0
- package/dist/types/memory/citations.d.ts +39 -0
- package/dist/types/memory/compositeBackend.d.ts +30 -0
- package/dist/types/memory/constants.d.ts +121 -0
- package/dist/types/memory/embeddings.d.ts +15 -0
- package/dist/types/memory/factory.d.ts +23 -0
- package/dist/types/memory/index.d.ts +21 -0
- package/dist/types/memory/migrate.d.ts +14 -0
- package/dist/types/memory/mmr.d.ts +50 -0
- package/dist/types/memory/paths.d.ts +107 -0
- package/dist/types/memory/pgvectorStore.d.ts +56 -0
- package/dist/types/memory/recallTracking.d.ts +30 -0
- package/dist/types/memory/temporalDecay.d.ts +53 -0
- package/dist/types/memory/types.d.ts +182 -0
- package/dist/types/prompts/memoryFlushPrompt.d.ts +54 -0
- package/dist/types/run.d.ts +1 -0
- package/dist/types/tools/AskUser.d.ts +1 -1
- package/dist/types/tools/BrowserTools.d.ts +2 -2
- package/dist/types/tools/approval/constants.d.ts +2 -2
- package/dist/types/tools/memory/index.d.ts +39 -0
- package/dist/types/tools/memory/memoryAppendTool.d.ts +27 -0
- package/dist/types/tools/memory/memoryGetTool.d.ts +22 -0
- package/dist/types/tools/memory/memorySearchTool.d.ts +22 -0
- package/dist/types/tools/memory/shared.d.ts +106 -0
- package/dist/types/types/graph.d.ts +10 -3
- package/dist/types/utils/childAgentContext.d.ts +99 -0
- package/dist/types/utils/events.d.ts +21 -0
- package/dist/types/utils/finishReasons.d.ts +32 -0
- package/dist/types/utils/logging.d.ts +2 -0
- package/dist/types/utils/toolCallNormalization.d.ts +44 -0
- package/package.json +6 -4
- package/src/agents/AgentContext.ts +12 -4
- package/src/common/__tests__/enum.test.ts +4 -2
- package/src/common/__tests__/spawnPath.test.ts +110 -0
- package/src/common/index.ts +1 -0
- package/src/common/spawnPath.ts +101 -0
- package/src/graphs/Graph.ts +90 -47
- package/src/graphs/HandoffRegistry.ts +48 -17
- package/src/graphs/MultiAgentGraph.ts +588 -327
- package/src/graphs/__tests__/HandoffRegistry.test.ts +4 -1
- package/src/graphs/__tests__/multi-agent-delegate.test.ts +61 -16
- package/src/graphs/__tests__/multi-agent-edges.test.ts +4 -2
- package/src/graphs/__tests__/multi-agent-nested-subgraph.test.ts +221 -0
- package/src/graphs/__tests__/structured-output.integration.test.ts +212 -118
- package/src/graphs/contextManagement.e2e.test.ts +1 -1
- package/src/graphs/phases/__tests__/flushLoop.test.ts +264 -0
- package/src/graphs/phases/__tests__/memoryFlushPhase.test.ts +37 -0
- package/src/graphs/phases/__tests__/runMemoryFlush.test.ts +150 -0
- package/src/graphs/phases/flushLoop.ts +303 -0
- package/src/graphs/phases/memoryFlushPhase.ts +209 -0
- package/src/index.ts +30 -1
- package/src/llm/bedrock/index.ts +4 -5
- package/src/memory/__tests__/citations.test.ts +61 -0
- package/src/memory/__tests__/compositeBackend.test.ts +79 -0
- package/src/memory/__tests__/isolation.test.ts +206 -0
- package/src/memory/__tests__/mmr.test.ts +148 -0
- package/src/memory/__tests__/mockBackend.ts +161 -0
- package/src/memory/__tests__/paths.test.ts +168 -0
- package/src/memory/__tests__/recallTracking.test.ts +96 -0
- package/src/memory/__tests__/temporalDecay.test.ts +151 -0
- package/src/memory/citations.ts +80 -0
- package/src/memory/compositeBackend.ts +99 -0
- package/src/memory/constants.ts +229 -0
- package/src/memory/embeddings.ts +188 -0
- package/src/memory/factory.ts +111 -0
- package/src/memory/index.ts +46 -0
- package/src/memory/migrate.ts +116 -0
- package/src/memory/mmr.ts +161 -0
- package/src/memory/paths.ts +258 -0
- package/src/memory/pgvectorStore.ts +324 -0
- package/src/memory/recallTracking.ts +127 -0
- package/src/memory/schema.sql +51 -0
- package/src/memory/temporalDecay.ts +134 -0
- package/src/memory/types.ts +185 -0
- package/src/nodes/ApprovalGateNode.ts +4 -10
- package/src/nodes/__tests__/ApprovalGateNode.test.ts +11 -20
- package/src/prompts/memoryFlushPrompt.ts +78 -0
- package/src/run.ts +17 -6
- package/src/scripts/test-bedrock-handoff-autonomous.ts +56 -20
- package/src/specs/agent-handoffs-bedrock.integration.test.ts +8 -5
- package/src/specs/agent-handoffs.test.ts +8 -2
- package/src/tools/AskUser.ts +7 -2
- package/src/tools/BrowserTools.ts +3 -5
- package/src/tools/ToolNode.ts +150 -13
- package/src/tools/__tests__/ToolApproval.test.ts +22 -9
- package/src/tools/approval/__tests__/constants.test.ts +1 -1
- package/src/tools/approval/constants.ts +2 -2
- package/src/tools/memory/__tests__/memoryTools.test.ts +205 -0
- package/src/tools/memory/index.ts +96 -0
- package/src/tools/memory/memoryAppendTool.ts +101 -0
- package/src/tools/memory/memoryGetTool.ts +53 -0
- package/src/tools/memory/memorySearchTool.ts +80 -0
- package/src/tools/memory/shared.ts +169 -0
- package/src/tools/search/search.test.ts +6 -1
- package/src/types/graph.ts +10 -3
- package/src/utils/__tests__/childAgentContext.test.ts +217 -0
- package/src/utils/__tests__/finishReasons.test.ts +55 -0
- package/src/utils/__tests__/toolCallNormalization.test.ts +181 -0
- package/src/utils/childAgentContext.ts +259 -0
- package/src/utils/events.ts +37 -7
- package/src/utils/finishReasons.ts +40 -0
- package/src/utils/llm.ts +0 -1
- package/src/utils/logging.ts +45 -8
- package/src/utils/toolCallNormalization.ts +271 -0
|
@@ -33,6 +33,9 @@ var providers = require('../llm/providers.cjs');
|
|
|
33
33
|
var ToolNode = require('../tools/ToolNode.cjs');
|
|
34
34
|
var index = require('../llm/openai/index.cjs');
|
|
35
35
|
var events = require('../utils/events.cjs');
|
|
36
|
+
var logging = require('../utils/logging.cjs');
|
|
37
|
+
var toolCallNormalization = require('../utils/toolCallNormalization.cjs');
|
|
38
|
+
var finishReasons = require('../utils/finishReasons.cjs');
|
|
36
39
|
var schema = require('../tools/schema.cjs');
|
|
37
40
|
var validate = require('../schemas/validate.cjs');
|
|
38
41
|
var AgentContext = require('../agents/AgentContext.cjs');
|
|
@@ -797,7 +800,7 @@ class StandardGraph extends Graph {
|
|
|
797
800
|
const resolved = agentContext.resolveStructuredOutputMode();
|
|
798
801
|
method = resolved.method;
|
|
799
802
|
if (resolved.warnings.length > 0) {
|
|
800
|
-
|
|
803
|
+
logging.mwarn('[Graph] Structured output mode warnings:', resolved.warnings);
|
|
801
804
|
}
|
|
802
805
|
}
|
|
803
806
|
else {
|
|
@@ -820,7 +823,7 @@ class StandardGraph extends Graph {
|
|
|
820
823
|
const { schema: prepared, warnings } = validate.prepareSchemaForProvider(schema, provider, structuredOutputConfig.strict !== false);
|
|
821
824
|
preparedSchema = prepared;
|
|
822
825
|
if (warnings.length > 0) {
|
|
823
|
-
|
|
826
|
+
logging.mwarn('[Graph] Schema preparation warnings:', warnings);
|
|
824
827
|
}
|
|
825
828
|
}
|
|
826
829
|
// Use withStructuredOutput to bind the schema
|
|
@@ -890,7 +893,7 @@ class StandardGraph extends Graph {
|
|
|
890
893
|
const errorMessage = typeof handleErrors === 'string'
|
|
891
894
|
? handleErrors
|
|
892
895
|
: `The response did not match the expected schema. Error: ${lastError.message}. Please try again with a valid response.`;
|
|
893
|
-
|
|
896
|
+
logging.mwarn(`[Graph] Structured output attempt ${attempts} failed: ${lastError.message}. Retrying...`);
|
|
894
897
|
// Add the error as a human message for context
|
|
895
898
|
finalMessages = [
|
|
896
899
|
...finalMessages,
|
|
@@ -1040,7 +1043,7 @@ class StandardGraph extends Graph {
|
|
|
1040
1043
|
const cachedDiscoveries = this._toolDiscoveryCache.getNewDiscoveries(messages$1);
|
|
1041
1044
|
if (cachedDiscoveries.length > 0) {
|
|
1042
1045
|
agentContext.markToolsAsDiscovered(cachedDiscoveries);
|
|
1043
|
-
|
|
1046
|
+
logging.mlog(`[Graph:ToolDiscovery] Cached ${cachedDiscoveries.length} new tools (total: ${this._toolDiscoveryCache.size})`);
|
|
1044
1047
|
}
|
|
1045
1048
|
const toolsForBinding = agentContext.getToolsForBinding();
|
|
1046
1049
|
// PERF: Detect subsequent ReAct iterations (tool results present in messages)
|
|
@@ -1059,8 +1062,8 @@ class StandardGraph extends Graph {
|
|
|
1059
1062
|
clientOptions: effectiveClientOptions,
|
|
1060
1063
|
});
|
|
1061
1064
|
// DEBUG: Log which model and tools each agent uses during handoff
|
|
1062
|
-
|
|
1063
|
-
`model=${effectiveClientOptions
|
|
1065
|
+
logging.mlog(`[createCallModel] Agent "${agentId}" invoking LLM | provider=${agentContext.provider} | ` +
|
|
1066
|
+
`model=${effectiveClientOptions.model ?? 'default'} | ` +
|
|
1064
1067
|
`toolsForBinding=${toolsForBinding?.length ?? 0} | ` +
|
|
1065
1068
|
`toolNames=[${(toolsForBinding ?? []).map((t) => t.name ?? 'unknown').join(', ')}]`);
|
|
1066
1069
|
if (agentContext.systemRunnable) {
|
|
@@ -1072,7 +1075,15 @@ class StandardGraph extends Graph {
|
|
|
1072
1075
|
if (!config.signal) {
|
|
1073
1076
|
config.signal = this.signal;
|
|
1074
1077
|
}
|
|
1075
|
-
this.config
|
|
1078
|
+
// First-writer-wins: `this.config` is used ONLY as a "has a run started"
|
|
1079
|
+
// existence flag by the dispatch* methods (they never read its value —
|
|
1080
|
+
// they read the current RunnableConfig from LangChain AsyncLocalStorage).
|
|
1081
|
+
// Unconditionally reassigning here races across concurrent child
|
|
1082
|
+
// subgraph.invoke() calls under parallel multi-agent handoffs; the last
|
|
1083
|
+
// writer wins, and any dispatch firing between writes would historically
|
|
1084
|
+
// have been tagged with the wrong child's metadata. Keeping the first
|
|
1085
|
+
// write pinned makes this a true flag, eliminating the race.
|
|
1086
|
+
this.config ??= config;
|
|
1076
1087
|
let messagesToUse = messages$1;
|
|
1077
1088
|
// ====================================================================
|
|
1078
1089
|
// PRE-PRUNING DELEGATION CHECK
|
|
@@ -1138,13 +1149,13 @@ class StandardGraph extends Graph {
|
|
|
1138
1149
|
const oldMessages = messages$1.slice(messages$1[0]?.getType() === 'system' ? 1 : 0, Math.max(1, messages$1.length - recentTurnCount));
|
|
1139
1150
|
if (oldMessages.length > 0) {
|
|
1140
1151
|
this._summaryInFlight = true;
|
|
1141
|
-
|
|
1152
|
+
logging.mlog(`[Graph:ProactiveSummary] Context at ${utilization.toFixed(1)}% (threshold ${threshold}%) — summarizing ${oldMessages.length} older msgs in background`);
|
|
1142
1153
|
agentContext
|
|
1143
1154
|
.summarizeCallback(oldMessages)
|
|
1144
1155
|
.then((updated) => {
|
|
1145
1156
|
if (updated != null && updated !== '') {
|
|
1146
1157
|
this._cachedRunSummary = updated;
|
|
1147
|
-
|
|
1158
|
+
logging.mlog(`[Graph:ProactiveSummary] Background summary ready (len=${updated.length})`);
|
|
1148
1159
|
}
|
|
1149
1160
|
})
|
|
1150
1161
|
.catch((err) => {
|
|
@@ -1320,7 +1331,7 @@ class StandardGraph extends Graph {
|
|
|
1320
1331
|
viewIdx++;
|
|
1321
1332
|
}
|
|
1322
1333
|
agentContext.indexTokenCountMap = viewTokenMap;
|
|
1323
|
-
|
|
1334
|
+
logging.mlog(`[Graph:Compaction] ${messages$1.length}→${viewParts.length} msgs | ` +
|
|
1324
1335
|
`compacted=${compactedMessages.length} window=${recentMessages.length} | ` +
|
|
1325
1336
|
`summary=${summarySource} | budget=${usedTokens}/${recentBudget}` +
|
|
1326
1337
|
(fileManifestTokens > 0
|
|
@@ -1334,7 +1345,7 @@ class StandardGraph extends Graph {
|
|
|
1334
1345
|
if (shouldSummarize) {
|
|
1335
1346
|
if (this._summaryInFlight) {
|
|
1336
1347
|
this._pendingMessagesToRefine.push(...compactedMessages);
|
|
1337
|
-
|
|
1348
|
+
logging.mlog(`[Graph:Compaction] Summary in-flight, queued ${compactedMessages.length} msgs (pending=${this._pendingMessagesToRefine.length})`);
|
|
1338
1349
|
}
|
|
1339
1350
|
else {
|
|
1340
1351
|
this._summaryInFlight = true;
|
|
@@ -1375,7 +1386,7 @@ class StandardGraph extends Graph {
|
|
|
1375
1386
|
const { messages: dedupedMessages, removedCount } = dedup.deduplicateSystemMessages(messagesToUse);
|
|
1376
1387
|
if (removedCount > 0) {
|
|
1377
1388
|
messagesToUse = dedupedMessages;
|
|
1378
|
-
|
|
1389
|
+
logging.mlog(`[Graph:Dedup] Removed ${removedCount} duplicate system message(s)`);
|
|
1379
1390
|
}
|
|
1380
1391
|
let finalMessages = messagesToUse;
|
|
1381
1392
|
if (agentContext.useLegacyContent) {
|
|
@@ -1549,8 +1560,8 @@ class StandardGraph extends Graph {
|
|
|
1549
1560
|
errorMessage.includes('prompt is too long');
|
|
1550
1561
|
// Log when we detect the error
|
|
1551
1562
|
if (isInputTooLongError) {
|
|
1552
|
-
|
|
1553
|
-
|
|
1563
|
+
logging.mwarn('[Graph] Detected input too long error:', errorMessage.substring(0, 200));
|
|
1564
|
+
logging.mwarn('[Graph] Checking emergency pruning conditions:', {
|
|
1554
1565
|
hasPruneMessages: !!agentContext.pruneMessages,
|
|
1555
1566
|
hasTokenCounter: !!agentContext.tokenCounter,
|
|
1556
1567
|
maxContextTokens: agentContext.maxContextTokens,
|
|
@@ -1570,12 +1581,12 @@ class StandardGraph extends Graph {
|
|
|
1570
1581
|
if (result)
|
|
1571
1582
|
break; // Exit if we got a result
|
|
1572
1583
|
const reducedMaxTokens = Math.floor(agentContext.maxContextTokens * reductionFactor);
|
|
1573
|
-
|
|
1584
|
+
logging.mwarn(`[Graph] Input too long. Retrying with ${reductionFactor * 100}% context (${reducedMaxTokens} tokens)...`);
|
|
1574
1585
|
// Build fresh indexTokenCountMap if missing/incomplete
|
|
1575
1586
|
// This is needed when messages were dynamically added without updating the token map
|
|
1576
1587
|
let tokenMapForPruning = agentContext.indexTokenCountMap;
|
|
1577
1588
|
if (Object.keys(tokenMapForPruning).length < messages$1.length) {
|
|
1578
|
-
|
|
1589
|
+
logging.mwarn('[Graph] Building fresh token count map for emergency pruning...');
|
|
1579
1590
|
tokenMapForPruning = {};
|
|
1580
1591
|
for (let i = 0; i < messages$1.length; i++) {
|
|
1581
1592
|
tokenMapForPruning[i] = agentContext.tokenCounter(messages$1[i]);
|
|
@@ -1595,7 +1606,7 @@ class StandardGraph extends Graph {
|
|
|
1595
1606
|
});
|
|
1596
1607
|
// Skip if we can't fit any messages
|
|
1597
1608
|
if (reducedMessages.length === 0) {
|
|
1598
|
-
|
|
1609
|
+
logging.mwarn(`[Graph] Cannot fit any messages at ${reductionFactor * 100}% reduction, trying next level...`);
|
|
1599
1610
|
continue;
|
|
1600
1611
|
}
|
|
1601
1612
|
// Calculate how many messages were pruned and estimate context timeframe
|
|
@@ -1655,7 +1666,7 @@ If I seem to be missing something we discussed earlier, just give me a quick rem
|
|
|
1655
1666
|
retryErrorMsg.includes('context length') ||
|
|
1656
1667
|
retryErrorMsg.includes('validationexception');
|
|
1657
1668
|
if (stillTooLong && reductionFactor > 0.1) {
|
|
1658
|
-
|
|
1669
|
+
logging.mwarn(`[Graph] Still too long at ${reductionFactor * 100}%, trying more aggressive pruning...`);
|
|
1659
1670
|
}
|
|
1660
1671
|
else {
|
|
1661
1672
|
console.error(`[Graph] Retry at ${reductionFactor * 100}% failed:`, retryError.message);
|
|
@@ -1715,6 +1726,20 @@ If I seem to be missing something we discussed earlier, just give me a quick rem
|
|
|
1715
1726
|
* handled everything — both paths become no-ops.
|
|
1716
1727
|
*/
|
|
1717
1728
|
const responseMessage = result.messages?.[0];
|
|
1729
|
+
// Tool-call name normalization — catches LLM output that names tools
|
|
1730
|
+
// with wrong delimiters (outlook/operations), prefixes
|
|
1731
|
+
// (functions.outlook_operations), case drift, counter suffixes, or
|
|
1732
|
+
// empty names recoverable from the tool_call id. Mutates in place so
|
|
1733
|
+
// the downstream ToolNode dispatch sees the corrected names.
|
|
1734
|
+
if (responseMessage && agentContext.toolMap) {
|
|
1735
|
+
const allowedNames = new Set(Object.keys(agentContext.toolMap));
|
|
1736
|
+
if (allowedNames.size > 0) {
|
|
1737
|
+
const rewrote = toolCallNormalization.normalizeMessageToolCalls(responseMessage, allowedNames);
|
|
1738
|
+
if (rewrote) {
|
|
1739
|
+
logging.mlog(`[Graph] normalized tool_call names on agent "${agentId}" response`);
|
|
1740
|
+
}
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1718
1743
|
const toolCalls = responseMessage
|
|
1719
1744
|
?.tool_calls;
|
|
1720
1745
|
const hasToolCalls = Array.isArray(toolCalls) && toolCalls.length > 0;
|
|
@@ -1801,12 +1826,20 @@ If I seem to be missing something we discussed earlier, just give me a quick rem
|
|
|
1801
1826
|
const meta = finalMsg.response_metadata;
|
|
1802
1827
|
// Bedrock streaming nests stopReason inside messageStop: { stopReason: '...' }
|
|
1803
1828
|
const messageStop = meta.messageStop;
|
|
1804
|
-
|
|
1805
|
-
meta.
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1829
|
+
const nextReason = meta.finish_reason ?? // OpenAI/Azure
|
|
1830
|
+
meta.stop_reason ?? // Anthropic direct API
|
|
1831
|
+
meta.stopReason ?? // Bedrock invoke (non-streaming)
|
|
1832
|
+
messageStop?.stopReason ?? // Bedrock streaming
|
|
1833
|
+
meta.finishReason; // VertexAI/Google
|
|
1834
|
+
// Sticky on truncation: a single Graph instance is reused across
|
|
1835
|
+
// every scoped-subgraph inner node invocation (see MultiAgentGraph
|
|
1836
|
+
// buildScopedSubgraph). If an earlier inner node hit max_tokens
|
|
1837
|
+
// but a later inner node finished cleanly, the host's continuation layer
|
|
1838
|
+
// would miss the truncation signal unless we preserve it. Keep the
|
|
1839
|
+
// truncation reason pinned so the outer caller can retry.
|
|
1840
|
+
if (!finishReasons.isTruncationReason(this.lastFinishReason)) {
|
|
1841
|
+
this.lastFinishReason = nextReason;
|
|
1842
|
+
}
|
|
1810
1843
|
}
|
|
1811
1844
|
this.cleanupSignalListener();
|
|
1812
1845
|
// DEFERRED STRUCTURED OUTPUT: When the agent has tools AND structured output configured,
|
|
@@ -1854,7 +1887,7 @@ If I seem to be missing something we discussed earlier, just give me a quick rem
|
|
|
1854
1887
|
// but we couldn't format the output as structured JSON.
|
|
1855
1888
|
// Return the unstructured text response from attemptInvoke.
|
|
1856
1889
|
console.error('[Graph] Deferred structured output failed after successful tool use:', structuredError);
|
|
1857
|
-
|
|
1890
|
+
logging.mwarn('[Graph] Falling back to unstructured response from tool-use phase');
|
|
1858
1891
|
return result;
|
|
1859
1892
|
}
|
|
1860
1893
|
}
|
|
@@ -1870,7 +1903,10 @@ If I seem to be missing something we discussed earlier, just give me a quick rem
|
|
|
1870
1903
|
const agentNode = `${AGENT}${agentId}`;
|
|
1871
1904
|
const toolNode = `${TOOLS}${agentId}`;
|
|
1872
1905
|
const routeMessage = (state, config) => {
|
|
1873
|
-
this.config
|
|
1906
|
+
// First-writer-wins — see note in createCallModel. `this.config` is an
|
|
1907
|
+
// existence flag only; assigning unconditionally would race under
|
|
1908
|
+
// parallel child subgraph.invoke().
|
|
1909
|
+
this.config ??= config;
|
|
1874
1910
|
return ToolNode.toolsCondition(state, toolNode, this.invokedToolIds);
|
|
1875
1911
|
};
|
|
1876
1912
|
const StateAnnotation = langgraph.Annotation.Root({
|
|
@@ -1908,10 +1944,16 @@ If I seem to be missing something we discussed earlier, just give me a quick rem
|
|
|
1908
1944
|
default: () => [],
|
|
1909
1945
|
}),
|
|
1910
1946
|
});
|
|
1947
|
+
// Pass compileOptions (including the HITL checkpointer) to the OUTER
|
|
1948
|
+
// workflow — not just the inner agent subgraph. hasInterrupts() calls
|
|
1949
|
+
// getState() on the outer compiled graph; without a checkpointer here,
|
|
1950
|
+
// getState reports zero tasks and the HITL interrupt/resume loop breaks
|
|
1951
|
+
// out immediately even though interrupt() fired correctly inside the
|
|
1952
|
+
// agent subgraph.
|
|
1911
1953
|
const workflow = new langgraph.StateGraph(StateAnnotation)
|
|
1912
1954
|
.addNode(this.defaultAgentId, agentNode, { ends: [langgraph.END] })
|
|
1913
1955
|
.addEdge(langgraph.START, this.defaultAgentId)
|
|
1914
|
-
.compile();
|
|
1956
|
+
.compile(this.compileOptions);
|
|
1915
1957
|
return workflow;
|
|
1916
1958
|
}
|
|
1917
1959
|
/**
|
|
@@ -1982,12 +2024,16 @@ If I seem to be missing something we discussed earlier, just give me a quick rem
|
|
|
1982
2024
|
}
|
|
1983
2025
|
catch (_e) {
|
|
1984
2026
|
/** If we can't get agent context, that's okay - agentId remains undefined */
|
|
1985
|
-
|
|
2027
|
+
logging.mlog(`[dispatchRunStep] Could not resolve agentId from metadata.langgraph_node="${metadata.langgraph_node}": ${_e.message}`);
|
|
1986
2028
|
}
|
|
1987
2029
|
}
|
|
1988
2030
|
this.contentData.push(runStep);
|
|
1989
2031
|
this.contentIndexMap.set(stepId, runStep.index);
|
|
1990
|
-
|
|
2032
|
+
// Pass undefined so safeDispatchCustomEvent resolves the runnable config
|
|
2033
|
+
// from LangChain's AsyncLocalStorage. Using the shared `this.config` would
|
|
2034
|
+
// race across concurrent child subgraph.invoke calls under parallel
|
|
2035
|
+
// multi-agent handoffs and tag events with the wrong child's spawnKey.
|
|
2036
|
+
await events.safeDispatchCustomEvent(_enum.GraphEvents.ON_RUN_STEP, runStep);
|
|
1991
2037
|
return stepId;
|
|
1992
2038
|
}
|
|
1993
2039
|
async handleToolCallCompleted(data, metadata, omitOutput) {
|
|
@@ -2095,7 +2141,7 @@ If I seem to be missing something we discussed earlier, just give me a quick rem
|
|
|
2095
2141
|
throw new Error('No config provided');
|
|
2096
2142
|
}
|
|
2097
2143
|
if (!data.id) {
|
|
2098
|
-
|
|
2144
|
+
logging.mwarn('No Tool ID provided for Tool Error');
|
|
2099
2145
|
return;
|
|
2100
2146
|
}
|
|
2101
2147
|
const stepId = graph.toolCallStepIds.get(data.id) ?? '';
|
|
@@ -2143,7 +2189,10 @@ If I seem to be missing something we discussed earlier, just give me a quick rem
|
|
|
2143
2189
|
id,
|
|
2144
2190
|
delta,
|
|
2145
2191
|
};
|
|
2146
|
-
|
|
2192
|
+
// See dispatchRunStep note: do not pass `this.config`. The implicit
|
|
2193
|
+
// AsyncLocalStorage config is the correct per-async-branch source under
|
|
2194
|
+
// parallel handoffs.
|
|
2195
|
+
await events.safeDispatchCustomEvent(_enum.GraphEvents.ON_RUN_STEP_DELTA, runStepDelta);
|
|
2147
2196
|
}
|
|
2148
2197
|
async dispatchMessageDelta(id, delta) {
|
|
2149
2198
|
if (!this.config) {
|
|
@@ -2153,7 +2202,8 @@ If I seem to be missing something we discussed earlier, just give me a quick rem
|
|
|
2153
2202
|
id,
|
|
2154
2203
|
delta,
|
|
2155
2204
|
};
|
|
2156
|
-
|
|
2205
|
+
// See dispatchRunStep note.
|
|
2206
|
+
await events.safeDispatchCustomEvent(_enum.GraphEvents.ON_MESSAGE_DELTA, messageDelta);
|
|
2157
2207
|
}
|
|
2158
2208
|
dispatchReasoningDelta = async (stepId, delta) => {
|
|
2159
2209
|
if (!this.config) {
|
|
@@ -2163,7 +2213,8 @@ If I seem to be missing something we discussed earlier, just give me a quick rem
|
|
|
2163
2213
|
id: stepId,
|
|
2164
2214
|
delta,
|
|
2165
2215
|
};
|
|
2166
|
-
|
|
2216
|
+
// See dispatchRunStep note.
|
|
2217
|
+
await events.safeDispatchCustomEvent(_enum.GraphEvents.ON_REASONING_DELTA, reasoningDelta);
|
|
2167
2218
|
};
|
|
2168
2219
|
}
|
|
2169
2220
|
|