Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/core/src/agents/local-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export class LocalAgentExecutor<TOutput extends z.ZodTypeAny> {
): Promise<AgentTurnResult> {
const promptId = `${this.agentId}#${turnCounter}`;

await this.tryCompressChat(chat, promptId);
await this.tryCompressChat(chat, promptId, combinedSignal);

const { functionCalls } = await promptIdContext.run(promptId, async () =>
this.callModel(chat, currentMessage, combinedSignal, promptId),
Expand Down Expand Up @@ -668,6 +668,7 @@ export class LocalAgentExecutor<TOutput extends z.ZodTypeAny> {
private async tryCompressChat(
chat: GeminiChat,
prompt_id: string,
abortSignal?: AbortSignal,
): Promise<void> {
const model = this.definition.modelConfig.model ?? DEFAULT_GEMINI_MODEL;

Expand All @@ -678,6 +679,7 @@ export class LocalAgentExecutor<TOutput extends z.ZodTypeAny> {
model,
this.runtimeContext,
this.hasFailedCompressionAttempt,
abortSignal,
);

if (
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/core/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ export class GeminiClient {
// Check for context window overflow
const modelForLimitCheck = this._getActiveModelForCurrentTurn();

const compressed = await this.tryCompressChat(prompt_id, false);
const compressed = await this.tryCompressChat(prompt_id, false, signal);

if (compressed.compressionStatus === CompressionStatus.COMPRESSED) {
yield { type: GeminiEventType.ChatCompressed, value: compressed };
Expand Down Expand Up @@ -1049,6 +1049,7 @@ export class GeminiClient {
async tryCompressChat(
prompt_id: string,
force: boolean = false,
abortSignal?: AbortSignal,
): Promise<ChatCompressionInfo> {
// If the model is 'auto', we will use a placeholder model to check.
// Compression occurs before we choose a model, so calling `count_tokens`
Expand All @@ -1062,6 +1063,7 @@ export class GeminiClient {
model,
this.config,
this.hasFailedCompressionAttempt,
abortSignal,
);

if (
Expand Down