Replies: 2 comments
-
To achieve this behavior in CrewAI, you can set up a loop within the Here's a high-level plan for how you can implement this:
Below is an example implementation in Python: Step 1: Create a function to handle user inputThis function will ask the user if they want to continue with a new task and return their response. def ask_user_to_continue():
while True:
user_input = input("Would you like to submit more papers for additional queries? (yes/no): ").strip().lower()
if user_input in ["yes", "no"]:
return user_input == "yes"
else:
print("Please enter 'yes' or 'no'.") Step 2: Initialize the crew and tasksSet up your crew and initial tasks as you normally would. Step 3: Wrap the kickoff process in a loopCreate a loop that kicks off the crew, waits for completion, and then checks if the user wants to continue. import os
from crewai import Agent, Task, Crew, Process
from crewai_tools import SerperDevTool
# Assuming you have a SerperDevTool configured
search_tool = SerperDevTool()
def create_crew_and_tasks(query):
researcher = Agent(
role='Researcher',
goal='Conduct literature review on {query}',
verbose=True,
memory=True,
backstory=(
"You are an expert in literature review, skilled at finding and synthesizing information from various sources."
),
tools=[search_tool]
)
review_task = Task(
description=(
"Perform a thorough literature review on the topic '{query}'."
"Compile the most relevant papers and provide a comprehensive report."
),
expected_output='A detailed report on the literature review for {query}.',
tools=[search_tool],
agent=researcher,
)
crew = Crew(
agents=[researcher],
tasks=[review_task],
process=Process.sequential
)
return crew
def main():
os.environ["SERPER_API_KEY"] = "Your_SerperDevTool_API_Key"
os.environ["OPENAI_API_KEY"] = "Your_OpenAI_API_Key"
while True:
query = input("Enter the query for literature review: ")
crew = create_crew_and_tasks(query)
result = crew.kickoff(inputs={'query': query})
print(result)
if not ask_user_to_continue():
print("Ending the process.")
break
if __name__ == "__main__":
main() Explanation:
|
Beta Was this translation helpful? Give feedback.
-
Thanks for responding. Where are you calling th eask_user_to_continue() function in the main file? I'm going to have to really think this out, I have several agents with many custom tools I've written. At the moment I'm using Holoviz Panel for a front end so I'm having the added complexity of passing the messages and user input back and forth via a front-end interface. I'm going to put all the crewai code behind a Flask api and write a nextjs front-end. One other thing is that crewai really needs an interactive proxy agent like Autogen. |
Beta Was this translation helpful? Give feedback.
-
How can you make a crew start a new task when the old one is completed ? I have a crew that I've built that does a research paper literature review, takes in a query, combines the papers and answers the query. When that task is completed and the report is submitted to the user by the final agent it would be great if the user were asked if they would like to submit more papers for additional queries. How do you have the crew kickoff again after its task is complete for a new task without manually ending the present run and restarting the application? Sort of how in a simple python app you can ask the user for input if they want to repeat a task or end it.
Beta Was this translation helpful? Give feedback.
All reactions