|
| 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 | +} |
0 commit comments