Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -78,7 +78,7 @@ class Context:
|
|
78 |
self.test_cases = test_cases
|
79 |
self.test_results = test_results
|
80 |
self.documentation = documentation
|
81 |
-
# Initialize with the user's task
|
82 |
self.conversation_history = conversation_history or [{"agent": "User", "message": original_task}]
|
83 |
|
84 |
def add_conversation_entry(self, agent_name: str, message: str):
|
@@ -119,7 +119,6 @@ class OrchestratorAgent:
|
|
119 |
)
|
120 |
plan = await call_model(prompt, model="gpt-4o", api_key=api_key)
|
121 |
context.add_conversation_entry("Orchestrator", f"Plan:\n{plan}")
|
122 |
-
# Report update after planning
|
123 |
self.log_queue.put(("update", context.conversation_history))
|
124 |
if "REQUEST_HUMAN_FEEDBACK" in plan:
|
125 |
question = plan.split("REQUEST_HUMAN_FEEDBACK\n", 1)[1].strip()
|
@@ -159,6 +158,7 @@ class CodeReviewerAgent:
|
|
159 |
)
|
160 |
review = await call_model(prompt, model="gpt-4o", api_key=api_key)
|
161 |
context.add_conversation_entry("Code Reviewer", f"Review:\n{review}")
|
|
|
162 |
if "APPROVE" not in review.upper():
|
163 |
structured_review = {"comments": []}
|
164 |
for line in review.splitlines():
|
@@ -239,7 +239,7 @@ class AgentDispatcher:
|
|
239 |
context = await self.agents[agent_name].generate_documentation(context, api_key)
|
240 |
else:
|
241 |
raise ValueError(f"Unknown agent: {agent_name}")
|
242 |
-
#
|
243 |
self.log_queue.put(("update", context.conversation_history))
|
244 |
return context
|
245 |
|
@@ -250,7 +250,9 @@ class AgentDispatcher:
|
|
250 |
return "orchestrator"
|
251 |
if not context.code:
|
252 |
return "coder"
|
253 |
-
|
|
|
|
|
254 |
return "code_reviewer"
|
255 |
if not context.test_cases:
|
256 |
return "qa_tester"
|
@@ -278,14 +280,15 @@ async def multi_agent_conversation(task_message: str, log_queue: queue.Queue, ap
|
|
278 |
context = await dispatcher.dispatch(next_agent, context, api_key, model="gpt-3.5-turbo-16k")
|
279 |
else:
|
280 |
context = await dispatcher.dispatch(next_agent, context, api_key)
|
|
|
281 |
if next_agent == "code_reviewer":
|
282 |
-
approved = any("APPROVE" in
|
283 |
-
for
|
284 |
-
|
285 |
-
if
|
286 |
-
next_agent = "coder"
|
287 |
-
else:
|
288 |
next_agent = await dispatcher.determine_next_agent(context, api_key)
|
|
|
|
|
289 |
else:
|
290 |
next_agent = await dispatcher.determine_next_agent(context, api_key)
|
291 |
if next_agent == "coder" and coder_iterations > 5:
|
@@ -298,7 +301,7 @@ def process_conversation_generator(task_message: str, api_key: str,
|
|
298 |
human_event: threading.Event, human_input_queue: queue.Queue,
|
299 |
log_queue: queue.Queue) -> Generator[Any, None, None]:
|
300 |
"""
|
301 |
-
Runs the multi-agent conversation in a background thread and yields
|
302 |
in the proper messages format.
|
303 |
"""
|
304 |
def run_conversation():
|
@@ -312,16 +315,14 @@ def process_conversation_generator(task_message: str, api_key: str,
|
|
312 |
msg = log_queue.get(timeout=0.1)
|
313 |
if isinstance(msg, tuple):
|
314 |
if msg[0] in ("update", "result"):
|
315 |
-
# Yield the updated conversation history in proper format.
|
316 |
yield gr.update(value=convert_history(msg[1]), visible=True)
|
317 |
else:
|
318 |
-
#
|
319 |
pass
|
320 |
except queue.Empty:
|
321 |
pass
|
322 |
time.sleep(0.1)
|
323 |
|
324 |
-
# Final update if needed
|
325 |
yield gr.update(visible=True)
|
326 |
|
327 |
# -------------------- Multi-Agent Chat Function --------------------
|
|
|
78 |
self.test_cases = test_cases
|
79 |
self.test_results = test_results
|
80 |
self.documentation = documentation
|
81 |
+
# Initialize with the user's task.
|
82 |
self.conversation_history = conversation_history or [{"agent": "User", "message": original_task}]
|
83 |
|
84 |
def add_conversation_entry(self, agent_name: str, message: str):
|
|
|
119 |
)
|
120 |
plan = await call_model(prompt, model="gpt-4o", api_key=api_key)
|
121 |
context.add_conversation_entry("Orchestrator", f"Plan:\n{plan}")
|
|
|
122 |
self.log_queue.put(("update", context.conversation_history))
|
123 |
if "REQUEST_HUMAN_FEEDBACK" in plan:
|
124 |
question = plan.split("REQUEST_HUMAN_FEEDBACK\n", 1)[1].strip()
|
|
|
158 |
)
|
159 |
review = await call_model(prompt, model="gpt-4o", api_key=api_key)
|
160 |
context.add_conversation_entry("Code Reviewer", f"Review:\n{review}")
|
161 |
+
# If review is not "APPROVE", store the review comments.
|
162 |
if "APPROVE" not in review.upper():
|
163 |
structured_review = {"comments": []}
|
164 |
for line in review.splitlines():
|
|
|
239 |
context = await self.agents[agent_name].generate_documentation(context, api_key)
|
240 |
else:
|
241 |
raise ValueError(f"Unknown agent: {agent_name}")
|
242 |
+
# Push an update with the current conversation history.
|
243 |
self.log_queue.put(("update", context.conversation_history))
|
244 |
return context
|
245 |
|
|
|
250 |
return "orchestrator"
|
251 |
if not context.code:
|
252 |
return "coder"
|
253 |
+
# Instead of checking review_comments (which may be empty if reviewer approved),
|
254 |
+
# check the conversation history for a Code Reviewer entry containing "APPROVE".
|
255 |
+
if not any("APPROVE" in entry["message"].upper() for entry in context.conversation_history if entry["agent"].lower() == "code reviewer"):
|
256 |
return "code_reviewer"
|
257 |
if not context.test_cases:
|
258 |
return "qa_tester"
|
|
|
280 |
context = await dispatcher.dispatch(next_agent, context, api_key, model="gpt-3.5-turbo-16k")
|
281 |
else:
|
282 |
context = await dispatcher.dispatch(next_agent, context, api_key)
|
283 |
+
# Check approval by scanning the conversation history for a Code Reviewer entry that includes "APPROVE"
|
284 |
if next_agent == "code_reviewer":
|
285 |
+
approved = any("APPROVE" in entry["message"].upper()
|
286 |
+
for entry in context.conversation_history
|
287 |
+
if entry["agent"].lower() == "code reviewer")
|
288 |
+
if approved:
|
|
|
|
|
289 |
next_agent = await dispatcher.determine_next_agent(context, api_key)
|
290 |
+
else:
|
291 |
+
next_agent = "coder"
|
292 |
else:
|
293 |
next_agent = await dispatcher.determine_next_agent(context, api_key)
|
294 |
if next_agent == "coder" and coder_iterations > 5:
|
|
|
301 |
human_event: threading.Event, human_input_queue: queue.Queue,
|
302 |
log_queue: queue.Queue) -> Generator[Any, None, None]:
|
303 |
"""
|
304 |
+
Runs the multi-agent conversation in a background thread and yields conversation history updates
|
305 |
in the proper messages format.
|
306 |
"""
|
307 |
def run_conversation():
|
|
|
315 |
msg = log_queue.get(timeout=0.1)
|
316 |
if isinstance(msg, tuple):
|
317 |
if msg[0] in ("update", "result"):
|
|
|
318 |
yield gr.update(value=convert_history(msg[1]), visible=True)
|
319 |
else:
|
320 |
+
# Optionally handle log messages here.
|
321 |
pass
|
322 |
except queue.Empty:
|
323 |
pass
|
324 |
time.sleep(0.1)
|
325 |
|
|
|
326 |
yield gr.update(visible=True)
|
327 |
|
328 |
# -------------------- Multi-Agent Chat Function --------------------
|