mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-02 17:31:05 -07:00
Fix and rename introspection agent -> cli help agent (#16097)
This commit is contained in:
committed by
GitHub
parent
bd77515fd9
commit
d4b418ba01
@@ -5,18 +5,22 @@
|
||||
*/
|
||||
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { IntrospectionAgent } from './introspection-agent.js';
|
||||
import { CliHelpAgent } from './cli-help-agent.js';
|
||||
import { GET_INTERNAL_DOCS_TOOL_NAME } from '../tools/tool-names.js';
|
||||
import { GEMINI_MODEL_ALIAS_FLASH } from '../config/models.js';
|
||||
import type { LocalAgentDefinition } from './types.js';
|
||||
import type { Config } from '../config/config.js';
|
||||
|
||||
describe('IntrospectionAgent', () => {
|
||||
const localAgent = IntrospectionAgent as LocalAgentDefinition;
|
||||
describe('CliHelpAgent', () => {
|
||||
const fakeConfig = {
|
||||
getMessageBus: () => ({}),
|
||||
} as unknown as Config;
|
||||
const localAgent = CliHelpAgent(fakeConfig) as LocalAgentDefinition;
|
||||
|
||||
it('should have the correct agent definition metadata', () => {
|
||||
expect(localAgent.name).toBe('introspection_agent');
|
||||
expect(localAgent.name).toBe('cli_help');
|
||||
expect(localAgent.kind).toBe('local');
|
||||
expect(localAgent.displayName).toBe('Introspection Agent');
|
||||
expect(localAgent.displayName).toBe('CLI Help Agent');
|
||||
expect(localAgent.description).toContain('Gemini CLI');
|
||||
});
|
||||
|
||||
@@ -32,7 +36,9 @@ describe('IntrospectionAgent', () => {
|
||||
expect(localAgent.modelConfig?.model).toBe(GEMINI_MODEL_ALIAS_FLASH);
|
||||
|
||||
const tools = localAgent.toolConfig?.tools || [];
|
||||
const hasInternalDocsTool = tools.includes(GET_INTERNAL_DOCS_TOOL_NAME);
|
||||
const hasInternalDocsTool = tools.some(
|
||||
(t) => typeof t !== 'string' && t.name === GET_INTERNAL_DOCS_TOOL_NAME,
|
||||
);
|
||||
expect(hasInternalDocsTool).toBe(true);
|
||||
});
|
||||
|
||||
@@ -5,11 +5,12 @@
|
||||
*/
|
||||
|
||||
import type { AgentDefinition } from './types.js';
|
||||
import { GET_INTERNAL_DOCS_TOOL_NAME } from '../tools/tool-names.js';
|
||||
import { GEMINI_MODEL_ALIAS_FLASH } from '../config/models.js';
|
||||
import { z } from 'zod';
|
||||
import type { Config } from '../config/config.js';
|
||||
import { GetInternalDocsTool } from '../tools/get-internal-docs.js';
|
||||
|
||||
const IntrospectionReportSchema = z.object({
|
||||
const CliHelpReportSchema = z.object({
|
||||
answer: z
|
||||
.string()
|
||||
.describe('The detailed answer to the user question about Gemini CLI.'),
|
||||
@@ -22,14 +23,14 @@ const IntrospectionReportSchema = z.object({
|
||||
* An agent specialized in answering questions about Gemini CLI itself,
|
||||
* using its own documentation and runtime state.
|
||||
*/
|
||||
export const IntrospectionAgent: AgentDefinition<
|
||||
typeof IntrospectionReportSchema
|
||||
> = {
|
||||
name: 'introspection_agent',
|
||||
export const CliHelpAgent = (
|
||||
config: Config,
|
||||
): AgentDefinition<typeof CliHelpReportSchema> => ({
|
||||
name: 'cli_help',
|
||||
kind: 'local',
|
||||
displayName: 'Introspection Agent',
|
||||
displayName: 'CLI Help Agent',
|
||||
description:
|
||||
'Specialized in answering questions about yourself (Gemini CLI): features, documentation, and current runtime configuration.',
|
||||
'Specialized in answering questions about how users use you, (Gemini CLI): features, documentation, and current runtime configuration.',
|
||||
inputConfig: {
|
||||
inputs: {
|
||||
question: {
|
||||
@@ -42,7 +43,7 @@ export const IntrospectionAgent: AgentDefinition<
|
||||
outputConfig: {
|
||||
outputName: 'report',
|
||||
description: 'The final answer and sources as a JSON object.',
|
||||
schema: IntrospectionReportSchema,
|
||||
schema: CliHelpReportSchema,
|
||||
},
|
||||
|
||||
processOutput: (output) => JSON.stringify(output, null, 2),
|
||||
@@ -60,7 +61,7 @@ export const IntrospectionAgent: AgentDefinition<
|
||||
},
|
||||
|
||||
toolConfig: {
|
||||
tools: [GET_INTERNAL_DOCS_TOOL_NAME],
|
||||
tools: [new GetInternalDocsTool(config.getMessageBus())],
|
||||
},
|
||||
|
||||
promptConfig: {
|
||||
@@ -70,7 +71,7 @@ export const IntrospectionAgent: AgentDefinition<
|
||||
'${question}\n' +
|
||||
'</question>',
|
||||
systemPrompt:
|
||||
"You are **Introspection Agent**, an expert on Gemini CLI. Your purpose is to provide accurate information about Gemini CLI's features, configuration, and current state.\n\n" +
|
||||
"You are **CLI Help Agent**, an expert on Gemini CLI. Your purpose is to provide accurate information about Gemini CLI's features, configuration, and current state.\n\n" +
|
||||
'### Runtime Context\n' +
|
||||
'- **CLI Version:** ${cliVersion}\n' +
|
||||
'- **Active Model:** ${activeModel}\n' +
|
||||
@@ -82,4 +83,4 @@ export const IntrospectionAgent: AgentDefinition<
|
||||
'4. **Non-Interactive**: You operate in a loop and cannot ask the user for more info. If the question is ambiguous, answer as best as you can with the information available.\n\n' +
|
||||
'You MUST call `complete_task` with a JSON report containing your `answer` and the `sources` you used.',
|
||||
},
|
||||
};
|
||||
});
|
||||
@@ -220,26 +220,26 @@ describe('AgentRegistry', () => {
|
||||
).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should register introspection agent if enabled', async () => {
|
||||
it('should register CLI help agent if enabled', async () => {
|
||||
const config = makeFakeConfig({
|
||||
introspectionAgentSettings: { enabled: true },
|
||||
cliHelpAgentSettings: { enabled: true },
|
||||
});
|
||||
const registry = new TestableAgentRegistry(config);
|
||||
|
||||
await registry.initialize();
|
||||
|
||||
expect(registry.getDefinition('introspection_agent')).toBeDefined();
|
||||
expect(registry.getDefinition('cli_help')).toBeDefined();
|
||||
});
|
||||
|
||||
it('should NOT register introspection agent if disabled', async () => {
|
||||
it('should NOT register CLI help agent if disabled', async () => {
|
||||
const config = makeFakeConfig({
|
||||
introspectionAgentSettings: { enabled: false },
|
||||
cliHelpAgentSettings: { enabled: false },
|
||||
});
|
||||
const registry = new TestableAgentRegistry(config);
|
||||
|
||||
await registry.initialize();
|
||||
|
||||
expect(registry.getDefinition('introspection_agent')).toBeUndefined();
|
||||
expect(registry.getDefinition('cli_help')).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import type { Config } from '../config/config.js';
|
||||
import type { AgentDefinition } from './types.js';
|
||||
import { loadAgentsFromDirectory } from './toml-loader.js';
|
||||
import { CodebaseInvestigatorAgent } from './codebase-investigator.js';
|
||||
import { IntrospectionAgent } from './introspection-agent.js';
|
||||
import { CliHelpAgent } from './cli-help-agent.js';
|
||||
import { A2AClientManager } from './a2a-client-manager.js';
|
||||
import { ADCHandler } from './remote-invocation.js';
|
||||
import { type z } from 'zod';
|
||||
@@ -106,7 +106,7 @@ export class AgentRegistry {
|
||||
|
||||
private loadBuiltInAgents(): void {
|
||||
const investigatorSettings = this.config.getCodebaseInvestigatorSettings();
|
||||
const introspectionSettings = this.config.getIntrospectionAgentSettings();
|
||||
const cliHelpSettings = this.config.getCliHelpAgentSettings();
|
||||
|
||||
// Only register the agent if it's enabled in the settings.
|
||||
if (investigatorSettings?.enabled) {
|
||||
@@ -145,9 +145,9 @@ export class AgentRegistry {
|
||||
this.registerLocalAgent(agentDef);
|
||||
}
|
||||
|
||||
// Register the introspection agent if it's explicitly enabled.
|
||||
if (introspectionSettings.enabled) {
|
||||
this.registerLocalAgent(IntrospectionAgent);
|
||||
// Register the CLI help agent if it's explicitly enabled.
|
||||
if (cliHelpSettings.enabled) {
|
||||
this.registerLocalAgent(CliHelpAgent(this.config));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -151,7 +151,7 @@ export interface ResolvedExtensionSetting {
|
||||
sensitive: boolean;
|
||||
}
|
||||
|
||||
export interface IntrospectionAgentSettings {
|
||||
export interface CliHelpAgentSettings {
|
||||
enabled?: boolean;
|
||||
}
|
||||
|
||||
@@ -333,7 +333,7 @@ export interface ConfigParameters {
|
||||
output?: OutputSettings;
|
||||
disableModelRouterForAuth?: AuthType[];
|
||||
codebaseInvestigatorSettings?: CodebaseInvestigatorSettings;
|
||||
introspectionAgentSettings?: IntrospectionAgentSettings;
|
||||
cliHelpAgentSettings?: CliHelpAgentSettings;
|
||||
continueOnFailedApiCall?: boolean;
|
||||
retryFetchErrors?: boolean;
|
||||
enableShellOutputEfficiency?: boolean;
|
||||
@@ -461,7 +461,7 @@ export class Config {
|
||||
private readonly policyEngine: PolicyEngine;
|
||||
private readonly outputSettings: OutputSettings;
|
||||
private readonly codebaseInvestigatorSettings: CodebaseInvestigatorSettings;
|
||||
private readonly introspectionAgentSettings: IntrospectionAgentSettings;
|
||||
private readonly cliHelpAgentSettings: CliHelpAgentSettings;
|
||||
private readonly continueOnFailedApiCall: boolean;
|
||||
private readonly retryFetchErrors: boolean;
|
||||
private readonly enableShellOutputEfficiency: boolean;
|
||||
@@ -621,8 +621,8 @@ export class Config {
|
||||
DEFAULT_THINKING_MODE,
|
||||
model: params.codebaseInvestigatorSettings?.model,
|
||||
};
|
||||
this.introspectionAgentSettings = {
|
||||
enabled: params.introspectionAgentSettings?.enabled ?? false,
|
||||
this.cliHelpAgentSettings = {
|
||||
enabled: params.cliHelpAgentSettings?.enabled ?? false,
|
||||
};
|
||||
this.continueOnFailedApiCall = params.continueOnFailedApiCall ?? true;
|
||||
this.enableShellOutputEfficiency =
|
||||
@@ -1682,8 +1682,8 @@ export class Config {
|
||||
return this.codebaseInvestigatorSettings;
|
||||
}
|
||||
|
||||
getIntrospectionAgentSettings(): IntrospectionAgentSettings {
|
||||
return this.introspectionAgentSettings;
|
||||
getCliHelpAgentSettings(): CliHelpAgentSettings {
|
||||
return this.cliHelpAgentSettings;
|
||||
}
|
||||
|
||||
async createToolRegistry(): Promise<ToolRegistry> {
|
||||
|
||||
@@ -36,7 +36,7 @@ export interface GetInternalDocsParams {
|
||||
*/
|
||||
async function getDocsRoot(): Promise<string> {
|
||||
const currentFile = fileURLToPath(import.meta.url);
|
||||
const currentDir = path.dirname(currentFile);
|
||||
let searchDir = path.dirname(currentFile);
|
||||
|
||||
const isDocsDir = async (dir: string) => {
|
||||
try {
|
||||
@@ -52,25 +52,17 @@ async function getDocsRoot(): Promise<string> {
|
||||
return false;
|
||||
};
|
||||
|
||||
// 1. Check for documentation in the distributed package (dist/docs)
|
||||
// Path: dist/src/tools/get-internal-docs.js -> dist/docs
|
||||
const distDocsPath = path.resolve(currentDir, '..', '..', 'docs');
|
||||
if (await isDocsDir(distDocsPath)) {
|
||||
return distDocsPath;
|
||||
}
|
||||
while (true) {
|
||||
const candidate = path.join(searchDir, 'docs');
|
||||
if (await isDocsDir(candidate)) {
|
||||
return candidate;
|
||||
}
|
||||
|
||||
// 2. Check for documentation in the repository root (development)
|
||||
// Path: packages/core/src/tools/get-internal-docs.ts -> docs/
|
||||
const repoDocsPath = path.resolve(currentDir, '..', '..', '..', '..', 'docs');
|
||||
if (await isDocsDir(repoDocsPath)) {
|
||||
return repoDocsPath;
|
||||
}
|
||||
|
||||
// 3. Check for documentation in the bundle directory (bundle/docs)
|
||||
// Path: bundle/gemini.js -> bundle/docs
|
||||
const bundleDocsPath = path.join(currentDir, 'docs');
|
||||
if (await isDocsDir(bundleDocsPath)) {
|
||||
return bundleDocsPath;
|
||||
const parent = path.dirname(searchDir);
|
||||
if (parent === searchDir) {
|
||||
break;
|
||||
}
|
||||
searchDir = parent;
|
||||
}
|
||||
|
||||
throw new Error('Could not find Gemini CLI documentation directory.');
|
||||
|
||||
Reference in New Issue
Block a user