nananie143 commited on
Commit
49575a4
·
1 Parent(s): 59a4304

Added comprehensive prompt generation with role-specific templates

Browse files
Files changed (1) hide show
  1. app.py +171 -0
app.py CHANGED
@@ -758,11 +758,182 @@ class EnhancedAIFlow(AIFlow):
758
  self.flow_graph = nx.DiGraph()
759
  self.contexts: Dict[AgentRole, AgentContext] = {}
760
  self.global_context = {}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
761
 
762
  async def execute_flow(self, requirements: str) -> str:
763
  """Execute the AI Flow and build the project."""
764
  try:
765
  # Initialize flow with requirements
 
766
  self.initialize_flow()
767
 
768
  # Extract app name
 
758
  self.flow_graph = nx.DiGraph()
759
  self.contexts: Dict[AgentRole, AgentContext] = {}
760
  self.global_context = {}
761
+ self.requirements = ""
762
+
763
+ def initialize_flow(self):
764
+ """Initialize the AI Flow with agent relationships and dependencies."""
765
+ # Create nodes for each agent role
766
+ for role in AgentRole:
767
+ self.flow_graph.add_node(role)
768
+ self.contexts[role] = AgentContext(
769
+ role=role,
770
+ state=FlowState.PENDING,
771
+ artifacts={},
772
+ dependencies=[],
773
+ feedback=[]
774
+ )
775
+
776
+ # Define dependencies
777
+ dependencies = {
778
+ AgentRole.UI_DESIGNER: [AgentRole.ARCHITECT],
779
+ AgentRole.BACKEND_DEVELOPER: [AgentRole.ARCHITECT],
780
+ AgentRole.DATABASE_ENGINEER: [AgentRole.ARCHITECT, AgentRole.BACKEND_DEVELOPER],
781
+ AgentRole.SECURITY_EXPERT: [AgentRole.ARCHITECT, AgentRole.BACKEND_DEVELOPER],
782
+ AgentRole.QA_ENGINEER: [AgentRole.UI_DESIGNER, AgentRole.BACKEND_DEVELOPER],
783
+ AgentRole.DEVOPS_ENGINEER: [AgentRole.BACKEND_DEVELOPER, AgentRole.DATABASE_ENGINEER],
784
+ AgentRole.DOCUMENTATION_WRITER: [AgentRole.ARCHITECT, AgentRole.UI_DESIGNER, AgentRole.BACKEND_DEVELOPER]
785
+ }
786
+
787
+ # Add edges based on dependencies
788
+ for role, deps in dependencies.items():
789
+ for dep in deps:
790
+ self.flow_graph.add_edge(dep, role)
791
+ self.contexts[role].dependencies.extend(deps)
792
+
793
+ def _generate_prompt(self, role: AgentRole) -> str:
794
+ """Generate a prompt for an agent based on context and dependencies."""
795
+ try:
796
+ context = self.contexts[role]
797
+ dependencies_output = []
798
+
799
+ # Gather outputs from dependencies
800
+ for dep_role in context.dependencies:
801
+ dep_context = self.contexts[dep_role]
802
+ if dep_context.state == FlowState.COMPLETED and "output" in dep_context.artifacts:
803
+ dependencies_output.append(f"## {dep_role.value} Output:\n{dep_context.artifacts['output']}")
804
+
805
+ # Build role-specific prompts
806
+ role_prompts = {
807
+ AgentRole.ARCHITECT: """You are a Software Architect. Design the high-level architecture for:
808
+ Requirements:
809
+ {requirements}
810
+
811
+ Focus on:
812
+ 1. Overall system design
813
+ 2. Component interactions
814
+ 3. Technology stack
815
+ 4. Data flow
816
+ 5. Scalability considerations""",
817
+
818
+ AgentRole.UI_DESIGNER: """You are a UI/UX Designer. Design the user interface for:
819
+ Requirements:
820
+ {requirements}
821
+
822
+ Previous Designs:
823
+ {dependencies}
824
+
825
+ Focus on:
826
+ 1. User experience
827
+ 2. Component layout
828
+ 3. Responsive design
829
+ 4. Visual hierarchy
830
+ 5. Accessibility""",
831
+
832
+ AgentRole.BACKEND_DEVELOPER: """You are a Backend Developer. Implement the server-side logic for:
833
+ Requirements:
834
+ {requirements}
835
+
836
+ Architecture:
837
+ {dependencies}
838
+
839
+ Focus on:
840
+ 1. API design
841
+ 2. Business logic
842
+ 3. Data validation
843
+ 4. Error handling
844
+ 5. Performance""",
845
+
846
+ AgentRole.DATABASE_ENGINEER: """You are a Database Engineer. Design the data layer for:
847
+ Requirements:
848
+ {requirements}
849
+
850
+ System Context:
851
+ {dependencies}
852
+
853
+ Focus on:
854
+ 1. Schema design
855
+ 2. Data relationships
856
+ 3. Indexing strategy
857
+ 4. Query optimization
858
+ 5. Data integrity""",
859
+
860
+ AgentRole.SECURITY_EXPERT: """You are a Security Expert. Review and enhance security for:
861
+ Requirements:
862
+ {requirements}
863
+
864
+ System Context:
865
+ {dependencies}
866
+
867
+ Focus on:
868
+ 1. Authentication
869
+ 2. Authorization
870
+ 3. Data protection
871
+ 4. Security best practices
872
+ 5. Compliance requirements""",
873
+
874
+ AgentRole.QA_ENGINEER: """You are a QA Engineer. Design the testing strategy for:
875
+ Requirements:
876
+ {requirements}
877
+
878
+ Implementation Details:
879
+ {dependencies}
880
+
881
+ Focus on:
882
+ 1. Test coverage
883
+ 2. Test automation
884
+ 3. Edge cases
885
+ 4. Performance testing
886
+ 5. Security testing""",
887
+
888
+ AgentRole.DEVOPS_ENGINEER: """You are a DevOps Engineer. Set up the deployment pipeline for:
889
+ Requirements:
890
+ {requirements}
891
+
892
+ System Context:
893
+ {dependencies}
894
+
895
+ Focus on:
896
+ 1. CI/CD pipeline
897
+ 2. Infrastructure as code
898
+ 3. Monitoring
899
+ 4. Scaling
900
+ 5. Disaster recovery""",
901
+
902
+ AgentRole.DOCUMENTATION_WRITER: """You are a Technical Writer. Create comprehensive documentation for:
903
+ Requirements:
904
+ {requirements}
905
+
906
+ System Details:
907
+ {dependencies}
908
+
909
+ Focus on:
910
+ 1. Setup instructions
911
+ 2. API documentation
912
+ 3. User guides
913
+ 4. Architecture overview
914
+ 5. Troubleshooting guides"""
915
+ }
916
+
917
+ # Get the base prompt for the role
918
+ base_prompt = role_prompts.get(role, "")
919
+
920
+ # Format the prompt with requirements and dependencies
921
+ formatted_prompt = base_prompt.format(
922
+ requirements=self.requirements,
923
+ dependencies="\n\n".join(dependencies_output) if dependencies_output else "No previous context available."
924
+ )
925
+
926
+ return formatted_prompt
927
+
928
+ except Exception as e:
929
+ logger.error(f"Failed to generate prompt for {role}: {str(e)}")
930
+ raise
931
 
932
  async def execute_flow(self, requirements: str) -> str:
933
  """Execute the AI Flow and build the project."""
934
  try:
935
  # Initialize flow with requirements
936
+ self.requirements = requirements
937
  self.initialize_flow()
938
 
939
  # Extract app name