mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-13 21:32:56 -07:00
Codebase Investigator: Separate initial query from system prompt and apply templateStrings in query and initialMessages (#10282)
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user