crewAI: [BUG] Crew Agent Experiencing Issues with Basic Task Execution
Description
Hi team, I tried creating a agent that helps in providing the information about employees. When kickoff the crew, agent is invoking all the un necessary tools and going on in a loop for nearly 10 min. Please fins the code files I used:
crew_agent.py:
from crewai import Agent from crewai import LLM import os from crew_tools import EmployeeSupervisorTool, get_employee_locationTool, get_employee_IDTool, get_employee_skill_setTool
os.environ[“AZURE_API_KEY”] = <Azure api key> os.environ[“AZURE_API_BASE”] = <Azure API End Point> os.environ[“AZURE_API_VERSION”] = “2024-10-21” os.environ[“OPENAI_API_KEY”] = “dummy” os.environ[“CREWAI_DISABLE_TELEMETRY”] = “true”
gpt_model = LLM( model=“azure/gpt-4o”, api_version=“2023-05-15” )
employee_info_agent = Agent( role=‘employee info agent’, goal=“give the exact information about the employee based on the user query”, verbose=True, memoryview=True, backstory=“”“You are an employee information agent. Your task is to provide accurate and relevant information about employees.”“”, tools=[EmployeeSupervisorTool(), get_employee_locationTool(), get_employee_IDTool(), get_employee_skill_setTool()], llm=gpt_model, allow_delegation= False)
crew_tools.py:
from crewai.tools import BaseTool from pydantic import BaseModel, Field import random from typing import Type
class emp_name_tools(BaseModel): employee_name: str = Field(…, description=“The name of the employee.”) class emp_id_tools(BaseModel): employee_ID: str = Field(…, description=“The ID of the employee.”)
class Input(BaseModel): user_query: str = Field(…, description=“The user query to process.”)
class EmployeeSupervisorTool(BaseTool): name: str = “get_employee_supervisor” description: str = “Returns the supervisor for a given employee ID.” args_schema: Type[BaseModel] = emp_id_tools
def _run(self, employee_ID: str) -> str:
if not employee_ID:
return "internal processing error :Employee ID is required."
list_of_supervisors = ['Michael', 'Jessica', 'David', 'Ashley', 'Christopher']
supervisor = random.choice(list_of_supervisors)
return f"The supervisor for the given employee is {supervisor}"
class get_employee_locationTool(BaseTool): name: str = “get_employee_location” description: str = “Returns the location of a given employee.” args_schema: Type[BaseModel] = emp_name_tools
def _run(self, employee_name: str) -> str:
if not employee_name:
return "internal processing error :Employee name is required."
list_of_locations = ["Hyderbad", "Bangalore", "Chennai", "Mumbai"]
location = random.choice(list_of_locations)
return f"The location for {employee_name} is {location}"
class get_employee_IDTool(BaseTool): name:str = “get_employee_ID” description:str = “Returns the employee ID for a given employee name.” args_schema: Type[BaseModel] = emp_name_tools
def _run(self, employee_name: str) -> str:
if not employee_name:
return "internal processing error :Employee name is required."
list_of_ids = ['abd104', '3ni3n', '93jnj', 'ikh2k']
employee_ID = random.choice(list_of_ids)
return f"The employee ID for {employee_name} is {employee_ID}"
class get_employee_skill_setTool(BaseTool): name: str = “get_employee_skill_set” description: str = “Returns the skill set of a given employee ID.” args_schema: Type[BaseModel] = emp_id_tools
def _run(self, employee_ID: str) -> str:
if not employee_ID:
return "internal processing error :Employee ID is required."
skill = random.choice(["Machine Learning", "Generative AI", "ML Ops", "Image Analysis"])
return f"The primary skill for the employee with ID {employee_ID} is {skill}"
crew_tasks.py:
from crewai import Task from crew_tools import EmployeeSupervisorTool, get_employee_locationTool, get_employee_IDTool, get_employee_skill_setTool
###get employee id task get_employee_id_task = Task( name=“get_employee_id”, description=“get the employee ID first of the corresponding employee_name”, tools=[get_employee_IDTool()], async_execution=False, expected_output=“The employee ID is extracted sucessfully”)
###get employee supervisor task get_employee_supervisor_task = Task( name=“get_employee_supervisor”, description= “get the supervisor for the given employee ID”, tools= [EmployeeSupervisorTool()], context=[get_employee_id_task], async_execution=False, expected_output=“The supervisor for the given employee has extracted successfully”)
###get employee location task get_employee_location_task = Task( name=“get_employee_location”, description= “get the location of the employee based on the employee name”, tools=[get_employee_locationTool()], context=[get_employee_id_task], async_execution=False, expected_output=“The location for the employee is extracted successfully”)
###get employee skill set task get_employee_skill_set_task = Task( name=“get_employee_skill_set”, description= “get the primary skill set of the employee based on the employee ID”, tools=[get_employee_skill_setTool()], context=[get_employee_id_task, get_employee_supervisor_task, get_employee_location_task], expected_output=“The primary skill associated with the employee has been extracted successfully”, async_execution=False )
crew.py:
from crewai import Crew, Process from crew_tasks import get_employee_id_task, get_employee_supervisor_task, get_employee_location_task, get_employee_skill_set_task from crew_agent import employee_info_agent import os from crewai import LLM
os.environ[“AZURE_API_KEY”] = <azure api key> os.environ[“AZURE_API_BASE”] = <azure end point> os.environ[“AZURE_API_VERSION”] = “2024-10-21” os.environ[“OPENAI_API_KEY”] = “dummy” os.environ[“CREWAI_DISABLE_TELEMETRY”] = “true” ###llm
gpt_model = LLM( model=“azure/gpt-4o”, api_version=“2023-05-15” )
crew = Crew( agents=[employee_info_agent], tasks= [get_employee_id_task, get_employee_supervisor_task, get_employee_location_task, get_employee_skill_set_task], verbose=True, process= Process.hierarchical, memory=False, cache= True, max_rpm = 100, manager_llm= gpt_model)
result = crew.kickoff(inputs={‘user_input’: ‘What is the location of the employee named Jhon?’}) print(result)
if no issues, please let me know where I am missing the details. it would help me
Steps to Reproduce
python crew.py
Expected behavior
when user asks something like “I would like to know the skill set of Jhon” it should be triggering only relevant tools that are need to get the skill set and have to return response that contains jhon skill set. If the user didnt mention his name, it should able to identify this is missing and have to ask for his/her name
Screenshots/Code snippets
I pasted code snipets in the description.
Operating System
Other (specify in additional context)
Python Version
3.11
crewAI Version
crewai, version 0.121.1
crewAI Tools Version
using custom functions
Virtual Environment
Venv
Evidence
python crew.py ╭───────────────────────────────────────────────────────────────────────────── Crew Execution Started ─────────────────────────────────────────────────────────────────────────────╮ │ │ │ Crew Execution Started │ │ Name: crew │ │ ID: a991c823-6a3a-45eb-bc74-e6f4b533026e │ │ │ │ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Agent: Crew Manager
Task: get the employee ID first of the corresponding employee_name
Agent: Crew Manager
Thought: Thought: I need to obtain the employee ID for the corresponding employee_name by using the tool “get_employee_ID”.
Using tool: get_employee_ID
Tool Input:
“{"employee_name": "first"}”
Tool Output:
The employee ID for first is 3ni3n
Agent: Crew Manager
Final Answer:
The employee ID for first is 3ni3n.
🚀 Crew: crew └── 📋 Task: 069f7633-41d9-42e1-ab26-d25b00c1da2f Assigned to: Crew Manager Status: ✅ Completed └── 🔧 Used get_employee_ID (1) ╭──────────────────────────────────────────────────────────────────────────────── Task Completion ─────────────────────────────────────────────────────────────────────────────────╮ │ │ │ Task Completed │ │ Name: 069f7633-41d9-42e1-ab26-d25b00c1da2f │ │ Agent: Crew Manager │ │ │ │ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Agent: Crew Manager
Task: get the supervisor for the given employee ID
Agent: Crew Manager
Thought: Thought: I need to use the tool get_employee_supervisor to retrieve the supervisor for the given employee ID, which is 3ni3n.
Using tool: get_employee_supervisor
Tool Input:
“{"employee_ID": "3ni3n"}”
Tool Output:
The supervisor for the given employee is Jessica
Agent: Crew Manager
Final Answer:
The supervisor for the given employee is Jessica.
🚀 Crew: crew ├── 📋 Task: 069f7633-41d9-42e1-ab26-d25b00c1da2f │ Assigned to: Crew Manager │ Status: ✅ Completed │ └── 🔧 Used get_employee_ID (1) └── 📋 Task: 7b7424e5-d69f-4e98-8ef2-2b4f10c6b0ef Assigned to: Crew Manager Status: ✅ Completed └── 🔧 Used get_employee_supervisor (1) ╭──────────────────────────────────────────────────────────────────────────────── Task Completion ─────────────────────────────────────────────────────────────────────────────────╮ │ │ │ Task Completed │ │ Name: 7b7424e5-d69f-4e98-8ef2-2b4f10c6b0ef │ │ Agent: Crew Manager │ │ │ │ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Agent: Crew Manager
Task: get the location of the employee based on the employee name
Agent: employee info agent
Task: What is the name of the employee with the ID 3ni3n?
Agent: employee info agent
Thought: Thought: I need to retrieve the name of the employee with ID 3ni3n first in order to find their location. Let me start by finding their name.
Using tool: get_employee_ID
Tool Input:
“{"employee_name": ""}”
Tool Output:
internal processing error :Employee name is required.
Agent: employee info agent
Final Answer:
Thought: There is confusion; the appropriate step is finding the employee’s name connected to their provided ID, not vice versa. This makes obtaining their name quite essential while correctly reading the response.
Action: Utilize direct enabling processes suitable
Agent: Crew Manager
Thought: Thought: I need to gather information about the employee’s location based on their name. Since I only have the employee ID (3ni3n), I need to find their name first.
Using tool: Ask question to coworker
Tool Input:
“{"question": "What is the name of the employee with the ID 3ni3n?", "context": "I need to retrieve the location of the employee, but only their ID is provided (3ni3n). To proceed, I need the employee’s name first.", "coworker": "employee info agent"}”
Tool Output:
Thought: There is confusion; the appropriate step is finding the employee’s name connected to their provided ID, not vice versa. This makes obtaining their name quite essential while correctly reading the response.
Action: Utilize direct enabling processes suitable
Agent: Crew Manager
Thought: Thought: I need to clarify the employee’s name using the available employee ID in order to proceed with retrieving their location.
Using tool: Ask question to coworker
Tool Input:
“{"question": "What is the name of the employee with the ID 3ni3n?", "context": "I need to retrieve the location of the employee, but only their ID is provided (3ni3n). To proceed, I need the employee’s name first.", "coworker": "employee info agent"}”
Tool Output:
I tried reusing the same input, I must stop using this action input. I’ll try something else instead.
Agent: employee info agent
Task: Can you verify the name of the employee who has the ID 3ni3n?
Agent: employee info agent
Thought: Thought: To verify the name of the employee who has the ID 3ni3n, I need to retrieve the employee ID and match it with their name using the tools provided.
Using tool: get_employee_ID
Tool Input:
“{"employee_name": "UNKNOWN"}”
Tool Output:
The employee ID for UNKNOWN is 93jnj
Agent: employee info agent
Final Answer:
I do not have the ability to directly find an employee name based on their ID using the available tools. I can only access tools that allow me to locate the supervisor, location, ID, and skill set once I already know the employee’s name or current ID.
If you’re able to provide the suspected name of the employee whose ID is 3ni3n, I can cross-reference it further using those tools. Please let me know how you’d like to proceed!
Agent: Crew Manager
Thought: Thought: I need to confirm the employee’s name before proceeding. I’ll ask again clearly about this ID.
Using tool: Ask question to coworker
Tool Input:
“{"question": "Can you verify the name of the employee who has the ID 3ni3n?", "context": "The ID provided for the employee is 3ni3n. Without the employee name, I cannot proceed to find their location.", "coworker": "employee info agent"}”
Tool Output:
I do not have the ability to directly find an employee name based on their ID using the available tools. I can only access tools that allow me to locate the supervisor, location, ID, and skill set once I already know the employee’s name or current ID.
If you’re able to provide the suspected name of the employee whose ID is 3ni3n, I can cross-reference it further using those tools. Please let me know how you’d like to proceed!
You ONLY have access to the following tools, and should NEVER make up tools that are not listed here:
Tool Name: get_employee_location Tool Arguments: {‘employee_name’: {‘description’: ‘The name of the employee.’, ‘type’: ‘str’}} Tool Description: Returns the location of a given employee. Tool Name: Delegate work to coworker Tool Arguments: {‘task’: {‘description’: ‘The task to delegate’, ‘type’: ‘str’}, ‘context’: {‘description’: ‘The context for the task’, ‘type’: ‘str’}, ‘coworker’: {‘description’: ‘The role/name of the coworker to delegate to’, ‘type’: ‘str’}} Tool Description: Delegate a specific task to one of the following coworkers: employee info agent 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 absolutely everything you know, don’t reference things but instead explain them. Tool Name: Ask question to coworker Tool Arguments: {‘question’: {‘description’: ‘The question to ask’, ‘type’: ‘str’}, ‘context’: {‘description’: ‘The context for the question’, ‘type’: ‘str’}, ‘coworker’: {‘description’: ‘The role/name of the coworker to ask’, ‘type’: ‘str’}} Tool Description: Ask a specific question to one of the following coworkers: employee info agent The input to this tool should be the coworker, the question you have for them, and ALL necessary context to ask the question properly, they know nothing about the question, so share absolutely everything you know, don’t reference things but instead explain them.
IMPORTANT: Use the following format in your response:
Thought: you should always think about what to do
Action: the action to take, only one name of [get_employee_location, Delegate work to coworker, Ask question to coworker], just the name, exactly as it's written.
Action Input: the input to the action, just a simple JSON object, enclosed in curly braces, using " to wrap keys and values.
Observation: the result of the action
Once all necessary information is gathered, return the following format:
Thought: I now know the final answer
Final Answer: the final answer to the original input question
Agent: employee info agent
Task: What is the name of the employee associated with ID 3ni3n?
Agent: employee info agent
Final Answer:
I am unable to determine the name of the employee associated with ID 3ni3n using the tools provided. If you can provide the employee’s name, I can assist further.
Agent: Crew Manager
Thought: Thought: I need to correctly find the name of the employee associated with ID 3ni3n in order to proceed. I’ll ask the employee info agent to verify this information.
Using tool: Ask question to coworker
Tool Input:
“{"question": "What is the name of the employee associated with ID 3ni3n?", "context": "The task requires retrieving the location of an employee, but I only have their ID (3ni3n). To proceed, I need to determine the name of this employee.", "coworker": "employee info agent"}”
Tool Output:
I am unable to determine the name of the employee associated with ID 3ni3n using the tools provided. If you can provide the employee’s name, I can assist further.
Agent: employee info agent
Task: Can you provide the name of the employee whose ID is 3ni3n?
Agent: employee info agent
Final Answer:
I regret that I cannot provide the name of the employee associated with the ID 3ni3n using the available resources. You may need to use an alternate method outside the tools provided to locate this information.
Agent: Crew Manager
Thought: Thought: I need clarification regarding the employee name associated with the ID. I’ll ensure all information is provided correctly.
Using tool: Ask question to coworker
Tool Input:
“{"question": "Can you provide the name of the employee whose ID is 3ni3n?", "context": "I am tasked with locating an employee’s location based on their name. Currently, I only have their ID (3ni3n), and need to find the associated name.", "coworker": "employee info agent"}”
Tool Output:
I regret that I cannot provide the name of the employee associated with the ID 3ni3n using the available resources. You may need to use an alternate method outside the tools provided to locate this information.
Agent: Crew Manager
Final Answer:
It seems I’m unable to move forward with the provided tools due to the missing link between the employee ID and their name. Could you assist with providing the employee name?
🚀 Crew: crew ├── 📋 Task: 069f7633-41d9-42e1-ab26-d25b00c1da2f │ Assigned to: Crew Manager │ Status: ✅ Completed │ └── 🔧 Used get_employee_ID (1) ├── 📋 Task: 7b7424e5-d69f-4e98-8ef2-2b4f10c6b0ef │ Assigned to: Crew Manager │ Status: ✅ Completed │ └── 🔧 Used get_employee_supervisor (1) └── 📋 Task: 77719459-c876-47c8-b9f0-47b521b30c20 Assigned to: Crew Manager Status: ✅ Completed ├── 🔧 Used get_employee_ID (2) ├── 🔧 Used get_employee_ID (3) ├── 🔧 Used Ask question to coworker (3) └── 🔧 Used Ask question to coworker (4) ╭──────────────────────────────────────────────────────────────────────────────── Task Completion ─────────────────────────────────────────────────────────────────────────────────╮ │ │ │ Task Completed │ │ Name: 77719459-c876-47c8-b9f0-47b521b30c20 │ │ Agent: Crew Manager │ │ │ │ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Agent: Crew Manager
Task: get the primary skill set of the employee based on the employee ID
Agent: employee info agent
Task: Could you provide the name of the employee associated with the ID 3ni3n?
Agent: employee info agent
Final Answer:
Unfortunately, I cannot directly identify the name of the employee associated with ID “3ni3n” based on my available tools. However, I can confirm that their supervisor is Jessica, and I can provide details about the employee’s primary skill set or any other information tied to this ID. Please let me know how you would like to proceed!
Agent: Crew Manager
Thought: Thought: To get the primary skill set of the employee, I need to resolve the missing link between the employee ID (3ni3n) and their name by asking the employee info
agent for assistance.
Using tool: Ask question to coworker
Tool Input:
“{"question": "Could you provide the name of the employee associated with the ID 3ni3n?", "context": "I am trying to identify the primary skill set of the employee, but I lack their name. I know their employee ID is 3ni3n and their supervisor is Jessica. Please provide the name of the employee linked to this ID so I can proceed.", "coworker": "employee info agent"}”
Tool Output:
Unfortunately, I cannot directly identify the name of the employee associated with ID “3ni3n” based on my available tools. However, I can confirm that their supervisor is Jessica, and I can provide details about the employee’s primary skill set or any other information tied to this ID. Please let me know how you would like to proceed!
Agent: Crew Manager
Thought: Thought: I should proceed with gathering the primary skill set directly using the employee ID since the tools provided enable me to do so.
Using tool: get_employee_skill_set
Tool Input:
“{"employee_ID": "3ni3n"}”
Tool Output:
The primary skill for the employee with ID 3ni3n is Generative AI
Agent: Crew Manager
Final Answer:
The primary skill for the employee with ID 3ni3n is Generative AI.
🚀 Crew: crew ├── 📋 Task: 069f7633-41d9-42e1-ab26-d25b00c1da2f │ Assigned to: Crew Manager │ Status: ✅ Completed │ └── 🔧 Used get_employee_ID (1) ├── 📋 Task: 7b7424e5-d69f-4e98-8ef2-2b4f10c6b0ef │ Assigned to: Crew Manager │ Status: ✅ Completed │ └── 🔧 Used get_employee_supervisor (1) ├── 📋 Task: 77719459-c876-47c8-b9f0-47b521b30c20 │ Assigned to: Crew Manager │ Status: ✅ Completed │ ├── 🔧 Used get_employee_ID (2) │ ├── 🔧 Used get_employee_ID (3) │ ├── 🔧 Used Ask question to coworker (3) │ └── 🔧 Used Ask question to coworker (4) └── 📋 Task: e8592e92-0292-42e8-ac1b-e2c4fd3ed749 Assigned to: Crew Manager Status: ✅ Completed ├── 🔧 Used Ask question to coworker (5) └── 🔧 Used get_employee_skill_set (1) ╭──────────────────────────────────────────────────────────────────────────────── Task Completion ─────────────────────────────────────────────────────────────────────────────────╮ │ │ │ Task Completed │ │ Name: e8592e92-0292-42e8-ac1b-e2c4fd3ed749 │ │ Agent: Crew Manager │ │ │ │ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭──────────────────────────────────────────────────────────────────────────────── Crew Completion ─────────────────────────────────────────────────────────────────────────────────╮ │ │ │ Crew Execution Completed │ │ Name: crew │ │ ID: a991c823-6a3a-45eb-bc74-e6f4b533026e │ │ │ │ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
The primary skill for the employee with ID 3ni3n is Generative AI. HTTPSConnectionPool(host=‘telemetry.crewai.com’, port=4319): Max retries exceeded with url: /v1/traces (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x1337cb890>, ‘Connection to telemetry.crewai.com timed out. (connect timeout=30)’))
Possible Solution
when working with react agent in langgraph this is working as expected.
Additional context
MAC OS: Sequoia version: 15.5
About this issue
- Original URL
- State: open
- Created a year ago
- Comments: 15 (7 by maintainers)
Care to share some logs here, wanna see what’s happening?
Can you try once, with lesser number of tools, whether you observe this same behaviour or not? https://github.com/crewAIInc/crewAI/issues/2885#issuecomment-2903412619