Skip to content

Commit 41e7ef0

Browse files
committed
fix: disable pruning in subagent sessions and guide model to return summary
1 parent 58aeac6 commit 41e7ef0

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ const plugin: Plugin = (async (ctx) => {
8888
event: createEventHandler(ctx.client, janitor, logger, config, toolTracker),
8989
"chat.params": createChatParamsHandler(ctx.client, state, logger),
9090
tool: config.strategies.onTool.length > 0 ? {
91-
prune: createPruningTool(janitor, config, toolTracker),
91+
prune: createPruningTool(ctx.client, janitor, config, toolTracker),
9292
} : undefined,
9393
}
9494
}) satisfies Plugin

lib/pruning-tool.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { PluginConfig } from "./config"
44
import type { ToolTracker } from "./synth-instruction"
55
import { resetToolTrackerCount } from "./synth-instruction"
66
import { loadPrompt } from "./prompt"
7+
import { isSubagentSession } from "./hooks"
78

89
/** Tool description for the context_pruning tool, loaded from prompts/tool.txt */
910
export const CONTEXT_PRUNING_DESCRIPTION = loadPrompt("tool")
@@ -12,7 +13,7 @@ export const CONTEXT_PRUNING_DESCRIPTION = loadPrompt("tool")
1213
* Creates the context_pruning tool definition.
1314
* Returns a tool definition that can be passed to the plugin's tool registry.
1415
*/
15-
export function createPruningTool(janitor: Janitor, config: PluginConfig, toolTracker: ToolTracker): ReturnType<typeof tool> {
16+
export function createPruningTool(client: any, janitor: Janitor, config: PluginConfig, toolTracker: ToolTracker): ReturnType<typeof tool> {
1617
return tool({
1718
description: CONTEXT_PRUNING_DESCRIPTION,
1819
args: {
@@ -21,6 +22,12 @@ export function createPruningTool(janitor: Janitor, config: PluginConfig, toolTr
2122
),
2223
},
2324
async execute(args, ctx) {
25+
// Skip pruning in subagent sessions, but guide the model to provide a proper summary
26+
// TODO: implement something better here when PR 4913 is merged
27+
if (await isSubagentSession(client, ctx.sessionID)) {
28+
return "Pruning is disabled in subagent sessions. IMPORTANT: You must now provide your final summary/findings to return to the main agent. Do not call this tool again - simply respond with your results."
29+
}
30+
2431
const result = await janitor.runForTool(
2532
ctx.sessionID,
2633
config.strategies.onTool,

0 commit comments

Comments
 (0)