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 subprocess
|
||||
import json
|
||||
|
||||
def get_role_documents(role: str) -> list[str]:
|
||||
if role == 'tier1':
|
||||
@@ -15,9 +16,24 @@ def execute_agent(role: str, prompt: str, docs: list[str]) -> str:
|
||||
for doc in docs:
|
||||
command_text += f" @{doc}"
|
||||
|
||||
cmd = ["gemini", command_text]
|
||||
process = subprocess.run(cmd, capture_output=True, text=True)
|
||||
return process.stdout
|
||||
cmd = ['gemini', '-p', command_text, '--output-format', 'json', '--model', 'gemini-2.5-flash-lite']
|
||||
try:
|
||||
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():
|
||||
parser = argparse.ArgumentParser(description="MMA Execution Script")
|
||||
|
||||
Reference in New Issue
Block a user