mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-17 06:04:51 +00:00
Use token-based maxTokens instead of fraction-based reserveFraction
- BranchSummarySettings.maxTokens (default 100000) instead of reserveFraction - More intuitive and consistent with CompactionSettings.keepRecentTokens
This commit is contained in:
parent
839a46e6fe
commit
f5f39f08f1
3 changed files with 8 additions and 12 deletions
|
|
@ -1656,7 +1656,7 @@ export class AgentSession {
|
||||||
apiKey,
|
apiKey,
|
||||||
signal: this._branchSummaryAbortController.signal,
|
signal: this._branchSummaryAbortController.signal,
|
||||||
customInstructions: options.customInstructions,
|
customInstructions: options.customInstructions,
|
||||||
reserveFraction: branchSummarySettings.reserveFraction,
|
maxTokens: branchSummarySettings.maxTokens,
|
||||||
});
|
});
|
||||||
this._branchSummaryAbortController = undefined;
|
this._branchSummaryAbortController = undefined;
|
||||||
if (result.aborted) {
|
if (result.aborted) {
|
||||||
|
|
|
||||||
|
|
@ -53,8 +53,8 @@ export interface GenerateBranchSummaryOptions {
|
||||||
signal: AbortSignal;
|
signal: AbortSignal;
|
||||||
/** Optional custom instructions for summarization */
|
/** Optional custom instructions for summarization */
|
||||||
customInstructions?: string;
|
customInstructions?: string;
|
||||||
/** Reserve this fraction of context window for summary (default 0.2) */
|
/** Maximum tokens to include in summary context (default 100000) */
|
||||||
reserveFraction?: number;
|
maxTokens?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
@ -321,13 +321,9 @@ export async function generateBranchSummary(
|
||||||
entries: SessionEntry[],
|
entries: SessionEntry[],
|
||||||
options: GenerateBranchSummaryOptions,
|
options: GenerateBranchSummaryOptions,
|
||||||
): Promise<BranchSummaryResult> {
|
): Promise<BranchSummaryResult> {
|
||||||
const { model, apiKey, signal, customInstructions, reserveFraction = 0.2 } = options;
|
const { model, apiKey, signal, customInstructions, maxTokens = 100000 } = options;
|
||||||
|
|
||||||
// Calculate token budget (leave room for summary generation)
|
const { messages, fileOps } = prepareBranchEntries(entries, maxTokens);
|
||||||
const contextWindow = model.contextWindow || 128000;
|
|
||||||
const tokenBudget = Math.floor(contextWindow * (1 - reserveFraction));
|
|
||||||
|
|
||||||
const { messages, fileOps } = prepareBranchEntries(entries, tokenBudget);
|
|
||||||
|
|
||||||
if (messages.length === 0) {
|
if (messages.length === 0) {
|
||||||
return { summary: "No content to summarize" };
|
return { summary: "No content to summarize" };
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ export interface CompactionSettings {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BranchSummarySettings {
|
export interface BranchSummarySettings {
|
||||||
reserveFraction?: number; // default: 0.2 (fraction of context window reserved for summary)
|
maxTokens?: number; // default: 100000 (max tokens to include in branch summary context)
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RetrySettings {
|
export interface RetrySettings {
|
||||||
|
|
@ -260,9 +260,9 @@ export class SettingsManager {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
getBranchSummarySettings(): { reserveFraction: number } {
|
getBranchSummarySettings(): { maxTokens: number } {
|
||||||
return {
|
return {
|
||||||
reserveFraction: this.settings.branchSummary?.reserveFraction ?? 0.2,
|
maxTokens: this.settings.branchSummary?.maxTokens ?? 100000,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue