Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does CrewAI support dynamic generation of multiple agents? #605

Open
a58982284 opened this issue May 12, 2024 · 1 comment
Open

Does CrewAI support dynamic generation of multiple agents? #605

a58982284 opened this issue May 12, 2024 · 1 comment

Comments

@a58982284
Copy link

from flask import Flask, request, jsonify
from crewai import Crew
from textwrap import dedent

from stock_analysis_agents import StockAnalysisAgents
from stock_analysis_tasks import StockAnalysisTasks

from dotenv import load_dotenv
load_dotenv()

app = Flask(__name__)

class FinancialCrew:
  def __init__(self, company):
    self.company = company

  def run(self):
    agents = StockAnalysisAgents()
    tasks = StockAnalysisTasks()

    research_analyst_agent = agents.research_analyst()
    financial_analyst_agent = agents.financial_analyst()
    investment_advisor_agent = agents.investment_advisor()

    research_task = tasks.research(research_analyst_agent, self.company)
    financial_task = tasks.financial_analysis(financial_analyst_agent)
    filings_task = tasks.filings_analysis(financial_analyst_agent)
    recommend_task = tasks.recommend(investment_advisor_agent)

    crew = Crew(
      agents=[
        research_analyst_agent,
        financial_analyst_agent,
        investment_advisor_agent
      ],
      tasks=[
        research_task,
        financial_task,
        filings_task,
        recommend_task
      ],
      verbose=True
    )

    result = crew.kickoff()
    return result

@app.route('/analyze', methods=['POST'])
def analyze():
  company = request.json.get('company')
  financial_crew = FinancialCrew(company)
  result = financial_crew.run()
  return jsonify(result)

if __name__ == "__main__":
  app.run(debug=True)

The above is a scenario example: I have encapsulated multiple agents using the Flask framework. During the running of the Flask program, if I want to dynamically add agents, such as research_analyst_agent2, financial_analyst_agent2, investment_advisor_agent2, how should I proceed?

@masonzhang
Copy link

yes, but you may need to complete the dynamic agent generation on your side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants