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