I have been trying to learn how to create and use custom tools but kept getting errors. So I tried to replicate the training on deeplearning.ai on my local, but still get the same error. Therefore I believe it is not the way I am defining tools, because I have copied and pasted it from the training. There is the detail of the error I am getting:
" Crew: crew
βββ Task: f29b0972-dfbd-453d-b109-0f3942e4880a
β Assigned to: Sales Representative
β Status: Completed
β βββ Agent: Sales Representative
β Status: Completed
β βββ Used List files in directory (4)
β βββ Used Read a fileβs content (6)
βββ Task: 5b85f8cf-6215-40c3-8b2f-2390961e5542
Status: Executing Taskβ¦
βββ Agent: Lead Sales Representative
Status: In Progress
βββ Using Sentiment Analysis (1)
Crew: crew
βββ Task: f29b0972-dfbd-453d-b109-0f3942e4880a
β Assigned to: Sales Representative
β Status: Completed
β βββ Agent: Sales Representative
β Status: Completed
β βββ Used List files in directory (4)
β βββ Used Read a fileβs content (6)
βββ Task: 5b85f8cf-6215-40c3-8b2f-2390961e5542
Status: Executing Taskβ¦
βββ Agent: Lead Sales Representative
Status: In Progress
βββ Failed Sentiment Analysis (1)
βββββββββββββββββββββββββββββββββ Tool Error ββββββββββββββββββββββββββββββββββ
β β
β Tool Usage Failed β
β Name: Sentiment Analysis β
β Error: βSentiment Analysis Toolβ β
β β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
An unknown error occurred. Please check the details below.
Error details: βSentiment Analysis Toolβ
An unknown error occurred. Please check the details below.
Error details: βSentiment Analysis Toolβ
Crew: crew
βββ Task: f29b0972-dfbd-453d-b109-0f3942e4880a
β Assigned to: Sales Representative
β Status: Completed
β βββ Agent: Sales Representative
β Status: Completed
β βββ Used List files in directory (4)
β βββ Used Read a fileβs content (6)
βββ Task: 5b85f8cf-6215-40c3-8b2f-2390961e5542
Status: Executing Taskβ¦
βββ Agent: Lead Sales Representative
β Status: In Progress
β βββ Failed Sentiment Analysis (1)
βββ Agent: Lead Sales Representative
Status: In Progress"
My import:
from crewai.tools import BaseTool
Defining the tool:
class SentimentAnalysisTool(BaseTool):
name: str =βSentiment Analysis Toolβ
description: str = ("Analyzes the sentiment of text "
βto ensure positive and engaging communication.β)
def _run(self, text: str) -> str:
# Your custom code tool goes here
return "positive"
sentiment_analysis_tool = SentimentAnalysisTool()
Task that uses it:
personalized_outreach_task = Task(
description=(
"Using the insights gathered from "
"the lead profiling report on {lead_name}, "
"craft a personalized outreach campaign "
"aimed at {key_decision_maker}, "
"the {position} of {lead_name}. "
"The campaign should address their recent {milestone} "
"and how our solutions can support their goals. "
"Your communication must resonate "
"with {lead_name}'s company culture and values, "
"demonstrating a deep understanding of "
βtheir business and needs.\nβ
"Donβt make assumptions and only "
βuse information you absolutely sure about.β
),
expected_output=(
"A series of personalized email drafts "
"tailored to {lead_name}, "
βspecifically targeting {key_decision_maker}.β
"Each draft should include "
"a compelling narrative that connects our solutions "
"with their recent achievements and future goals. "
"Ensure the tone is engaging, professional, "
βand aligned with {lead_name}'s corporate identity.β
),
tools=[sentiment_analysis_tool],
agent=lead_sales_rep_agent,)
agent that uses it:
lead_sales_rep_agent = Agent(
role=βLead Sales Representativeβ,
goal=βNurture leads with personalized, compelling communicationsβ,
backstory=(
"Within the vibrant ecosystem of CrewAIβs sales department, "
"you stand out as the bridge between potential clients "
βand the solutions they need.β
"By creating engaging, personalized messages, "
"you not only inform leads about our offerings "
βbut also make them feel seen and heard.β
"Your role is pivotal in converting interest "
"into action, guiding leads through the journey "
βfrom curiosity to commitment.β
),
allow_delegation=False,
llm = llm,
verbose=True
)
crew:
crew = Crew(
agents=[sales_rep_agent, lead_sales_rep_agent],
tasks=[lead_profiling_task, personalized_outreach_task],
verbose=True
)
This is my first ever message, sorry if I missed some things and thank you for your support