From b3d5d472edf594b6a0c90fe69a6a4b1d62cc0548 Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Mon, 5 Jan 2026 01:13:30 -0500 Subject: [PATCH] fix: skip DCP injection for internal agents (title, summary, compaction) Detect internal agent sessions by their system prompt signatures and skip injecting context management prompts. This prevents wasting tokens and confusing small models used for title generation and conversation summaries. Fixes #218 --- index.ts | 15 +++++++++++++++ lib/hooks.ts | 2 +- lib/state/state.ts | 2 ++ lib/state/types.ts | 5 +++-- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/index.ts b/index.ts index d7a7a145..13df1b08 100644 --- a/index.ts +++ b/index.ts @@ -30,6 +30,21 @@ const plugin: Plugin = (async (ctx) => { _input: unknown, output: { system: string[] }, ) => { + const systemText = output.system.join("\n") + const internalAgentSignatures = [ + "You are a title generator", + "You are a helpful AI assistant tasked with summarizing conversations", + "Summarize what was done in this conversation", + ] + if (internalAgentSignatures.some((sig) => systemText.includes(sig))) { + logger.info("Skipping DCP injection for internal agent") + state.isInternalAgent = true + return + } + + // Reset flag for normal sessions + state.isInternalAgent = false + const discardEnabled = config.tools.discard.enabled const extractEnabled = config.tools.extract.enabled diff --git a/lib/hooks.ts b/lib/hooks.ts index e70c892a..231357df 100644 --- a/lib/hooks.ts +++ b/lib/hooks.ts @@ -15,7 +15,7 @@ export function createChatMessageTransformHandler( return async (input: {}, output: { messages: WithParts[] }) => { await checkSession(client, state, logger, output.messages) - if (state.isSubAgent) { + if (state.isSubAgent || state.isInternalAgent) { return } diff --git a/lib/state/state.ts b/lib/state/state.ts index 956ac9dd..05ebc0cb 100644 --- a/lib/state/state.ts +++ b/lib/state/state.ts @@ -43,6 +43,7 @@ export function createSessionState(): SessionState { return { sessionId: null, isSubAgent: false, + isInternalAgent: false, prune: { toolIds: [], }, @@ -61,6 +62,7 @@ export function createSessionState(): SessionState { export function resetSessionState(state: SessionState): void { state.sessionId = null state.isSubAgent = false + state.isInternalAgent = false state.prune = { toolIds: [], } diff --git a/lib/state/types.ts b/lib/state/types.ts index 9a6de02d..f9dfd7af 100644 --- a/lib/state/types.ts +++ b/lib/state/types.ts @@ -12,7 +12,7 @@ export interface ToolParameterEntry { parameters: any status?: ToolStatus error?: string - turn: number // Which turn (step-start count) this tool was called on + turn: number } export interface SessionStats { @@ -27,11 +27,12 @@ export interface Prune { export interface SessionState { sessionId: string | null isSubAgent: boolean + isInternalAgent: boolean prune: Prune stats: SessionStats toolParameters: Map nudgeCounter: number lastToolPrune: boolean lastCompaction: number - currentTurn: number // Current turn count derived from step-start parts + currentTurn: number }