fix(mma): Use headless execution flag for context amnesia and parse json output
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import json
|
||||||
|
|
||||||
def get_role_documents(role: str) -> list[str]:
|
def get_role_documents(role: str) -> list[str]:
|
||||||
if role == 'tier1':
|
if role == 'tier1':
|
||||||
@@ -15,9 +16,24 @@ def execute_agent(role: str, prompt: str, docs: list[str]) -> str:
|
|||||||
for doc in docs:
|
for doc in docs:
|
||||||
command_text += f" @{doc}"
|
command_text += f" @{doc}"
|
||||||
|
|
||||||
cmd = ["gemini", command_text]
|
cmd = ['gemini', '-p', command_text, '--output-format', 'json', '--model', 'gemini-2.5-flash-lite']
|
||||||
process = subprocess.run(cmd, capture_output=True, text=True)
|
try:
|
||||||
return process.stdout
|
process = subprocess.run(cmd, capture_output=True, text=True, shell=True)
|
||||||
|
if not process.stdout and process.stderr:
|
||||||
|
return f"Error: {process.stderr}"
|
||||||
|
|
||||||
|
stdout = process.stdout
|
||||||
|
start_index = stdout.find('{')
|
||||||
|
if start_index != -1:
|
||||||
|
json_str = stdout[start_index:]
|
||||||
|
try:
|
||||||
|
data = json.loads(json_str)
|
||||||
|
return data.get('response', stdout)
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
return stdout
|
||||||
|
return stdout
|
||||||
|
except Exception as e:
|
||||||
|
return f"Execution failed: {str(e)}"
|
||||||
|
|
||||||
def create_parser():
|
def create_parser():
|
||||||
parser = argparse.ArgumentParser(description="MMA Execution Script")
|
parser = argparse.ArgumentParser(description="MMA Execution Script")
|
||||||
|
|||||||
@@ -64,7 +64,8 @@ def test_execute_agent():
|
|||||||
cmd_list = args[0]
|
cmd_list = args[0]
|
||||||
|
|
||||||
assert cmd_list[0] == "gemini"
|
assert cmd_list[0] == "gemini"
|
||||||
assert cmd_list[1] == expected_gemini_arg
|
assert cmd_list[1] == "-p"
|
||||||
|
assert cmd_list[2] == expected_gemini_arg
|
||||||
assert kwargs.get("capture_output") is True
|
assert kwargs.get("capture_output") is True
|
||||||
assert kwargs.get("text") is True
|
assert kwargs.get("text") is True
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user