Skip to content

Commit 5b1feba

Browse files
committed
remove relace tool formatter experiment
1 parent a07ddf0 commit 5b1feba

File tree

2 files changed

+15
-155
lines changed

2 files changed

+15
-155
lines changed

backend/src/llm-apis/relace-api.ts

Lines changed: 0 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import {
44
parseMarkdownCodeBlock,
55
} from 'common/util/file'
66

7-
import { CoreMessage } from 'ai'
8-
import { toolSchema } from 'common/constants/tools'
97
import { env } from '../env.mjs'
108
import { saveMessage } from '../llm-apis/message-cost-tracker'
119
import { logger } from '../util/logger'
@@ -242,141 +240,3 @@ export async function rerank(
242240
return files.map((f) => f.path)
243241
}
244242
}
245-
246-
const toolParams = Object.entries(toolSchema)
247-
.map(([name, params]) => {
248-
return `\`${name}\`: [${params
249-
.map((p) => (typeof p === 'string' ? JSON.stringify(p) : `${p}`))
250-
.join(', ')}]`
251-
})
252-
.join('\n')
253-
254-
const outputSchema = {
255-
type: 'object',
256-
properties: {
257-
tool_calls: {
258-
type: 'array',
259-
items: {
260-
type: 'object',
261-
properties: {
262-
name: { type: 'string' },
263-
args: { type: 'object' },
264-
},
265-
required: ['name', 'args'],
266-
},
267-
},
268-
},
269-
}
270-
271-
const systemInstructions = `
272-
You are a helpful assistant that structures potentially malformed XML text into tool calls.
273-
274-
Below are the available tools and their parameters. Parameters are either "String" or /RegExp/ values.
275-
${toolParams}
276-
277-
Some tools will have multi-line parameters (frequently write_file). Do not forget to add these to the tool_calls.
278-
279-
None of the parameters are required. Do not infer any additional tools or parameters beyond those explicitly listed in the user message.
280-
281-
Output according to this schema:
282-
${JSON.stringify(outputSchema, null, 2)}
283-
`.trim()
284-
285-
export async function toolFormatter(
286-
assistantMessage: string,
287-
options: {
288-
clientSessionId: string
289-
fingerprintId: string
290-
userInputId: string
291-
userId: string | undefined
292-
messageId: string
293-
}
294-
) {
295-
const { clientSessionId, fingerprintId, userInputId, userId, messageId } =
296-
options
297-
const startTime = Date.now()
298-
299-
const messages: CoreMessage[] = [
300-
{ role: 'system', content: systemInstructions },
301-
{ role: 'user', content: assistantMessage },
302-
]
303-
304-
try {
305-
const response = (await Promise.race([
306-
fetch('https://tool-formatter.endpoint.relace.run/v1/code/format', {
307-
method: 'POST',
308-
headers: {
309-
'Content-Type': 'application/json',
310-
Authorization: `Bearer ${env.RELACE_API_KEY}`,
311-
},
312-
body: JSON.stringify({
313-
model: 'Tool-Formatter',
314-
messages,
315-
temperature: 0,
316-
max_tokens: 8192,
317-
response_format: {
318-
type: 'json_schema',
319-
json_schema: {
320-
name: 'tool_calls',
321-
schema: outputSchema,
322-
},
323-
},
324-
'relace-metadata': {
325-
'codebuff-id': messageId,
326-
},
327-
}),
328-
}),
329-
timeoutPromise(100_000),
330-
])) as Response
331-
332-
if (!response.ok) {
333-
const errorText = await response
334-
.text()
335-
.catch(() => 'No error text available')
336-
logger.error(
337-
{
338-
status: response.status,
339-
statusText: response.statusText,
340-
errorText,
341-
assistantMessageLength: assistantMessage.length,
342-
messageId,
343-
},
344-
'Relace Tool Formatter API error'
345-
)
346-
return
347-
}
348-
349-
const json = await response.json()
350-
const toolCalls = JSON.parse(json.choices[0].message.content)
351-
352-
saveMessage({
353-
messageId,
354-
userId,
355-
clientSessionId,
356-
fingerprintId,
357-
userInputId,
358-
model: 'relace-tool-formatter',
359-
request: messages,
360-
response: toolCalls,
361-
inputTokens: countTokens(systemInstructions + assistantMessage),
362-
outputTokens: countTokens(JSON.stringify(toolCalls)),
363-
finishedAt: new Date(),
364-
latencyMs: Date.now() - startTime,
365-
chargeUser: false,
366-
})
367-
368-
logger.info({ toolCalls }, 'Relace Tool Formatter')
369-
} catch (error) {
370-
logger.error(
371-
{
372-
error:
373-
error && typeof error === 'object' && 'message' in error
374-
? error.message
375-
: 'Unknown error',
376-
},
377-
'Error calling Relace Tool Formatter API'
378-
)
379-
// Silent failure as specified - no fallback needed
380-
return
381-
}
382-
}

