Add support for specifying maxSessionTurns via the settings configuration (#3507)

This commit is contained in:
anj-s
2025-07-11 07:55:03 -07:00
committed by GitHub
parent 0151a9e1a3
commit c9e1e6d3bd
10 changed files with 231 additions and 15 deletions

View File

@@ -86,6 +86,7 @@ export class GeminiClient {
temperature: 0,
topP: 1,
};
private sessionTurnCount = 0;
private readonly MAX_TURNS = 100;
/**
* Threshold for compression token count as a fraction of the model's token limit.
@@ -266,6 +267,14 @@ export class GeminiClient {
turns: number = this.MAX_TURNS,
originalModel?: string,
): AsyncGenerator<ServerGeminiStreamEvent, Turn> {
this.sessionTurnCount++;
if (
this.config.getMaxSessionTurns() > 0 &&
this.sessionTurnCount > this.config.getMaxSessionTurns()
) {
yield { type: GeminiEventType.MaxSessionTurns };
return new Turn(this.getChat(), prompt_id);
}
// Ensure turns never exceeds MAX_TURNS to prevent infinite loops
const boundedTurns = Math.min(turns, this.MAX_TURNS);
if (!boundedTurns) {