Skip to content

Commit ac8126c

Browse files
instruct the LLM to output the answer and stop researching when we are at the last step by modfying it's system prompt
1 parent 4293cbd commit ac8126c

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

packages/web/src/env.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export const env = createEnv({
107107
AWS_REGION: z.string().optional(),
108108

109109
SOURCEBOT_CHAT_MODEL_TEMPERATURE: numberSchema.default(0.3),
110-
SOURCEBOT_CHAT_MAX_STEP_COUNT: numberSchema.default(20),
110+
SOURCEBOT_CHAT_MAX_STEP_COUNT: numberSchema.default(10),
111111

112112
DEBUG_WRITE_CHAT_MESSAGES_TO_FILE: booleanSchema.default('false'),
113113
},

packages/web/src/features/chat/agent.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ export const createAgentStream = async ({
7171
}
7272
}
7373

74+
if (stepNumber === env.SOURCEBOT_CHAT_MAX_STEP_COUNT - 1) {
75+
return {
76+
system: `**CRITICAL**: You have reached the maximum number of steps!! YOU MUST PROVIDE YOUR FINAL ANSWER NOW. DO NOT KEEP RESEARCHING.\n\n${answerInstructions}`,
77+
activeTools: [],
78+
}
79+
}
80+
7481
return undefined;
7582
},
7683
temperature: env.SOURCEBOT_CHAT_MODEL_TEMPERATURE,
@@ -170,6 +177,11 @@ During the research phase, you have these tools available:
170177
Use these tools to gather comprehensive context before answering. Always explain why you're using each tool.
171178
</research_phase_instructions>
172179
180+
${answerInstructions}
181+
`;
182+
}
183+
184+
const answerInstructions = `
173185
<answer_instructions>
174186
When you have sufficient context, output your answer as a structured markdown response.
175187
@@ -196,7 +208,6 @@ Authentication in Sourcebot is built on NextAuth.js with a session-based approac
196208
197209
</answer_instructions>
198210
`;
199-
}
200211

201212
interface FileSourcesSystemPromptOptions {
202213
files: {

0 commit comments

Comments
 (0)