Skip to content

Commit 64ebddc

Browse files
committed
Fix bug where instructions prompt was not added if no prompt was provided
1 parent a492cdc commit 64ebddc

File tree

1 file changed

+26
-29
lines changed

1 file changed

+26
-29
lines changed

backend/src/run-agent-step.ts

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -502,34 +502,27 @@ export const loopAgentSteps = async (
502502
})
503503

504504
// Initialize message history with user prompt and instructions on first iteration
505-
const hasPrompt = Boolean(
506-
prompt || (spawnParams && Object.keys(spawnParams).length > 0),
507-
)
508-
509-
// Get the instructions prompt if we have a prompt/params
510-
const instructionsPrompt = hasPrompt
511-
? await getAgentPrompt({
512-
...params,
513-
agentTemplate,
514-
promptType: { type: 'instructionsPrompt' },
515-
agentTemplates: localAgentTemplates,
516-
additionalToolDefinitions: () => {
517-
const additionalToolDefinitions = cloneDeep(
518-
Object.fromEntries(
519-
Object.entries(fileContext.customToolDefinitions).filter(
520-
([toolName]) => agentTemplate.toolNames.includes(toolName),
521-
),
522-
),
523-
)
524-
return getMCPToolData({
525-
ws,
526-
toolNames: agentTemplate.toolNames,
527-
mcpServers: agentTemplate.mcpServers,
528-
writeTo: additionalToolDefinitions,
529-
})
530-
},
505+
const instructionsPrompt = await getAgentPrompt({
506+
...params,
507+
agentTemplate,
508+
promptType: { type: 'instructionsPrompt' },
509+
agentTemplates: localAgentTemplates,
510+
additionalToolDefinitions: () => {
511+
const additionalToolDefinitions = cloneDeep(
512+
Object.fromEntries(
513+
Object.entries(fileContext.customToolDefinitions).filter(
514+
([toolName]) => agentTemplate.toolNames.includes(toolName),
515+
),
516+
),
517+
)
518+
return getMCPToolData({
519+
ws,
520+
toolNames: agentTemplate.toolNames,
521+
mcpServers: agentTemplate.mcpServers,
522+
writeTo: additionalToolDefinitions,
531523
})
532-
: undefined
524+
},
525+
})
533526

534527
// Build the initial message history with user prompt and instructions
535528
// Generate system prompt once, using parent's if inheritParentSystemPrompt is true
@@ -558,12 +551,16 @@ export const loopAgentSteps = async (
558551
},
559552
})) ?? ''
560553

554+
const hasUserMessage = Boolean(
555+
prompt || (spawnParams && Object.keys(spawnParams).length > 0),
556+
)
557+
561558
const initialMessages = buildArray<Message>(
562559
...agentState.messageHistory,
563560

564-
hasPrompt && [
561+
hasUserMessage && [
565562
{
566-
// Actual user prompt!
563+
// Actual user message!
567564
role: 'user' as const,
568565
content: buildUserMessageContent(prompt, spawnParams, content),
569566
keepDuringTruncation: true,

0 commit comments

Comments
 (0)