@agentionai/agents 0.10.1 → 0.10.2

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.
@@ -84,6 +84,9 @@ class ClaudeAgent extends BaseAgent_1.BaseAgent {
84
84
  // Mark session boundary so transform plugins (e.g. toolResultMaskingPlugin)
85
85
  // don't mask tool results produced within this execute() loop.
86
86
  this.history.setSessionAnchor();
87
+ // Suspend auto-trimming so tool_use / tool_result pairs are never split
88
+ // mid-loop. endExecution() in the finally block enforces limits once.
89
+ this.history.beginExecution();
87
90
  try {
88
91
  const messages = transformers_1.anthropicTransformer.toProvider(this.history.getEntries());
89
92
  const systemMessage = this.history.getSystemMessage();
@@ -125,6 +128,9 @@ class ClaudeAgent extends BaseAgent_1.BaseAgent {
125
128
  throw executionError;
126
129
  }
127
130
  }
131
+ finally {
132
+ this.history.endExecution();
133
+ }
128
134
  }
129
135
  async handleResponse(response) {
130
136
  const usage = this.parseUsage(response.usage);
@@ -184,6 +184,9 @@ class GeminiAgent extends BaseAgent_1.BaseAgent {
184
184
  // Mark session boundary so transform plugins (e.g. toolResultMaskingPlugin)
185
185
  // don't mask tool results produced within this execute() loop.
186
186
  this.history.setSessionAnchor();
187
+ // Suspend auto-trimming so tool_use / tool_result pairs are never split
188
+ // mid-loop. endExecution() in the finally block enforces limits once.
189
+ this.history.beginExecution();
187
190
  try {
188
191
  const contents = transformers_1.geminiTransformer.toProvider(this.history.getEntries());
189
192
  const systemMessage = this.history.getSystemMessage();
@@ -229,6 +232,9 @@ class GeminiAgent extends BaseAgent_1.BaseAgent {
229
232
  throw executionError;
230
233
  }
231
234
  }
235
+ finally {
236
+ this.history.endExecution();
237
+ }
232
238
  }
233
239
  async handleResponse(response) {
234
240
  const result = response.response;
@@ -94,6 +94,9 @@ class MistralAgent extends BaseAgent_1.BaseAgent {
94
94
  // Mark session boundary so transform plugins (e.g. toolResultMaskingPlugin)
95
95
  // don't mask tool results produced within this execute() loop.
96
96
  this.history.setSessionAnchor();
97
+ // Suspend auto-trimming so tool_use / tool_result pairs are never split
98
+ // mid-loop. endExecution() in the finally block enforces limits once.
99
+ this.history.beginExecution();
97
100
  try {
98
101
  const messages = transformers_1.mistralTransformer.toProvider(this.history.getEntries());
99
102
  const response = await this.client.chat.complete({
@@ -133,6 +136,9 @@ class MistralAgent extends BaseAgent_1.BaseAgent {
133
136
  throw executionError;
134
137
  }
135
138
  }
139
+ finally {
140
+ this.history.endExecution();
141
+ }
136
142
  }
137
143
  async handleResponse(response) {
138
144
  if (!response.choices || response.choices.length === 0) {
@@ -105,6 +105,9 @@ class OpenAiAgent extends BaseAgent_1.BaseAgent {
105
105
  // Mark session boundary so transform plugins (e.g. toolResultMaskingPlugin)
106
106
  // don't mask tool results produced within this execute() loop.
107
107
  this.history.setSessionAnchor();
108
+ // Suspend auto-trimming so tool_use / tool_result pairs are never split
109
+ // mid-loop. endExecution() in the finally block enforces limits once.
110
+ this.history.beginExecution();
108
111
  try {
109
112
  const inputMessages = transformers_1.openAiTransformer.toProvider(this.history.getEntries());
110
113
  const response = await this.client.responses.create({
@@ -150,6 +153,9 @@ class OpenAiAgent extends BaseAgent_1.BaseAgent {
150
153
  throw executionError;
151
154
  }
152
155
  }
156
+ finally {
157
+ this.history.endExecution();
158
+ }
153
159
  }
154
160
  async handleResponse(response) {
155
161
  if (!response.output || !response.output.length) {
@@ -123,6 +123,7 @@ export declare class History extends EventEmitter {
123
123
  transient: boolean;
124
124
  private _plugins;
125
125
  private _reducing;
126
+ private _executing;
126
127
  private _sessionAnchor;
127
128
  constructor(entries?: HistoryEntry[], options?: HistoryOptions);
128
129
  /**
@@ -247,6 +248,22 @@ export declare class History extends EventEmitter {
247
248
  * Create a copy of this history
248
249
  */
249
250
  clone(options?: HistoryOptions): History;
251
+ /**
252
+ * Signal the start of an agent execute() loop. While executing, automatic
253
+ * trimming on addEntry() is suspended so tool_use / tool_result pairs are
254
+ * never split mid-loop. Call endExecution() in a finally block to resume.
255
+ */
256
+ beginExecution(): void;
257
+ /**
258
+ * Signal the end of an agent execute() loop. Resumes automatic trimming and
259
+ * immediately enforces maxLength / maxTokens limits on the accumulated history.
260
+ */
261
+ endExecution(): void;
262
+ /**
263
+ * Explicitly enforce maxLength and maxTokens limits. Useful when using
264
+ * History standalone, outside of an agent execute() loop.
265
+ */
266
+ trim(): void;
250
267
  /**
251
268
  * Apply maxLength and maxTokens trimming to the current entry list.
252
269
  * Safe to call after bulk-loading entries (e.g. RedisHistory.load()).
@@ -127,6 +127,7 @@ class History extends events_1.default {
127
127
  this.transient = false;
128
128
  this._plugins = [];
129
129
  this._reducing = false;
130
+ this._executing = false;
130
131
  this._sessionAnchor = null;
131
132
  this.options = options;
132
133
  this.transient = Boolean(options?.transient);
@@ -399,12 +400,37 @@ class History extends events_1.default {
399
400
  // ===========================================================================
400
401
  // Private helpers
401
402
  // ===========================================================================
403
+ /**
404
+ * Signal the start of an agent execute() loop. While executing, automatic
405
+ * trimming on addEntry() is suspended so tool_use / tool_result pairs are
406
+ * never split mid-loop. Call endExecution() in a finally block to resume.
407
+ */
408
+ beginExecution() {
409
+ this._executing = true;
410
+ }
411
+ /**
412
+ * Signal the end of an agent execute() loop. Resumes automatic trimming and
413
+ * immediately enforces maxLength / maxTokens limits on the accumulated history.
414
+ */
415
+ endExecution() {
416
+ this._executing = false;
417
+ this.applyTrimming();
418
+ }
419
+ /**
420
+ * Explicitly enforce maxLength and maxTokens limits. Useful when using
421
+ * History standalone, outside of an agent execute() loop.
422
+ */
423
+ trim() {
424
+ this.applyTrimming();
425
+ }
402
426
  /**
403
427
  * Apply maxLength and maxTokens trimming to the current entry list.
404
428
  * Safe to call after bulk-loading entries (e.g. RedisHistory.load()).
405
429
  * Subclasses may call this after directly manipulating _entries.
406
430
  */
407
431
  applyTrimming() {
432
+ if (this._executing)
433
+ return;
408
434
  if (this.options.maxLength && this._entries.length > this.options.maxLength) {
409
435
  this._entries = this._entries.slice(this._entries.length - this.options.maxLength);
410
436
  this.sanitizeToolPairs();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@agentionai/agents",
3
3
  "author": "Laurent Zuijdwijk",
4
- "version": "0.10.1",
4
+ "version": "0.10.2",
5
5
  "description": "Agent Library",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",