Spaces:
Sleeping
Sleeping
Update app.py
Browse files77 unmodified lines787980818182838434 unmodified lines11912012112212212312433 unmodified lines15815916016116216316474 unmodified lines2392402412422422432442454 unmodified lines25025125225325325425525625725821 unmodified lines2802812822832842822832842852862872852862872882892902912922932946 unmodified lines3013023033013043053063077 unmodified lines31531631731531831931832032132232332432532432632732877 unmodified lines self.test_cases = test_cases self.test_results = test_results self.documentation = documentation # Initialize with the user's task # Initialize with the user's task. self.conversation_history = conversation_history or [{"agent": "User", "message": original_task}]
def add_conversation_entry(self, agent_name: str, message: str):34 unmodified lines ) plan = await call_model(prompt, model="gpt-4o", api_key=api_key) context.add_conversation_entry("Orchestrator", f"Plan:\n{plan}") # Report update after planning self.log_queue.put(("update", context.conversation_history)) if "REQUEST_HUMAN_FEEDBACK" in plan: question = plan.split("REQUEST_HUMAN_FEEDBACK\n", 1)[1].strip()33 unmodified lines ) review = await call_model(prompt, model="gpt-4o", api_key=api_key) context.add_conversation_entry("Code Reviewer", f"Review:\n{review}") # If review is not "APPROVE", store the review comments. if "APPROVE" not in review.upper(): structured_review = {"comments": []} for line in review.splitlines():74 unmodified lines context = await self.agents[agent_name].generate_documentation(context, api_key) else: raise ValueError(f"Unknown agent: {agent_name}") # After each dispatch, push an update with the current conversation history. # Push an update with the current conversation history. self.log_queue.put(("update", context.conversation_history)) return context
4 unmodified lines return "orchestrator" if not context.code: return "coder" if not any("APPROVE" in comment.get("issue", "").upper() for review in context.review_comments for comment in review.get("comments", [])): # Instead of checking review_comments (which may be empty if reviewer approved), # check the conversation history for a Code Reviewer entry containing "APPROVE". if not any("APPROVE" in entry["message"].upper() for entry in context.conversation_history if entry["agent"].lower() == "code reviewer"): return "code_reviewer" if not context.test_cases: return "qa_tester"21 unmodified lines context = await dispatcher.dispatch(next_agent, context, api_key, model="gpt-3.5-turbo-16k") else: context = await dispatcher.dispatch(next_agent, context, api_key) # Check approval by scanning the conversation history for a Code Reviewer entry that includes "APPROVE" if next_agent == "code_reviewer": approved = any("APPROVE" in comment.get("issue", "").upper() for review in context.review_comments for comment in review.get("comments", [])) if not approved: next_agent = "coder" else: approved = any("APPROVE" in entry["message"].upper() for entry in context.conversation_history if entry["agent"].lower() == "code reviewer") if approved: next_agent = await dispatcher.determine_next_agent(context, api_key) else: next_agent = "coder" else: next_agent = await dispatcher.determine_next_agent(context, api_key) if next_agent == "coder" and coder_iterations > 5:6 unmodified lines human_event: threading.Event, human_input_queue: queue.Queue, log_queue: queue.Queue) -> Generator[Any, None, None]: """ Runs the multi-agent conversation in a background thread and yields only conversation history updates Runs the multi-agent conversation in a background thread and yields conversation history updates in the proper messages format. """ def run_conversation():7 unmodified lines msg = log_queue.get(timeout=0.1) if isinstance(msg, tuple): if msg[0] in ("update", "result"): # Yield the updated conversation history in proper format. yield gr.update(value=convert_history(msg[1]), visible=True) else: # Log messages can be printed or handled here if needed. # Optionally handle log messages here. pass except queue.Empty: pass time.sleep(0.1) # Final update if needed yield gr.update(visible=True)
# -------------------- Multi-Agent Chat Function --------------------app.py+15-14