feat(mma): Refine tier roles, tool access, and observability

This commit is contained in:
2026-02-26 08:31:19 -05:00
parent 732f3d4e13
commit 91693a5168
10 changed files with 108 additions and 78 deletions

View File

@@ -81,17 +81,33 @@ def get_role_documents(role: str) -> list[str]:
return ['conductor/workflow.md']
return []
def log_delegation(role, prompt):
def log_delegation(role, prompt, result=None):
os.makedirs('logs/agents', exist_ok=True)
timestamp = datetime.datetime.now().strftime('%Y%m%d_%H%M%S')
log_file = f'logs/agents/mma_{role}_task_{timestamp}.log'
with open(log_file, 'w', encoding='utf-8') as f:
f.write("==================================================\n")
f.write(f"ROLE: {role}\n")
f.write(f"TIMESTAMP: {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n")
f.write("--------------------------------------------------\n")
f.write(f"PROMPT:\n{prompt}\n")
f.write("--------------------------------------------------\n")
if result:
f.write(f"RESULT:\n{result}\n")
f.write("==================================================\n")
# Also keep the master log
os.makedirs(os.path.dirname(LOG_FILE), exist_ok=True)
timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
with open(LOG_FILE, 'a', encoding='utf-8') as f:
f.write("--------------------------------------------------\n")
f.write(f"TIMESTAMP: {timestamp}\n")
f.write(f"TIER: {role}\n")
f.write(f"PROMPT: {prompt}\n")
f.write("--------------------------------------------------\n")
f.write(f"[{datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}] {role}: {prompt[:100]}... (Log: {log_file})\n")
return log_file
def get_dependencies(filepath):
def execute_agent(role: str, prompt: str, docs: list[str]) -> str:
model = get_model_for_role(role)
# Advanced Context: Dependency skeletons for Tier 3
"""Identify top-level module imports from a Python file."""
try:
with open(filepath, 'r', encoding='utf-8') as f:
@@ -116,7 +132,6 @@ def get_dependencies(filepath):
return []
def execute_agent(role: str, prompt: str, docs: list[str]) -> str:
log_delegation(role, prompt)
model = get_model_for_role(role)
# Advanced Context: Dependency skeletons for Tier 3
@@ -158,16 +173,17 @@ def execute_agent(role: str, prompt: str, docs: list[str]) -> str:
# MMA Protocol: Tier 3 and 4 are stateless.
if role in ['tier3', 'tier3-worker']:
system_directive = "STRICT SYSTEM DIRECTIVE: You are a stateless Tier 3 Worker (Contributor). " \
"Your goal is to generate high-quality code or diffs based on the provided task. " \
"DO NOT USE ANY TOOLS (no write_file, no run_shell_command, etc.). " \
"ONLY output the clean code or the requested diff. No pleasantries, no conversational filler."
"Your goal is to implement specific code changes or tests based on the provided task. " \
"You have access to tools for reading and writing files. " \
"Follow TDD and return success status or code changes. No pleasantries, no conversational filler."
elif role in ['tier4', 'tier4-qa']:
system_directive = "STRICT SYSTEM DIRECTIVE: You are a stateless Tier 4 QA Agent. " \
"Your goal is to analyze errors, summarize logs, or verify tests. " \
"DO NOT USE ANY TOOLS. ONLY output the requested analysis. No pleasantries."
"You have access to tools for reading files and exploring the codebase. " \
"ONLY output the requested analysis. No pleasantries."
else:
system_directive = f"STRICT SYSTEM DIRECTIVE: You are a stateless {role}. " \
"DO NOT USE ANY TOOLS. ONLY output the requested text. No pleasantries."
"ONLY output the requested text. No pleasantries."
command_text = f"{system_directive}\n\n{injected_context}\n\n"
@@ -194,8 +210,13 @@ def execute_agent(role: str, prompt: str, docs: list[str]) -> str:
try:
process = subprocess.run(cmd, input=command_text, capture_output=True, text=True, encoding='utf-8')
result = process.stdout
if not process.stdout and process.stderr:
return f"Error: {process.stderr}"
result = f"Error: {process.stderr}"
# Log the attempt and result
log_file = log_delegation(role, command_text, result)
print(f"Sub-agent log created: {log_file}")
stdout = process.stdout
start_index = stdout.find('{')
@@ -208,7 +229,9 @@ def execute_agent(role: str, prompt: str, docs: list[str]) -> str:
return stdout
return stdout
except Exception as e:
return f"Execution failed: {str(e)}"
err_msg = f"Execution failed: {str(e)}"
log_delegation(role, command_text, err_msg)
return err_msg
def create_parser():
parser = argparse.ArgumentParser(description="MMA Execution Script")