fix(conductor): Enforce strict statelessness and robust JSON parsing for subagents
This commit is contained in:
@@ -8,5 +8,29 @@ param(
|
||||
# Ensure the session has the API key loaded
|
||||
. C:\projects\misc\setup_gemini.ps1
|
||||
|
||||
# Piping an empty string ensures stdin is closed, forcing the Gemini CLI to terminate naturally after answering.
|
||||
echo "" | gemini $Prompt --model $Model
|
||||
# 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user