fix(agents): wire up autoCompactIfNeeded to prevent token overflow
The auto-compaction logic (threshold 80K tokens, summarize older messages via Haiku) existed but was never called in sendMessage flow. Now called after context injection, before agent loop. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
f2903bd67a
commit
033e476a6f
|
|
@ -211,7 +211,7 @@ export class CoordinatorAgentService implements OnModuleInit {
|
|||
const systemPrompt = this.buildSystemPromptBlocks();
|
||||
|
||||
// 3. Inject dynamic context
|
||||
const enrichedMessages = await this.contextInjector.inject(
|
||||
let enrichedMessages = await this.contextInjector.inject(
|
||||
{
|
||||
conversationId: context.conversationId,
|
||||
userId: context.userId,
|
||||
|
|
@ -227,6 +227,13 @@ export class CoordinatorAgentService implements OnModuleInit {
|
|||
messages,
|
||||
);
|
||||
|
||||
// 3.5. Auto-compact if messages exceed token threshold
|
||||
const { messages: compactedMessages, wasCompacted } =
|
||||
await this.contextInjector.autoCompactIfNeeded(enrichedMessages, this.anthropicClient);
|
||||
if (wasCompacted) {
|
||||
enrichedMessages = compactedMessages;
|
||||
}
|
||||
|
||||
// 4. Create abort controller
|
||||
const abortController = new AbortController();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue