@myagentroam/agent 0.15.10 → 0.15.11

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.
@@ -25,6 +25,7 @@ export class ExecutionLoop {
25
25
  const { mode, messages } = input;
26
26
  let recoveringFromContextOverflow = false;
27
27
  const modelRetryState = { attempts: 0 };
28
+ let retryTpsStartedAt;
28
29
  while (true) {
29
30
  let stop;
30
31
  let sawTool = false;
@@ -38,7 +39,6 @@ export class ExecutionLoop {
38
39
  const startedMessages = new Set();
39
40
  const leadingMessageWhitespace = new Map();
40
41
  let sawModelSemanticEvent = false;
41
- let requestStartedAt;
42
42
  let firstModelResponseAt;
43
43
  let generation = new ModelGenerationTiming();
44
44
  let requestCompletedAt;
@@ -55,19 +55,24 @@ export class ExecutionLoop {
55
55
  const emitFinalPerformance = async (completedAt) => {
56
56
  if (mode === 'compact')
57
57
  return;
58
- generation.finish(completedAt);
59
- const outputDuration = generation.durationMs;
58
+ const requestDurationMs = completedAt - tpsStartedAt;
60
59
  const outputTokens = requestOutputTokens;
61
- if (outputTokens === undefined || outputDuration === undefined)
60
+ if (outputTokens === undefined ||
61
+ !Number.isFinite(requestDurationMs) ||
62
+ requestDurationMs <= 0)
62
63
  return;
64
+ generation.finish(completedAt);
65
+ const outputDurationMs = Math.round(generation.durationMs ?? 0);
66
+ // Final output tokens can include reasoning that the provider did not stream.
67
+ const rateDurationMs = Math.max(requestDurationMs, 1_000);
63
68
  await input.publish({
64
69
  type: 'model.performance',
65
70
  ...(firstModelResponseAt === undefined
66
71
  ? {}
67
72
  : { latencyMs: Math.max(0, Math.round(firstModelResponseAt - requestStartedAt)) }),
68
73
  outputTokens,
69
- outputDurationMs: Math.round(outputDuration),
70
- tokensPerSecond: Number(((outputTokens * 1000) / outputDuration).toFixed(2))
74
+ ...(outputDurationMs === 0 ? {} : { outputDurationMs }),
75
+ tokensPerSecond: Number(((outputTokens * 1_000) / rateDurationMs).toFixed(2))
71
76
  });
72
77
  };
73
78
  const persistToolCalls = async (calls) => {
@@ -84,8 +89,10 @@ export class ExecutionLoop {
84
89
  await input.appendContext(message);
85
90
  }
86
91
  };
92
+ const requestStartedAt = performance.now();
93
+ const tpsStartedAt = retryTpsStartedAt ?? requestStartedAt;
94
+ retryTpsStartedAt = undefined;
87
95
  try {
88
- requestStartedAt = performance.now();
89
96
  for await (const event of input.startModel({
90
97
  ...round.request,
91
98
  retryState: modelRetryState
@@ -207,6 +214,9 @@ export class ExecutionLoop {
207
214
  messages.push({ role: 'assistant', content: event.text });
208
215
  }
209
216
  else if (event.type === 'usage') {
217
+ // Adapters merge intermediate usage within the request before publishing final usage.
218
+ if (event.final === false)
219
+ continue;
210
220
  latestUsage = event.usage;
211
221
  if (event.final === true)
212
222
  generation.finish(observedAt);
@@ -215,7 +225,7 @@ export class ExecutionLoop {
215
225
  event.usage.outputTokens >= 0
216
226
  ? event.usage.outputTokens
217
227
  : undefined;
218
- if (event.final !== false && (outputTokens !== undefined || event.final === true))
228
+ if (outputTokens !== undefined || event.final === true)
219
229
  requestOutputTokens = outputTokens;
220
230
  const reportedContext = event.usage.contextInputTokens ?? event.usage.inputTokens;
221
231
  if (reportedContext !== undefined &&
@@ -293,8 +303,11 @@ export class ExecutionLoop {
293
303
  pendingTools.splice(0, pendingTools.length);
294
304
  else if (pendingTools.length > 0)
295
305
  await persistToolCalls(pendingTools);
296
- if (pendingTools.length === 0)
306
+ if (pendingTools.length === 0) {
307
+ // Runtime recovery continues the same logical request unless it runs a tool.
308
+ retryTpsStartedAt = tpsStartedAt;
297
309
  continue;
310
+ }
298
311
  }
299
312
  else if (mode === 'compact' &&
300
313
  !sawModelSemanticEvent &&
@@ -410,6 +423,7 @@ export class ExecutionLoop {
410
423
  this.planOutputPrefixes.clear();
411
424
  if (await recoverModelStream(error, modelRetryState, input.recoverySignal())) {
412
425
  this.finalAnswer = '';
426
+ retryTpsStartedAt = tpsStartedAt;
413
427
  continue;
414
428
  }
415
429
  throw error;
@@ -1,4 +1,4 @@
1
- /** Request-local observed generation intervals, excluding explicit execution pauses. */
1
+ /** Diagnostic generation intervals within one model attempt, excluding explicit execution pauses. */
2
2
  export declare class ModelGenerationTiming {
3
3
  private startedAt;
4
4
  private latestAt;
@@ -1,4 +1,4 @@
1
- /** Request-local observed generation intervals, excluding explicit execution pauses. */
1
+ /** Diagnostic generation intervals within one model attempt, excluding explicit execution pauses. */
2
2
  export class ModelGenerationTiming {
3
3
  startedAt;
4
4
  latestAt;
@@ -34,6 +34,6 @@ export class ModelGenerationTiming {
34
34
  this.completed = true;
35
35
  }
36
36
  get durationMs() {
37
- return this.completed && this.valid && this.duration >= 1_000 ? this.duration : undefined;
37
+ return this.completed && this.valid && this.duration > 0 ? this.duration : undefined;
38
38
  }
39
39
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myagentroam/agent",
3
- "version": "0.15.10",
3
+ "version": "0.15.11",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/myagentroam/mar.git",