feat(mma): Implement context injection using ASTParser in run_worker_lifecycle

This commit is contained in:
2026-02-26 20:10:15 -05:00
parent 559355ce47
commit 9d6d1746c6
2 changed files with 75 additions and 1 deletions

View File

@@ -1,5 +1,7 @@
import ai_client
from typing import List, Optional
from models import Ticket, Track, WorkerContext
from file_cache import ASTParser
class ConductorEngine:
"""
@@ -34,15 +36,35 @@ class ConductorEngine:
)
run_worker_lifecycle(ticket, context)
def run_worker_lifecycle(ticket: Ticket, context: WorkerContext):
def run_worker_lifecycle(ticket: Ticket, context: WorkerContext, context_files: List[str] = None):
"""
Simulates the lifecycle of a single agent working on a ticket.
Calls the AI client and updates the ticket status based on the response.
"""
context_injection = ""
if context_files:
parser = ASTParser(language="python")
for i, file_path in enumerate(context_files):
try:
with open(file_path, 'r', encoding='utf-8') as f:
content = f.read()
if i == 0:
view = parser.get_curated_view(content)
else:
view = parser.get_skeleton(content)
context_injection += f"\nFile: {file_path}\n{view}\n"
except Exception as e:
context_injection += f"\nError reading {file_path}: {e}\n"
# Build a prompt for the worker
user_message = (
f"You are assigned to Ticket {ticket.id}.\n"
f"Task Description: {ticket.description}\n"
)
if context_injection:
user_message += f"\nContext Files:\n{context_injection}\n"
user_message += (
"Please complete this task. If you are blocked and cannot proceed, "
"start your response with 'BLOCKED' and explain why."
)