Problem with AI Agents project with Langchain and Open AI

  Kiến thức lập trình

I have a problem generating the result of my code, it is giving me the following error.

I encountered an error while trying to use the tool. This was the error: BaseAgentTools.delegate_work() missing 1 required positional argument: ‘context’.
Tool Delegate work to coworker accepts these inputs: Delegate a specific task to one of the following coworkers: [Senior Sustainability Researcher]
The input to this tool should be the coworker, the task you want them to do, and ALL necessary context to execute the task, they know nothing about the task, so share absolute everything you know, don’t reference things but instead explain them .

follow the full code

# IMPORTING LIBRARIES
import them
from crewai import Agent, Task, Process, Crew
import openai
from langchain_community.utilities import GoogleSerperAPIWrapper
from langchain.agents import Tool
from langchain_openai import ChatOpenAI

# API configuration via environment variables
os.environ["OPENAI_API_KEY"] = ""
os.environ["SERPER_API_KEY"] = ""

# Instantiating objects
openai.api_key = os.environ["OPENAI_API_KEY"]

# Google search tool
search = GoogleSerperAPIWrapper()

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


# Set theme variable
theme_publicacao = "climate journey"

# Define agents
researcher = Agent(
   role="Senior Sustainability Researcher",
   goal=f"Find relevant information about {tema_publicacao} for publications on LinkedIn",
   backstory="""You work at Grupo Report, a consultancy focused on transforming companies and people through sustainability.
As a researcher, you collect information from leading sustainability news sources,
including Capital Reset, Invest News, InfoMoney, Valor Econômico, Sustainable Brands, Economia B, Brazil Journal,
Triple Pundit, Bloomberg Intelligence and World Economic Forum.
""",
   tools=[search_tool],
   verbose=True,
   llm=ChatOpenAI(model="gpt-3.5-turbo-0125", temperature=0.3),
)

writer = Agent(
   role="Senior Sustainable Content Writer",
   goal=f"Write engaging posts about {tema_publicacao} for LinkedIn",
   backstory="""You are part of the Report Group, a consultancy committed to sustainability.
Your role is to transform the information collected into clear and impactful texts,
that promote sustainability practices and engage readers.
""",
   verbose=True,
   llm=ChatOpenAI(model="gpt-3.5-turbo-0125", temperature=0.7),
)

reviewer = Agent(
   role="Senior Sustainable Content Reviewer",
   goal=f"Review and improve publications about {tema_publicacao} on LinkedIn",
   backstory="""You are the guardian of quality at Grupo Report, ensuring that all publications on sustainability-related topics are accurate and engaging.
With extensive experience in proofreading, you ensure that all publications are polished and perfect before they are published.
""",
   verbose=True,
   llm=ChatOpenAI(model="gpt-3.5-turbo-0125", temperature=0.7),
)

manager = Agent(
   role="Sustainable Communication Manager",
   goal=f"Coordinate the workflow and ensure that the publication about {tema_publicacao} is perfect and ready to be posted on LinkedIn",
   backstory="""You are the Sustainability Communication Manager at Grupo Report, a consultancy dedicated to corporate sustainability.
Your role is to coordinate the workflow of the team of researchers, writers and reviewers, and review the final publication to ensure it is perfect.
You must ensure that all information is correct, accurate and up-to-date, and that the text is fluid, engaging and cohesive.
You must also ensure that the publication is visually appealing, with appropriate formatting and effective use of visual elements.
Ensure that all publications are made with common sense and prudence, without harming the development of the work or the company's image.
Professionals must always make it clear that they do not represent or speak on behalf of the company.
""",
   verbose=True,
   allow_delegation=True,
   llm=ChatOpenAI(model="gpt-3.5-turbo-0125", temperature=0.4),
)
# Set tasks
research_task = Task(
   description=f"""
Conduct comprehensive and detailed research on relevant topics in {tema_publicacao} in the following sources:
- Capital Reset
- Invest News
- InfoMoney
- Economy B
-Brazil Journal
- Economic value
- Sustainable Brands
-Bloomberg Intelligence
- World Economic Forum
- CNN
- And other communication channels relevant to Brazil and the world.

Focus on identifying and gathering information about:
- Current trends in the context of corporate sustainability
- Significant innovations
- Challenges faced by companies
- Best practices adopted in the sector

Research should cover articles, reports, case studies, recent news and market analysis.

Steps to be followed:
1. Consult each of the sources listed and collect relevant information.
2. Identify the key points and insights from each source.
3. Compile the data into five detailed summaries.
4. Include links to all sources used.
5. Add critical observations about the applicability of the information in the business context.
""",
   expected_output="""
Produce five detailed and relevant summaries in Portuguese, ensuring they include:
- Key points from each source researched
- Current and impactful insights
- Links to the sources used
- Critical observations on the applicability of information in the business context
""",
   tools=[search_tool],
   agent=researcher,
)

