Skip to content

Commit ef6dc8f

Browse files
committed
fix(agents): count frozen prompt bytes
1 parent f31306e commit ef6dc8f

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

‎src/agents/embedded-agent-runner/tool-result-truncation.ts‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -525,14 +525,14 @@ function buildAggregateToolResultReplacements(params: {
525525
} =>
526526
item.entry.type === "message" &&
527527
Boolean(item.entry.message) &&
528-
item.entry.aggregateEligible !== false &&
529528
(item.entry.message as { role?: string }).role === "toolResult",
530529
)
531530
.map((item) => ({
532531
index: item.index,
533532
entryId: item.entry.id,
534533
message: item.entry.message,
535534
textLength: getToolResultTextLength(item.entry.message),
535+
aggregateEligible: item.entry.aggregateEligible !== false,
536536
}))
537537
.filter((item) => item.textLength > 0);
538538

@@ -556,12 +556,14 @@ function buildAggregateToolResultReplacements(params: {
556556
const replacements: Array<{ entryId: string; message: AgentMessage }> = [];
557557

558558
// Spend aggregate reduction on older entries first so fresh tool output stays intact.
559-
for (const candidate of candidates.toSorted((a, b) => {
560-
if (a.index !== b.index) {
561-
return a.index - b.index;
562-
}
563-
return b.textLength - a.textLength;
564-
})) {
559+
for (const candidate of candidates
560+
.filter((item) => item.aggregateEligible)
561+
.toSorted((a, b) => {
562+
if (a.index !== b.index) {
563+
return a.index - b.index;
564+
}
565+
return b.textLength - a.textLength;
566+
})) {
565567
if (remainingReduction <= 0) {
566568
break;
567569
}

0 commit comments

Comments
 (0)