import evoagentx.workflow.operators as operator import examples.aflow.scicode_full.optimized.round_6.prompt as prompt_custom from evoagentx.models.model_configs import LLMConfig from evoagentx.benchmark.benchmark import Benchmark from evoagentx.models.model_utils import create_llm_instance class Workflow: def __init__( self, name: str, llm_config: LLMConfig, benchmark: Benchmark ): self.name = name self.llm = create_llm_instance(llm_config) self.benchmark = benchmark self.custom = operator.Custom(self.llm) self.custom_code_generate = operator.CustomCodeGenerate(self.llm) self.test_operator = operator.Test(self.llm) # Initialized the test operator self.sc_ensemble_operator = operator.ScEnsemble(self.llm) # Initialized ScEnsemble operator async def __call__(self, problem: str, entry_point: str): """ Implementation of the workflow Custom operator to generate multiple solutions for the problem. To get standard code, use custom_code_generate operator. """ solutions = [await self.custom_code_generate(problem=problem, entry_point=entry_point, instruction=prompt_custom.GENERATE_PYTHON_CODE_PROMPT) for _ in range(3)] solution_responses = [sol['response'] for sol in solutions] ensemble_result = await self.sc_ensemble_operator.sc_ensemble(solution_responses, problem) # Get the best solution via ensemble test_result = await self.test_operator.test(problem=problem, solution=ensemble_result['response'], entry_point=entry_point, benchmark=self.benchmark) # Testing the selected solution if not test_result['result']: # If the test fails, log the current solution and return failure indication return {"success": False, "current_solution": test_result['solution']} return {"success": True, "final_solution": ensemble_result['response']} # Return the final verified solution