@illuma-ai/agents 1.1.0 → 1.1.1

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.
@@ -102,6 +102,15 @@ class StandardGraph extends Graph {
102
102
  _pruneCalibration;
103
103
  /** Run-scoped tool discovery cache — avoids re-parsing conversation history on every iteration */
104
104
  _toolDiscoveryCache;
105
+ /**
106
+ * SCALE: Tracks whether a summary call is already in-flight for this Graph instance.
107
+ * Prevents multiple concurrent summary LLM calls when rapid tool iterations each
108
+ * trigger pruning. At 2000 users with 3+ tool calls per turn, this prevents
109
+ * 6000+ summary calls/turn from becoming 2000.
110
+ */
111
+ _summaryInFlight = false;
112
+ /** Messages accumulated across tool iterations while a summary call is in-flight */
113
+ _pendingMessagesToRefine = [];
105
114
  /** Map of agent contexts by agent ID */
106
115
  agentContexts = new Map();
107
116
  /** Default agent ID to use */
@@ -157,9 +166,11 @@ class StandardGraph extends Graph {
157
166
  this.messageStepHasToolCalls = graph.resetIfNotEmpty(this.messageStepHasToolCalls, new Map());
158
167
  this.prelimMessageIdsByStepKey = graph.resetIfNotEmpty(this.prelimMessageIdsByStepKey, new Map());
159
168
  this.invokedToolIds = graph.resetIfNotEmpty(this.invokedToolIds, undefined);
160
- // Reset EMA calibration and tool discovery cache for fresh run
169
+ // Reset EMA calibration, tool discovery cache, and summary debounce for fresh run
161
170
  this._pruneCalibration = pruneCalibration.createPruneCalibration();
162
171
  this._toolDiscoveryCache.reset();
172
+ this._summaryInFlight = false;
173
+ this._pendingMessagesToRefine = [];
163
174
  for (const context of this.agentContexts.values()) {
164
175
  context.reset();
165
176
  }
@@ -1121,17 +1132,34 @@ class StandardGraph extends Graph {
1121
1132
  }
1122
1133
  // Single consolidated log for the entire prune+summarize decision
1123
1134
  console.debug(`[Graph:ContextMgmt] Pruned ${messages$1.length}→${context.length} msgs (${messagesToRefine.length} discarded) | summary=${summarySource}${summary ? ` (len=${summary.length})` : ''} | calibration=${this._pruneCalibration.ratio.toFixed(3)}(${this._pruneCalibration.iterations})`);
1124
- // Fire background summarization — updates cache for next iteration/turn
1125
- agentContext
1126
- .summarizeCallback(messagesToRefine)
1127
- .then((updated) => {
1128
- if (updated != null && updated !== '') {
1129
- this._cachedRunSummary = updated;
1130
- }
1131
- })
1132
- .catch((err) => {
1133
- console.error('[Graph] Background summary failed (non-fatal):', err);
1134
- });
1135
+ // SCALE: Debounce background summarization — if a summary call is already
1136
+ // in-flight (from a prior tool iteration), accumulate messages instead of
1137
+ // firing another concurrent LLM call. At 2000 users with 3+ tool calls
1138
+ // per turn, this prevents 3x summary call volume.
1139
+ if (this._summaryInFlight) {
1140
+ this._pendingMessagesToRefine.push(...messagesToRefine);
1141
+ console.debug(`[Graph:ContextMgmt] Summary in-flight, queued ${messagesToRefine.length} msgs (pending=${this._pendingMessagesToRefine.length})`);
1142
+ }
1143
+ else {
1144
+ this._summaryInFlight = true;
1145
+ const allMessages = this._pendingMessagesToRefine.length > 0
1146
+ ? [...this._pendingMessagesToRefine, ...messagesToRefine]
1147
+ : messagesToRefine;
1148
+ this._pendingMessagesToRefine = [];
1149
+ agentContext
1150
+ .summarizeCallback(allMessages)
1151
+ .then((updated) => {
1152
+ if (updated != null && updated !== '') {
1153
+ this._cachedRunSummary = updated;
1154
+ }
1155
+ })
1156
+ .catch((err) => {
1157
+ console.error('[Graph] Background summary failed (non-fatal):', err);
1158
+ })
1159
+ .finally(() => {
1160
+ this._summaryInFlight = false;
1161
+ });
1162
+ }
1135
1163
  if (summary != null && summary !== '') {
1136
1164
  hasSummary = true;
1137
1165
  const summaryMsg = new messages.SystemMessage(`[Conversation Summary]\n${summary}`);