task_writing = Task(
   description=f"""
Write engaging posts about {tema_publicacao} based on research conducted by the search agent.
Publications must:
- Highlight innovative practices in corporate sustainability
- Present relevant success stories
- Use accessible, clear and motivating language
- Emphasize the importance of initiatives for the target audience

Posts should be formatted specifically for LinkedIn and structured to maximize audience attraction and engagement.

Steps to be followed:
1. Read and analyze the summaries provided by the researcher.
2. Identify the most impactful and relevant points for the target audience.
3. Write a catchy title.
4. Write an introduction that immediately captures the reader's attention.
5. Develop two detailed paragraphs with data, statistics and concrete examples.
6. Conclude with an inspirational message that encourages action or reflection, including a call to action (CTA).
7. Review and adjust the text to ensure clarity and cohesion.
""",
   expected_output="""
Produce draft publications in Portuguese for LinkedIn, including:
- An attractive title
- A captivating introduction
- Two detailed paragraphs with data, statistics and concrete examples
- An inspiring conclusion with a call to action (CTA)
""",
   agent=writer,
)

task_review = Task(
   description=f"""
Review and improve publications on {tema_publicacao} to ensure excellence in quality, clarity and impact.
Its goal is to ensure that all information presented is accurate, up-to-date and well-founded.
Improve the fluidity of the text so that reading is pleasant and engaging.
Add a humanized touch, connecting readers in an empathetic and authentic way.
Finally, organize the text in a structured way, ready for the user to publish on LinkedIn.

Steps to be followed:
1. Carefully read the draft provided by the writer.
2. Check the accuracy of the information presented and the sources.
3. Adjust text to improve clarity and flow.
4. Add elements that connect empathetically and authentically with readers.
5. Organize the text in a structured and professional way.
6. Ensure that the text is free from grammatical, spelling and typing errors.
""",
   expected_output="""
Finalized posts in Portuguese for LinkedIn, ready for publication, with:
- Clarity and precision in all information presented
- Fluid and engaging text
- Humanized touch that connects with readers in an empathetic and authentic way
- Organized and professional structure, ready for publication on LinkedIn
""",
   agent=reviewer,
)

task_manage = Task(
   description=f"""
Coordinate the workflow of the content team (researcher, writer and reviewer) and ensure that the publication on {tema_publicacao} is perfect.
Review the final publication to ensure that:
- All information is correct, accurate and up to date.
- The text is structured in a clear and logical way, with an introduction, two paragraphs and a conclusion.
- The text is fluid, engaging and cohesive, keeping the tone and style aligned with the voice and established mission.
- The publication is visually attractive, with adequate formatting and effective use of visual elements, such as images or infographics.
- The message is clear and impactful, engaging readers and encouraging interaction and sharing.
- The publication is free from grammatical, spelling and typing errors.
Facilitate final meetings with the content team to ensure all details are reviewed and approved.
Ensure that all publications are made with common sense and prudence, without harming the development of the work or the company's image.
Professionals must always make it clear that they do not represent or speak on behalf of the company.

Steps to be followed:
1. Coordinate and supervise the execution of all tasks.
2. Review all publications to ensure accuracy and quality.
3. Organize final meetings for feedback and approval.
4. Ensure that all information is correct and up to date.
5. Ensure that the message is clear, cohesive and engaging.
6. Check the formatting and use of visual elements.
7. Approve the final version for publication.
""",
   expected_output=f"""
Detailed publication in Portuguese about {tema_publicacao}, ready to be posted on LinkedIn, ensuring that:
- All information is correct, accurate and up to date.
- The text is structured in a clear and logical way, with an introduction, two paragraphs and conclusion.
- The text is fluid, engaging and cohesive, keeping the tone and style aligned with the voice and established mission.
- The publication is visually attractive, with adequate formatting and effective use of visual elements, such as images or infographics.
- The message is clear and impactful, engaging readers and encouraging interaction and sharing.
- The publication is free from grammatical, spelling and typing errors.
- Performance metrics are clearly defined and ready for monitoring after posting.
- The call to action is direct, motivating readers to interact, share or comment on the publication.
- The publication respects the company's values ​​and standards, ensuring that it does not harm the company's image.
""",
   agent=manager,
)

# Create and run the team
team = Crew(
   agents=[researcher, writer, reviewer],
   tasks=[research_task, writing_task, review_task, manage_task],
   process=Process.hierarchical,
   manager_agent=manager,
   manager_llm=ChatOpenAI(
       model="gpt-3.5-turbo-0125",
       temperature=0.4,
       api_key="",
       openai_organization="",
       streaming=True,
   ),
)

result = team.kickoff()
print("####### POST PREPARED ###########")
print(result)

New contributor

alan bergman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT