Skip to content

Commit 86ba4b4

Browse files
committed
Exclude tool results as well when includeToolCall = false
1 parent a8e8d19 commit 86ba4b4

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

backend/src/__tests__/run-programmatic-step.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ describe('runProgrammaticStep', () => {
120120
clientSessionId: 'test-session',
121121
fingerprintId: 'test-fingerprint',
122122
onResponseChunk: () => {},
123-
agentType: 'test-agent' as any,
124123
fileContext: mockFileContext,
125124
assistantMessage: undefined,
126125
assistantPrefix: undefined,

backend/src/__tests__/sandbox-generator.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ describe('QuickJS Sandbox Generator', () => {
114114
mockAgentState.agentType = 'test-vm-agent-error'
115115

116116
mockParams.template = mockTemplate
117-
mockParams.agentType = 'test-vm-agent-error'
118117
mockParams.params = {}
119118
mockParams.localAgentTemplates = { 'test-vm-agent-error': mockTemplate }
120119

backend/src/run-agent-step.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,6 @@ export const loopAgentSteps = async (
566566
clientSessionId,
567567
fingerprintId,
568568
onResponseChunk,
569-
agentType,
570569
fileContext,
571570
ws,
572571
template: agentTemplate,

backend/src/run-programmatic-step.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ import type {
1818
ToolResultPart,
1919
} from '@codebuff/common/types/messages/content-part'
2020
import type { PrintModeEvent } from '@codebuff/common/types/print-mode'
21-
import type {
22-
AgentState,
23-
AgentTemplateType,
24-
} from '@codebuff/common/types/session-state'
21+
import type { AgentState } from '@codebuff/common/types/session-state'
2522
import type { ProjectFileContext } from '@codebuff/common/util/file'
2623
import type { WebSocket } from 'ws'
2724

@@ -54,7 +51,6 @@ export async function runProgrammaticStep(
5451
clientSessionId,
5552
fingerprintId,
5653
onResponseChunk,
57-
agentType,
5854
fileContext,
5955
ws,
6056
localAgentTemplates,
@@ -68,7 +64,6 @@ export async function runProgrammaticStep(
6864
clientSessionId: string
6965
fingerprintId: string
7066
onResponseChunk: (chunk: string | PrintModeEvent) => void
71-
agentType: AgentTemplateType
7267
fileContext: ProjectFileContext
7368
ws: WebSocket
7469
localAgentTemplates: Record<string, AgentTemplate>
@@ -194,9 +189,9 @@ export async function runProgrammaticStep(
194189
)
195190
}
196191

192+
const excludeToolFromMessageHistory = toolCall?.includeToolCall === false
197193
// Add assistant message with the tool call before executing it
198-
// Exception: don't add tool call message for add_message since it adds its own message
199-
if (toolCall?.includeToolCall !== false) {
194+
if (!excludeToolFromMessageHistory) {
200195
const toolCallString = getToolCallString(
201196
toolCall.toolName,
202197
toolCall.input,
@@ -232,6 +227,7 @@ export async function runProgrammaticStep(
232227
state,
233228
userId,
234229
autoInsertEndStepParam: true,
230+
excludeToolFromMessageHistory,
235231
})
236232

237233
// TODO: Remove messages from state and always use agentState.messageHistory.

backend/src/tools/tool-executor.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ export interface ExecuteToolCallParams<T extends string = ToolName> {
126126
state: Record<string, any>
127127
userId: string | undefined
128128
autoInsertEndStepParam?: boolean
129+
excludeToolFromMessageHistory?: boolean
129130
}
130131

131132
export function executeToolCall<T extends ToolName>({
@@ -145,6 +146,7 @@ export function executeToolCall<T extends ToolName>({
145146
state,
146147
userId,
147148
autoInsertEndStepParam = false,
149+
excludeToolFromMessageHistory = false,
148150
}: ExecuteToolCallParams<T>): Promise<void> {
149151
const toolCall: CodebuffToolCall<T> | ToolCallError = parseRawToolCall<T>(
150152
{
@@ -264,10 +266,12 @@ export function executeToolCall<T extends ToolName>({
264266

265267
toolResults.push(toolResult)
266268

267-
state.messages.push({
268-
role: 'tool' as const,
269-
content: toolResult,
270-
})
269+
if (!excludeToolFromMessageHistory) {
270+
state.messages.push({
271+
role: 'tool' as const,
272+
content: toolResult,
273+
})
274+
}
271275
})
272276
}
273277

@@ -363,6 +367,7 @@ export function executeCustomToolCall({
363367
state,
364368
userId,
365369
autoInsertEndStepParam = false,
370+
excludeToolFromMessageHistory = false,
366371
}: ExecuteToolCallParams<string>): Promise<void> {
367372
const toolCall: CustomToolCall | ToolCallError = parseRawCustomToolCall(
368373
fileContext.customToolDefinitions,
@@ -461,10 +466,12 @@ export function executeCustomToolCall({
461466

462467
toolResults.push(toolResult)
463468

464-
state.messages.push({
465-
role: 'tool' as const,
466-
content: toolResult,
467-
} satisfies Message)
469+
if (!excludeToolFromMessageHistory) {
470+
state.messages.push({
471+
role: 'tool' as const,
472+
content: toolResult,
473+
} satisfies Message)
474+
}
468475
return
469476
})
470477
}

0 commit comments

Comments
 (0)