You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Set a low threshold to observe compaction in action.
21
+
returncompactionCandidateItems.length>=4;
22
+
},
18
23
});
19
24
20
25
constagent=newAgent({
21
26
name: 'Assistant',
22
-
model: 'gpt-4.1',
27
+
model: 'gpt-5.2',
23
28
instructions:
24
29
'Keep answers short. This example demonstrates responses.compact with a custom session. For every user turn, call fetch_image_data with the provided label. Do not include raw image bytes or data URLs in your final answer.',
25
30
modelSettings: {toolChoice: 'required'},
@@ -66,10 +71,19 @@ async function main() {
66
71
}
67
72
68
73
constcompactedHistory=awaitsession.getItems();
69
-
console.log('\nStored history after compaction:');
74
+
console.log('\nHitory including both compaction and newer items:');
70
75
for(constitemofcompactedHistory){
71
76
console.log(`- ${item.type}`);
72
77
}
78
+
79
+
// You can manually run compaction this way:
80
+
awaitsession.runCompaction({force: true});
81
+
82
+
constfinalHistory=awaitsession.getItems();
83
+
console.log('\nStored history after final compaction:');
0 commit comments