crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

'NoneType' object has no attribute 'allow_delegation'

Open dwk601 opened this issue 1 year ago • 2 comments

import os
from dotenv import load_dotenv
from crewai import Agent, Task, Process, Crew
from langchain.agents import load_tools
from langchain.agents import Tool
from langchain.chat_models import ChatOpenAI
from langchain.utilities import GoogleSerperAPIWrapper

load_dotenv()
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
SERPER_API_KEY = os.getenv("SERPER_API_KEY")

llm = ChatOpenAI(model="gpt-3.5", temperature=0.7)

search = GoogleSerperAPIWrapper()

search_tool = Tool(
    name="Scrape google searches",
    func=search.run,
    description="useful for when you need to ask the agent to search the internet",
)

# to load human in the loop
human_tools = load_tools(["human"])

# topic that will be used in the crew run
topic = "web application security"

# create a senior researcher agent
researcher = Agent(
    role="Senior Researcher",
    goal=f"Find the latest research papers on {topic}",
    verbose=True,
    backstory="I am a senior researcher with a focus on web application security. I am looking for the latest research papers on the topic to stay up to date with the latest trends and findings.",
    tools=[search_tool],
    llm=llm,
    allow_delegation=False,
)

# create a senior writer agent
writer = Agent(
    role="Senior Writer",
    goal=f"Write a summary of the latest research papers on {topic}",
    verbose=True,
    backstory="I am a senior writer with a focus on web application security. I am looking to write a summary of the latest research papers on the topic to inform my readers about the latest trends and findings.",
    llm=llm,
    allow_delegation=False,
)

# create tasks for the agents
researcher_task = Task(
    description="""Review existing web application security standards and frameworks. Identify potential threats and vulnerabilities specific to the project. Formulate design principles and countermeasures to mitigate security risks.""",
    agents=researcher,
)

# create tasks for the agents
writer_task = Task(
    description="""Using the insights provided, write a summary of the latest research papers on web application security. The summary should include the latest trends and findings in the field. """,
    agents=writer,
)

# instantiate the crew
crew = Crew(
    agents=[researcher, writer],
    tasks=[researcher_task, writer_task],
    verbose=2,
    process=Process.sequential,
)

# get the crew to run
result = crew.kickoff()

print("############################################")
print(result)

# save the result to a file
with open("result.txt", "w") as f:
    f.write(result)

I checked the spelling error but couldn't find what is wrong in the code. Please help me.

dwk601 avatar Feb 09 '24 05:02 dwk601

Yeah .I found it I don't know why this is an error but # create tasks for the agents researcher_task = Task( description="""Review existing web application security standards and frameworks. Identify potential threats and vulnerabilities specific to the project. Formulate design principles and countermeasures to mitigate security risks.""", agents=researcher, )

In the tasks instead of using agents=researcher use agent=researcher do this for both the tasks. It is working for me.

Haripritamreddy avatar Feb 09 '24 16:02 Haripritamreddy

Thank it fixed the error!

dwk601 avatar Feb 09 '24 16:02 dwk601