【用crewai 做一个稍微复杂的用例,四个智能体协通,两个工具】

1、crewai_tools中包含很多工具插件,例如爬虫、搜索插件,而且都已经完成了
例如SerperDevTool,可以去它的官网申请key,免费


from crewai import Agent, Task, Crew  , Process
from crewai_tools import ScrapeWebsiteTool
search_tool = SerperDevTool()   
scrape_tool = ScrapeWebsiteTool()
data_analyst_agent = Agent(role="Data Analyst",       
                           goal="Monitor and analyze market data in real-time to identify trends and predict market movements.",       
                           backstory="Specializing in financial markets, this agent uses statistical modeling and machine learning to provide crucial insights.",       
                           verbose=True,       allow_delegation=True,       
                           tools=[scrape_tool, search_tool]   )

trading_strategy_agent = Agent(role="Trading Strategy Developer",       
                               goal="Develop and test various trading strategies based on insights from the Data Analyst Agent.",       
                               backstory="Equipped with a deep understanding of financial markets and quantitative analysis, this agent devises and refines trading strategies.",       
                               verbose=True,       allow_delegation=True,       
                               tools=[scrape_tool, search_tool]   )

# 交易
execution_agent = Agent(role="Trade Advisor",       
                        goal="Suggest optimal trade execution strategies based on approved trading strategies.",       
                        backstory="This agent specializes in analyzing the timing, price, and logistical details of potential trades.",       
                        verbose=True,       allow_delegation=True,       
                        tools=[scrape_tool, search_tool]   )

risk_management_agent = Agent(role="Risk Advisor",       
                              goal="Evaluate and provide insights on the risks associated with potential trading activities.",       
                              backstory="Armed with a deep understanding of risk assessment models and market dynamics, this agent scrutinizes the potential risks of proposed trades.",       
                              verbose=True,       allow_delegation=True,       
                              tools=[scrape_tool, search_tool])

data_analysis_task = Task(description=("Continuously monitor and analyze market data for the selected stock ({stock_selection}). "  
                                       "Use statistical modeling and machine learning to identify trends and predict market movements."),       
                          expected_output=("Insights and alerts about significant market opportunities or threats for {stock_selection}." ),       
                          agent=data_analyst_agent,   )

# TASK
strategy_development_task = Task(       description=("Develop and refine trading strategies based on the insights from the Data Analyst and user-defined risk tolerance ({risk_tolerance}). "           
                                                     "Consider trading preferences ({trading_strategy_preference})."       ),       
                                 expected_output=("A set of potential trading strategies for {stock_selection} that align with the user's risk tolerance."),       
                                 agent=trading_strategy_agent, )

execution_planning_task = Task(description=("Analyze approved trading strategies to determine the best execution methods for {stock_selection}, "           
                                                   "considering current market conditions and optimal pricing."),       
                               expected_output=("Detailed execution plans suggesting how and when to execute trades for {stock_selection}."),       
                               agent=execution_agent,)
risk_assessment_task = Task(description=("Evaluate the risks associated with the proposed trading strategies and execution plans for {stock_selection}. "           
                                         "Provide a detailed analysis of potential risks and suggest mitigation strategies." ),       
                            expected_output=("A comprehensive risk analysis report detailing potential risks and mitigation recommendations for {stock_selection}."),       
                            agent=risk_management_agent,   )


financial_trading_crew = Crew(agents=[ data_analyst_agent,           
                                      trading_strategy_agent,           
                                      execution_agent,           
                                      risk_management_agent ],       
                               tasks=[   data_analysis_task,           
                                            strategy_development_task,           
                                            execution_planning_task,           
                                            risk_assessment_task       ],      
#                                 manager_llm=ChatOpenAI(model="gpt-3.5-turbo", temperature=0.7), 
                                  manager_llm=llama_model,
                                process=Process.hierarchical,       
                                verbose=True   )
financial_trading_inputs = { 'stock_selection': 'AAPL',       
                            'initial_capital': '100000',       
                            'risk_tolerance': 'Medium',       
                            'trading_strategy_preference': 'Day Trading',       
                            'news_impact_consideration': True   }
result = financial_trading_crew.kickoff(inputs=financial_trading_inputs)

结果:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Ai君臣

学会的就要教给人

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值