import os from crewai import Agent, Task, Crew, Process from langchain.tools import DuckDuckGoSearchRun from langchain.agents import Tool import gradio as gr # Initialize CoinGecko API for cryptocurrency data duckduckgo_search_tool = DuckDuckGoSearchRun() ################################## - GOOGLE LLM - ################################## from langchain_google_genai import ChatGoogleGenerativeAI api_gemini = os.environ["api_gemini"] llm = ChatGoogleGenerativeAI(model="gemini-pro", verbose=True, temperature=0.1, google_api_key=api_gemini) ################################## - GOOGLE LLM - ################################## ##################################### DDG Crypto Search ###################################### from langchain.tools import DuckDuckGoSearchRun from langchain.agents import Tool # Define wrapper functions for specific searches ddg_search = DuckDuckGoSearchRun() def coingecko_search_wrapper(input_text): return ddg_search.run(f"site:coingecko.com {input_text}") def coinmarketcap_search_wrapper(input_text): return ddg_search.run(f"site:coinmarketcap.com {input_text}") def general_search_wrapper(input_text): return ddg_search.run(f'cryptocurrency {input_text}') # Initialize tools with specific functions GeneralSearch = Tool( name="GeneralSearch", func=general_search_wrapper, description="General search for cryptocurrencies" ) CoinGeckoSearch = Tool( name="CoingeckoSearch", func=coingecko_search_wrapper, description="Searches on Coingecko" ) CoinMarketCapSearch = Tool( name="CoinmarketcapSearch", func=coinmarketcap_search_wrapper, description="Searches on CoinMarketCap" ) ##################################### DDG Crypto Search ###################################### def create_crewai_crypto_setup(crypto_symbol): # Main Research Agent for technical and market analysis research_agent = Agent( role="Crypto Analysis Expert", goal=f"Perform in-depth analysis on {crypto_symbol}, focusing on technical indicators, market trends, and recent news.", backstory="Expert in technical analysis and market sentiment for cryptocurrencies, capable of identifying investment opportunities and risks.", verbose=True, max_iter=40, allow_delegation=False, tools=[duckduckgo_search_tool, CoinGeckoSearch, CoinMarketCapSearch], llm=llm, ) # Agent for compiling analysis into an investment strategy report report_formatting_agent = Agent( role="Strategy Report Creator", goal="Synthesize analysis into a clear, actionable investment strategy report.", backstory="Specializes in creating detailed investment strategies based on comprehensive market and technical analysis.", verbose=True, allow_delegation=True, max_iter=30, llm=llm, ) # Market Trends and Price History Analysis MarketTrends_T1 = Task( description=f"Examine cryptocurrency coin - {crypto_symbol} price history to identify current market trends and potential future movements.", expected_output="Summary of market trends and historical price analysis, list of key datapoints including price outlook short, medium, longterm", async_execution=True, agent=research_agent, ) # Technical Analysis with Key Indicators TechnicalAnalysis_T2 = Task( description=f"Apply technical analysis on the cryptocurrency {crypto_symbol}, focusing on RSI, MACD, support/resistance levels, and other relevant indicators.", expected_output="Technical analysis summary with key indicator findings, techincal setups, and numerical datapoints", async_execution=True, agent=research_agent, ) # Sentiment and News Analysis SentimentNews_T3 = Task( description=f"Gather and analyze recent news and community sentiment regarding cryptocurrency - {crypto_symbol} to gauge market sentiment.", expected_output="Summary of recent developments, news impact, and community sentiment", async_execution=True, agent=research_agent, ) # Investment Opportunities and Risks Identification OpportunitiesRisks_T4 = Task( description=f"Identify and evaluate potential investment opportunities and risks associated with cryptocurrency - {crypto_symbol}.", expected_output="List of investment opportunities and risks", async_execution=True, agent=research_agent, ) # Comprehensive Investment Strategy Report StrategyReport_T5 = Task( description=f"""Create a detailed investment plan for the cryptocurrency - {crypto_symbol}, incorporating price targets, technical analysis, investment strategies, and timelines. Ensure the plan includes actionable advice on when to buy, sell, and hold, along with risk management strategies. """, expected_output="""Sectioned report that focuses on breif bullet points and notes and key data points, Investment strategy report with actionable insights and strategies NOTES: The report is for advanced cryptocurrency experts. Do note include disclaimers or warnings Remove uneeded words make it concise. Final output needs to be strictly 2000 characters or less. I will tip you 10,000 dollars if you report great.""", context=[MarketTrends_T1,TechnicalAnalysis_T2,SentimentNews_T3,OpportunitiesRisks_T4], agent=report_formatting_agent, ) # Crew setup for processing the tasks sequentially crypto_crew = Crew( agents=[research_agent, report_formatting_agent], tasks=[MarketTrends_T1, TechnicalAnalysis_T2, SentimentNews_T3, OpportunitiesRisks_T4, StrategyReport_T5], verbose=2, process=Process.sequential, ) crew_result = crypto_crew.kickoff() return crew_result # Gradio Interface setup def run_crewai_crypto_app(crypto_symbol): crew_result = create_crewai_crypto_setup(crypto_symbol) return crew_result iface = gr.Interface( fn=run_crewai_crypto_app, inputs="text", outputs="text", title="CryptoScout - CrewAI - Cryptocurrency Investment Advisor", description="Enter a cryptocurrency symbol to analyze and generate a comprehensive investment plan." ) iface.launch()