Unable to create agent

Unable to create agent :
data_analyst = Agent(
role=“Senior Data Analyst”,
goal=“You receive data from the database developer and analyze it”,
backstory=dedent(
“”"
You have deep experience with analyzing datasets using Python.
Your work is always based on the provided data and is clear,
easy-to-understand and to the point. You have attention
to detail and always produce very detailed work (as long as you need).
“”"
),
llm=llm,
allow_delegation=False,
)
ERROR:root:Failed to get supported params: argument of type ‘NoneType’ is not iterable

llm and tools are initialized and working properly. I can’t find the solution

@Mahdi_Hammi The error occurs probably because of how you set your LLM. Use the CrewAI LLM class, which uses liteLLM in the background.

See the example below with the Anthropic Claude 3.5 Sonnet LLM.

Note: Don’t forget to put anthropic/ before setting the LLM.

from crewai import Agent, LLM

my_llm = LLM(
    api_key=os.getenv("ANTHROPIC_API_KEY"),
    model="anthropic/claude-3-5-sonnet-20240620",
),

my_agent = Agent(
    ...,
    llm=my_llm,
)
1 Like

Hi @rokbenko,

I am getting the same error even after defining the LLM as you have described. Please let me know how to resolve it. I have been trying several ways with different LLMs but none worked yet.

Another i tried was-
GROQ_API_KEY = getpass(“Enter your API key”)
os.environ[‘GROQ_API_KEY’] = GROQ_API_KEY
llm = ChatGroq(model=“groq/llama3-70b-8192”,groq_api_key=GROQ_API_KEY)

I am working in google colab with latest version of crew ai and langchain_groq

Please suggest. Thank you.

Can you please share the code?

!pip install -q crewai 'crewai[tools]' langchain_groq --progress-bar off
groq_api_key = userdata.get('groq_api')
os.environ["GROQ_API_KEY"] = groq_api_key

import os
from crewai import LLM
groq_llm = LLM(
    model="groq/llama3-8b-8192",
    temperature=0.3,
    max_tokens=4096,
    api_key=groq_api_key,
    base_url="https://api.groq.com/openai/v1"
)
#further defined 
#agents
#tasks
#custom tool
#crew

Error- OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable

Let me know if further information is required.

This is a different error. I think the problem is somewhere else in your code. Can you please share the full code?

from crewai_tools import DirectoryReadTool, \
                         FileReadTool, \
                         SerperDevTool

directory_read_tool = DirectoryReadTool(directory='./instructions')
file_read_tool = FileReadTool()
search_tool = SerperDevTool()

from crewai_tools import BaseTool

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"

sales_rep_agent = Agent(
    role="Sales Representative",
    goal="Identify high-value leads that match "
         "our ideal customer profile",
    backstory=(
        "As a part of the dynamic sales team at CrewAI, "
        "your mission is to scour "
        "the digital landscape for potential leads. "
        "Armed with cutting-edge tools "
        "and a strategic mindset, you analyze data, "
        "trends, and interactions to "
        "unearth opportunities that others might overlook. "
        "Your work is crucial in paving the way "
        "for meaningful engagements and driving the company's growth."
    ),
    allow_delegation=False,
    verbose=True,
    tools=[directory_read_tool, file_read_tool, search_tool],
)

sentiment_analysis_tool = SentimentAnalysisTool()

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,
    tools=[sentiment_analysis_tool, search_tool],
    verbose=True
)

lead_profiling_task = Task(
    description=(
        "Conduct an in-depth analysis of {lead_name}, "
        "a company in the {industry} sector "
        "that recently showed interest in our solutions. "
        "Utilize all available data sources "
        "to compile a detailed profile, "
        "focusing on key decision-makers, recent business "
        "developments, and potential needs "
        "that align with our offerings. "
        "This task is crucial for tailoring "
        "our engagement strategy effectively.\n"
        "Don't make assumptions and "
        "only use information you absolutely sure about."
    ),
    expected_output=(
        "A comprehensive report on {lead_name}, "
        "including company background, "
        "key personnel, recent milestones, and identified needs. "
        "Highlight potential areas where "
        "our solutions can provide value, "
        "and suggest personalized engagement strategies."
    ),
    agent=sales_rep_agent,
)

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."
    ),
 
    agent=lead_sales_rep_agent,

)

crew = Crew(
    agents=[sales_rep_agent, 
            lead_sales_rep_agent],
    
    tasks=[lead_profiling_task, 
           personalized_outreach_task],
	
    verbose=True,
	  #memory=True
)

inputs = {
    "lead_name": "DeepLearningAI",
    "industry": "Online Learning Platform",
    "key_decision_maker": "Andrew Ng",
    "position": "CEO",
    "milestone": "product launch"
}

result = crew.kickoff(inputs=inputs)

This is the code that I am trying. Experimenting with custom tool.

Try to remove the base_url parameter. Does the error still occur?

1 Like

It worked… in both the agents i added llm=groq_llm and removed the base_url parameter.
Thanks a lot!

@Srishti_Nagu You’re welcome! :slight_smile:

1 Like

I deploy my own one-api server, and my llm defination must have the base_url to access my server, how can i solve this same problem in this case

@FuliangLiu Can you please post the code and the error traceback you get? What’s your issue?