Codebase Investigator: Separate initial query from system prompt and apply templateStrings in query and initialMessages (#10282)

This commit is contained in:
Silvio Junior
2025-10-01 16:21:01 -04:00
committed by GitHub
parent f3152fa7fb
commit 7e493f4a9e
4 changed files with 272 additions and 34 deletions
+30 -2
View File
@@ -148,8 +148,11 @@ export class AgentExecutor {
// Phase 1: Work Phase
// The agent works in a loop until it stops calling tools.
const query = this.definition.promptConfig.query
? templateString(this.definition.promptConfig.query, inputs)
: 'Get Started!';
let currentMessages: Content[] = [
{ role: 'user', parts: [{ text: 'Get Started!' }] },
{ role: 'user', parts: [{ text: query }] },
];
while (true) {
@@ -302,7 +305,10 @@ export class AgentExecutor {
);
}
const startHistory = [...(promptConfig.initialMessages ?? [])];
const startHistory = this.applyTemplateToInitialMessages(
promptConfig.initialMessages ?? [],
inputs,
);
// Build system instruction from the templated prompt string.
const systemInstruction = promptConfig.systemPrompt
@@ -501,6 +507,28 @@ Important Rules:
return 'Based on your work so far, provide a comprehensive summary of your analysis and findings. Do not perform any more function calls.';
}
/**
* Applies template strings to initial messages.
*
* @param initialMessages The initial messages from the prompt config.
* @param inputs The validated input parameters for this invocation.
* @returns A new array of `Content` with templated strings.
*/
private applyTemplateToInitialMessages(
initialMessages: Content[],
inputs: AgentInputs,
): Content[] {
return initialMessages.map((content) => {
const newParts = (content.parts ?? []).map((part) => {
if ('text' in part && part.text !== undefined) {
return { text: templateString(part.text, inputs) };
}
return part;
});
return { ...content, parts: newParts };
});
}
/**
* Validates that all tools in a registry are safe for non-interactive use.
*