param( [Parameter(Mandatory=$true)] [string]$Prompt, [string]$Model = "gemini-3-flash-preview" ) # Ensure the session has the API key loaded . C:\projects\misc\setup_gemini.ps1 # Prepend a strict system instruction to the prompt to prevent the model from entering a tool-usage loop $SafePrompt = "STRICT SYSTEM DIRECTIVE: You are a stateless utility function. DO NOT USE ANY TOOLS (no write_file, no run_shell_command, etc.). ONLY output the exact requested text, code, or JSON.`n`nUSER PROMPT:`n$Prompt" # Execute headless Gemini using -p, suppressing stderr noise $jsonOutput = gemini -p $SafePrompt --model $Model --output-format json 2>$null try { # Extract only the JSON part $fullString = $jsonOutput -join "`n" $jsonStartIndex = $fullString.IndexOf("{") if ($jsonStartIndex -ge 0) { $cleanJsonString = $fullString.Substring($jsonStartIndex) $parsed = $cleanJsonString | ConvertFrom-Json # Output only the clean response text Write-Output $parsed.response } else { Write-Warning "No JSON object found in output." Write-Output $fullString } } catch { # Fallback if parsing fails Write-Warning "Failed to parse JSON from sub-agent. Raw output:" Write-Output $jsonOutput }