Spaces:
Build error
Build error
Update app.py
Browse files282 unmodified lines283284285286287288176 unmodified lines465466467468469470471472473474475476282 unmodified linesself.experience_buffer = []self.performance_history = {}class DynamicLLM:_instance = None_model = None176 unmodified linesself.current_task = querystart_time = datetime.now()boss_response = self.llm.generate_response(prompt=self._create_boss_prompt(query),role="boss",context={"task_history": self.g_designer.experience_buffer})results = []for idx, agent in enumerate(agent_specs):agent_role = f"agent{idx+1}"282 unmodified lines283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411176 unmodified lines588589590591592593594595596597598599600601602603604282 unmodified linesself.experience_buffer = []self.performance_history = {}def _create_boss_prompt(self, query: str) -> str:"""Creates a structured prompt for the boss agent to interpret tasks and define specialized agents.Args:query (str): The user's input query/task descriptionReturns:str: A formatted prompt for the boss agent"""# Get historical performance if availabletask_history = self.g_designer.experience_buffer[-5:] if self.g_designer.experience_buffer else []historical_insights = "\n".join([f"- Previous task: {exp['task']}, Success: {exp['success']}, Time: {exp['execution_time']:.1f}s"for exp in task_history])boss_prompt = f"""You are the Boss AI responsible for managing a team of AI agents to solve complex tasks.CURRENT TASK: {query}HISTORICAL CONTEXT:{historical_insights if task_history else 'No previous task history available.'}YOUR RESPONSIBILITIES:1. Analyze the given task thoroughly2. Define exactly 3 specialized AI agents that would be best suited for solving this task3. Ensure the agents have complementary skills and clear responsibilities4. Consider any insights from previous similar tasks5. Provide structured response in the required formatRemember:- A dedicated summarizer agent will be added automatically- Focus on creating agents with distinct, complementary roles- Consider both general capabilities and specialized knowledge needed- Agents should collaborate effectively to solve the taskPlease provide your response in the following format:TASK ANALYSIS:[Provide a brief analysis of the task's requirements and complexity]AGENT SPECIFICATIONS:1. [Role1]Primary Function: [Main responsibility]Specialty: [Key areas of expertise]Plugins: [Relevant tools/capabilities]Reasoning: [Why this agent is needed]2. [Role2]Primary Function: [Main responsibility]Specialty: [Key areas of expertise]Plugins: [Relevant tools/capabilities]Reasoning: [Why this agent is needed]3. [Role3]Primary Function: [Main responsibility]Specialty: [Key areas of expertise]Plugins: [Relevant tools/capabilities]Reasoning: [Why this agent is needed]COLLABORATION STRATEGY:[Brief description of how these agents should work together]EXECUTION PLAN:Recommended Rounds: [Number between 1-8]Rationale: [Brief explanation for the number of rounds]Based on your analysis, provide the complete response following this format."""return boss_promptdef _parse_boss_response(self, response: str) -> Tuple[List[Dict], int]:"""Parses the boss's response to extract agent specifications and round count.Args:response (str): The boss agent's formatted responseReturns:Tuple[List[Dict], int]: A tuple containing the list of agent specifications and recommended rounds"""try:# Extract agent specificationsagent_specs = []agent_sections = response.split('\n\n')for section in agent_sections:if 'Primary Function:' in section:lines = section.strip().split('\n')role = lines[0].strip().replace('1.', '').replace('2.', '').replace('3.', '').strip()plugins = [p.strip() for p innext(l for l in lines if 'Plugins:' in l).replace('Plugins:', '').strip().split(',')]agent_specs.append({"role": role,"base": self.llm.model_name,"plugins": plugins})# Extract recommended roundsrounds_match = re.search(r'Recommended Rounds:\s*(\d+)', response)rounds = min(max(int(rounds_match.group(1)) if rounds_match else 3, 1), 8)# Ensure exactly 3 agentsif len(agent_specs) != 3:raise ValueError("Boss must specify exactly 3 agents")return agent_specs, roundsexcept Exception as e:print(f"Error parsing boss response: {str(e)}")# Return default specifications if parsing failsreturn [{"base": self.llm.model_name, "role": "Analyst", "plugins": ["analysis"]},{"base": self.llm.model_name, "role": "Expert", "plugins": ["domain"]},{"base": self.llm.model_name, "role": "Critic", "plugins": ["evaluation"]}], 3class DynamicLLM:_instance = None_model = None176 unmodified linesself.current_task = querystart_time = datetime.now()boss_response = self.llm.generate_response(prompt=self._create_boss_prompt(query),role="boss",context={"task_history": self.g_designer.experience_buffer})#agent_specs, rounds = self._parse_boss_response(boss_response)# Use agent_specs instead of the input agent_specs parameter# Use rounds instead of initial_rounds parameter#Has the Boss LLM chose the amount of rounds and learn the minimum amount of rounds needed for an answer instead of it being preset which is how it is currently set-up.results = []for idx, agent in enumerate(agent_specs):agent_role = f"agent{idx+1}"
app.py+130-2