Skip to content

Commit b0fd88a

Browse files
committed
add maxContextLength parameter
1 parent 5825196 commit b0fd88a

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

.agents/context-pruner.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { publisher } from './constants'
2+
23
import type { AgentDefinition, Message } from './types/agent-definition'
34

45
const definition: AgentDefinition = {
@@ -11,19 +12,29 @@ const definition: AgentDefinition = {
1112

1213
spawnerPrompt: `Spawn this agent between steps to prune context, starting with old tool results and then old messages.`,
1314

14-
inputSchema: {},
15+
inputSchema: {
16+
params: {
17+
type: 'object',
18+
properties: {
19+
maxContextLength: {
20+
type: 'number',
21+
},
22+
},
23+
required: [],
24+
},
25+
},
1526

1627
includeMessageHistory: true,
1728

18-
handleSteps: function* ({ agentState }) {
29+
handleSteps: function* ({ agentState, params }) {
1930
const messages = agentState.messageHistory
2031

2132
const countTokensJson = (obj: any): number => {
2233
// Very rough approximation
2334
return Math.ceil(JSON.stringify(obj).length / 3)
2435
}
2536

26-
const maxMessageTokens = 200_000
37+
const maxMessageTokens: number = params?.maxContextLength ?? 200_000
2738
const numTerminalCommandsToKeep = 5
2839

2940
// Remove the last assistant message if it contains the spawn call that invoked this context-pruner

.agents/factory/base.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ export const base = (model: ModelName): Omit<SecretAgentDefinition, 'id'> => ({
1919
type: 'string',
2020
description: 'A coding task to complete',
2121
},
22+
params: {
23+
type: 'object',
24+
properties: {
25+
maxContextLength: {
26+
type: 'number',
27+
},
28+
},
29+
required: [],
30+
},
2231
},
2332
outputMode: 'last_message',
2433
includeMessageHistory: false,
@@ -50,13 +59,14 @@ export const base = (model: ModelName): Omit<SecretAgentDefinition, 'id'> => ({
5059
instructionsPrompt: baseAgentUserInputPrompt(model),
5160
stepPrompt: baseAgentAgentStepPrompt(model),
5261

53-
handleSteps: function* ({ agentState }) {
62+
handleSteps: function* ({ params }) {
5463
while (true) {
5564
// Run context-pruner before each step
5665
yield {
5766
toolName: 'spawn_agent_inline',
5867
input: {
5968
agent_type: 'context-pruner',
69+
params,
6070
},
6171
} as any
6272

0 commit comments

Comments
 (0)