Skip to content

Commit 847a54e

Browse files
author
Eva
committed
feat(google): add Gemini execution guidance via prompt overlay
Ported from Hermes Agent's GOOGLE_MODEL_OPERATIONAL_GUIDANCE (prompt_builder.py lines 258-276) with Hermes-verbatim text (only mechanical tool-ID substitutions and one documented deviation: "Absolute paths" bullet omitted due to sandbox path conflict at src/agents/system-prompt.ts:600). Changes: - New: extensions/google/prompt-overlay.ts with Gemini operational directives (verify first, dependency checks, parallel calls, non-interactive commands, keep going) - Wire resolveSystemPromptContribution into both google and google-gemini-cli providers (rebased on 356110c's provider-hooks refactor) - Add tool_enforcement section ID and rendering (shared with PR 1) Part of GPT 5.4 Enhancement v3 sprint. Tracking: #66345. Supersedes: #66379.
1 parent 405c63f commit 847a54e

5 files changed

Lines changed: 65 additions & 1 deletion

File tree

extensions/google/gemini-cli-provider.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { buildOauthProviderAuthResult } from "openclaw/plugin-sdk/provider-auth-
77
import { buildProviderToolCompatFamilyHooks } from "openclaw/plugin-sdk/provider-tools";
88
import { fetchGeminiUsage } from "openclaw/plugin-sdk/provider-usage";
99
import { formatGoogleOauthApiKey, parseGoogleUsageToken } from "./oauth-token-shared.js";
10+
import { resolveGoogleSystemPromptContribution } from "./prompt-overlay.js";
1011
import { GOOGLE_GEMINI_PROVIDER_HOOKS } from "./provider-hooks.js";
1112
import { isModernGoogleModel, resolveGoogleGeminiForwardCompatModel } from "./provider-models.js";
1213

@@ -116,6 +117,11 @@ export function registerGoogleGeminiCliProvider(api: OpenClawPluginApi) {
116117
}),
117118
...GOOGLE_GEMINI_CLI_PROVIDER_HOOKS,
118119
isModernModelRef: ({ modelId }) => isModernGoogleModel(modelId),
120+
resolveSystemPromptContribution: (ctx) =>
121+
resolveGoogleSystemPromptContribution({
122+
modelProviderId: PROVIDER_ID,
123+
modelId: ctx.modelId,
124+
}),
119125
formatApiKey: (cred) => formatGoogleOauthApiKey(cred),
120126
resolveUsageAuth: async (ctx) => {
121127
const auth = await ctx.resolveOAuthToken();
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/text-runtime";
2+
3+
const GOOGLE_PROVIDER_IDS = new Set(["google", "google-vertex", "google-antigravity", "google-gemini-cli"]);
4+
5+
// Ported from Hermes Agent's GOOGLE_MODEL_OPERATIONAL_GUIDANCE
6+
// (agent/prompt_builder.py lines 258-276).
7+
//
8+
// Deviation from Hermes: the "Absolute paths" bullet is omitted because
9+
// OpenClaw runs exec inside a sandbox container whose workdir differs from
10+
// the host workspace. The core system prompt at src/agents/system-prompt.ts
11+
// explicitly tells the model to prefer relative paths so both sandboxed exec
12+
// and file tools work consistently.
13+
//
14+
// Tool ID substitutions: read_file/search_files -> read or exec
15+
export const GOOGLE_GEMINI_EXECUTION_GUIDANCE = `# Google model operational directives
16+
Follow these operational rules strictly:
17+
- **Verify first:** Use read or exec to check file contents and project structure before making changes. Never guess at file contents.
18+
- **Dependency checks:** Never assume a library is available. Check package.json, requirements.txt, Cargo.toml, etc. before importing.
19+
- **Conciseness:** Keep explanatory text brief — a few sentences, not paragraphs. Focus on actions and results over narration.
20+
- **Parallel tool calls:** When you need to perform multiple independent operations (e.g. reading several files), make all the tool calls in a single response rather than sequentially.
21+
- **Non-interactive commands:** Use flags like -y, --yes, --non-interactive to prevent CLI tools from hanging on prompts.
22+
- **Keep going:** Work autonomously until the task is fully resolved. Don't stop with a plan — execute it.
23+
`;
24+
25+
export function shouldApplyGooglePromptOverlay(params: {
26+
modelProviderId?: string;
27+
}): boolean {
28+
return GOOGLE_PROVIDER_IDS.has(normalizeLowercaseStringOrEmpty(params.modelProviderId ?? ""));
29+
}
30+
31+
/**
32+
* Returns a system prompt contribution for Google/Gemini models.
33+
* Uses inline return type to respect extension boundary (no src/ imports).
34+
*/
35+
export function resolveGoogleSystemPromptContribution(params: {
36+
modelProviderId?: string;
37+
modelId?: string;
38+
}): { sectionOverrides: Record<string, string> } | undefined {
39+
if (!shouldApplyGooglePromptOverlay({ modelProviderId: params.modelProviderId })) {
40+
return undefined;
41+
}
42+
return {
43+
sectionOverrides: {
44+
tool_enforcement: GOOGLE_GEMINI_EXECUTION_GUIDANCE,
45+
},
46+
};
47+
}

extensions/google/provider-registration.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
normalizeGoogleModelId,
88
resolveGoogleGenerativeAiTransport,
99
} from "./api.js";
10+
import { resolveGoogleSystemPromptContribution } from "./prompt-overlay.js";
1011
import { GOOGLE_GEMINI_PROVIDER_HOOKS } from "./provider-hooks.js";
1112
import { isModernGoogleModel, resolveGoogleGeminiForwardCompatModel } from "./provider-models.js";
1213

@@ -50,5 +51,10 @@ export function registerGoogleProvider(api: OpenClawPluginApi) {
5051
}),
5152
...GOOGLE_GEMINI_PROVIDER_HOOKS,
5253
isModernModelRef: ({ modelId }) => isModernGoogleModel(modelId),
54+
resolveSystemPromptContribution: (ctx) =>
55+
resolveGoogleSystemPromptContribution({
56+
modelProviderId: "google",
57+
modelId: ctx.modelId,
58+
}),
5359
});
5460
}

src/agents/system-prompt-contribution.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
export type ProviderSystemPromptSectionId =
22
| "interaction_style"
33
| "tool_call_style"
4-
| "execution_bias";
4+
| "execution_bias"
5+
| "tool_enforcement";
56

67
export type ProviderSystemPromptContribution = {
78
/**

src/agents/system-prompt.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,10 @@ export function buildAgentSystemPrompt(params: {
696696
isMinimal,
697697
}),
698698
}),
699+
...buildOverridablePromptSection({
700+
override: providerSectionOverrides.tool_enforcement,
701+
fallback: [],
702+
}),
699703
...buildOverridablePromptSection({
700704
override: providerStablePrefix,
701705
fallback: [],

0 commit comments

Comments
 (0)