backend/src/main-prompt.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ import {
3131
requestRelevantFilesForTraining,
3232
} from './find-files/request-files-prompt'
3333
import { getDocumentationForQuery } from './get-documentation-for-query'
34-
import { toolFormatter } from './llm-apis/relace-api'
3534
import { processFileBlock } from './process-file-block'
3635
import { processStrReplace } from './process-str-replace'
3736
import { getAgentStream } from './prompt-agent-stream'
37+
import { getAgentSystemPrompt } from './system-prompt/agent-system-prompt'
3838
import { additionalSystemPrompts } from './system-prompt/prompts'
3939
import { saveAgentRequest } from './system-prompt/save-agent-request'
4040
import { getSearchSystemPrompt } from './system-prompt/search-system-prompt'
@@ -72,13 +72,12 @@ import {
7272
simplifyReadFileToolResult,
7373
} from './util/simplify-tool-results'
7474
import { countTokens, countTokensJson } from './util/token-counter'
75+
import { getRequestContext } from './websockets/request-context'
7576
import {
7677
requestFiles,
7778
requestOptionalFile,
7879
} from './websockets/websocket-action'
7980
import { processStreamWithTags } from './xml-stream-parser'
80-
import { getRequestContext } from './websockets/request-context'
81-
import { getAgentSystemPrompt } from './system-prompt/agent-system-prompt'
8281

8382
const MAX_CONSECUTIVE_ASSISTANT_MESSAGES = 12
8483
// Turn this on to collect full file context, using Claude-4-Opus to pick which files to send up
@@ -144,7 +143,9 @@ export const mainPrompt = async (
144143
(t) => t.name === 'run_terminal_command'
145144
)
146145
const isAskMode = costMode === 'ask'
147-
const isExporting = prompt && (prompt.toLowerCase() === '/export' || prompt.toLowerCase() === 'export')
146+
const isExporting =
147+
prompt &&
148+
(prompt.toLowerCase() === '/export' || prompt.toLowerCase() === 'export')
148149
const geminiThinkingEnabled = costMode === 'max'
149150
const isLiteMode = costMode === 'lite'
150151
const isGeminiPro = model === models.gemini2_5_pro_preview
@@ -664,7 +665,16 @@ export const mainPrompt = async (
664665
}
665666

666667
// Filter out restricted tools in ask mode unless exporting summary
667-
if (isAskMode && !isExporting && ['write_file', 'str_replace', 'create_plan', 'run_terminal_command'].includes(tool)) {
668+
if (
669+
isAskMode &&
670+
!isExporting &&
671+
[
672+
'write_file',
673+
'str_replace',
674+
'create_plan',
675+
'run_terminal_command',
676+
].includes(tool)
677+
) {
668678
serverToolResults.push({
669679
name: tool,
670680
id: generateCompactId(),
@@ -853,16 +863,6 @@ export const mainPrompt = async (
853863
onResponseChunk(chunk)
854864
}
855865

856-
if (foundParsingError && process.env.NEXT_PUBLIC_CB_ENVIRONMENT === 'local') {
857-
toolFormatter(fullResponse, {
858-
messageId: generateCompactId('cb-tf-'),
859-
clientSessionId,
860-
fingerprintId,
861-
userInputId: promptId,
862-
userId,
863-
})
864-
}
865-
866866
const agentResponseTrace: AgentResponseTrace = {
867867
type: 'agent-response',
868868
created_at: new Date(),

0 commit comments

Comments
 (0)