crewAI
crewAI copied to clipboard
[BUG] Custom tools are not called by the crewAI agent
Description
Custom tools are not called by the crewAI agent (even when the agent decides to invoke the tool). This issue is seen in the version 0.114.0. Works fine in the version 0.108.0.
Steps to Reproduce
Create a custom tool and assign it to an agent. The task description should necessitate the agent to invoke the tool.
Expected behavior
The custom tool is called by the agent when it decides to invoke.
Screenshots/Code snippets
N/A
Operating System
Ubuntu 20.04
Python Version
3.12
crewAI Version
0.114.0
crewAI Tools Version
0.40.1
Virtual Environment
Venv
Evidence
I ran the same piece of code in both 0.114.0 and 0.108.0 version of crewAI and noticed that tool was called only in 0.108.0.
Possible Solution
Probably, comparison of the two versions (0.114.0 and 0.108.0) to identify the delta code change that introduced the issue.
Additional context
N/A
Can you set the verbose=True and share all the logs once
Can you share the custom tool code if you can ?
Hi, here is a sample tool and I notice that the API tool is getting called but the logs do not show that the tool is invoked (In the earlier version of crewAI the logs capture that the tool is invoked and also shows the tool input and output). Here, the statement print("---------Tool Invoked---------") Code and the logs below.
` SAMPLE_API_BASE_URL = "https://jsonplaceholder.typicode.com"
class SampleAPITool(BaseTool): """Tool for interacting with the sample JSONPlaceholder API."""
name: str = "sample_api_caller"
description: str = "Useful for fetching or creating sample data using the JSONPlaceholder API."
def _run(self, task: str, **kwargs) -> str:
"""Executes the API call based on the task and provided arguments."""
try:
print("---------Tool Invoked---------")
endpoint = "/todos"
params = kwargs.get("params", {})
response = requests.get(f"{SAMPLE_API_BASE_URL}{endpoint}", params=params)
response.raise_for_status()
return json.dumps(response.json(), indent=2)
except requests.exceptions.RequestException as e:
return f"Error communicating with the Sample API: {e}"
except json.JSONDecodeError:
return f"Error decoding JSON response from the Sample API."
except Exception as e:
return f"An unexpected error occurred: {e}"
sample_api_tool = SampleAPITool() `
───────────────────────────────────────────────────────── Crew Execution Started ──────────────────────────────────────────────────────────╮ │ │ │ Crew Execution Started │ │ Name: crew │ │ ID: 2c270d56-465c-416d-bc8b-3be1c757f9e8 │ │ │ │ │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Provider List: https://docs.litellm.ai/docs/providers
🚀 Crew: crew └── 📋 Task: e294f771-b90f-4659-87da-cb0d724f509e Status: Executing Task...
Provider List: https://docs.litellm.ai/docs/providers
🚀 Crew: crew └── 📋 Task: e294f771-b90f-4659-87da-cb0d724f509e Status: Executing Task... └── 🤖 Agent: API User Status: In Progress
Agent: API User
Task: Use the 'sample_api_caller' tool to fetch a list of all todo items from the API.
🤖 Agent: API User Status: In Progress └── 🧠 Thinking...
2025-04-24 14:35:56,517 - 6242250752 - init.py-init:111 - WARNING: Invalid type NoneType for attribute 'gen_ai.response.service_tier' value. Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types 🤖 Agent: API User Status: In Progress
Agent: API User
Final Answer:
{"todos": [{"userId": 1, "id": 1, "title": "delectus aut autem", "completed": false}, {"userId": 1, "id": 2, "title": "quis ut nam facilis et officia qui", "completed": false}, {"userId": 1, "id": 3, "title": "fugiat veniam minus", "completed": false}, {"userId": 1, "id": 4, "title": "et porro tempora", "completed": true}, {"userId": 1, "id": 5, "title": "laboriosam mollitia et enim quasi adipisci quia provident illum", "completed": false}, {"userId": 1, "id": 6, "title": "qui ullam ratione quibusdam voluptatem quia omnis", "completed": false}, {"userId": 1, "id": 7, "title": "illo expedita consequatur quia in", "completed": false}, {"userId": 1, "id": 8, "title": "quo adipisci enim quam ut ab", "completed": true}, {"userId": 1, "id": 9, "title": "molestiae perspiciatis ipsa", "completed": false}, {"userId": 1, "id": 10, "title": "illo est ratione doloremque quia maiores aut", "completed": true}]}
🚀 Crew: crew └── 📋 Task: e294f771-b90f-4659-87da-cb0d724f509e Status: Executing Task... └── 🤖 Agent: API User Status: ✅ Completed
🚀 Crew: crew └── 📋 Task: e294f771-b90f-4659-87da-cb0d724f509e Assigned to: API User Status: ✅ Completed └── 🤖 Agent: API User Status: ✅ Completed ╭───────────────────────────────────────────────────────────── Task Completion ──────────────────────────────────────────────────────────────╮ │ │ │ Task Completed │ │ Name: e294f771-b90f-4659-87da-cb0d724f509e │ │ Agent: API User │ │ │ │ │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭───────────────────────────────────────────────────────────── Crew Completion ──────────────────────────────────────────────────────────────╮ │ │ │ Crew Execution Completed │ │ Name: crew │ │ ID: 2c270d56-465c-416d-bc8b-3be1c757f9e8
Okay, so the tool is getting called but logs aren't showing up? Can you share your entire crew, along with agents ?
Could you test following this tutorial?
@Vidit-Ostwal. Here is the sample crew. You can even try with your example.
api_interaction_agent = Agent( role="API User", goal="Interact with the sample JSONPlaceholder API to retrieve and manage todo items.", backstory="An expert in consuming RESTful APIs to fetch and manipulate data.", verbose=True, allow_delegation=False, tools=[sample_api_tool], llm=crewai_llm )
get_all_todos_task = Task( description="Use the 'sample_api_caller' tool to fetch a list of all todo items from the API.", agent=api_interaction_agent, expected_output="get all todo items" )
api_crew = Crew( agents=[api_interaction_agent], tasks=[get_all_todos_task], verbose=True )
app = Flask(name)
@app.route('/kickoff', methods=['POST']) def kickoff(): try: print("Starting the Crew...") result = api_crew.kickoff() print("\nCrew Completed!") print("\nFinal Results:") print(result) return 200 except Exception as e: return jsonify({"status": "error", "message": str(e)}), 500
if name == 'main': app.run(debug=True,port=3000, host='0.0.0.0')
@sreanik Can you add the tool as well?
Hi Vidit,
The tool code is shared in the earlier comment along with the logs.
Thanks!
On Fri, 25 Apr 2025 at 6:40 PM, Vidit Ostwal @.***> wrote:
Vidit-Ostwal left a comment (crewAIInc/crewAI#2664) https://github.com/crewAIInc/crewAI/issues/2664#issuecomment-2830391349
@sreanik https://github.com/sreanik Can you add the tool as well?
— Reply to this email directly, view it on GitHub https://github.com/crewAIInc/crewAI/issues/2664#issuecomment-2830391349, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARKUOPYFBI4CBV73LXOEKPT23IX5PAVCNFSM6AAAAAB3UEUIUSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDQMZQGM4TCMZUHE . You are receiving this because you were mentioned.Message ID: @.***>
Hi Vidit,
The tool code is shared in the earlier comment along with the logs.
Thanks! …
On Fri, 25 Apr 2025 at 6:40 PM, Vidit Ostwal @.***> wrote: Vidit-Ostwal left a comment (crewAIInc/crewAI#2664) <#2664 (comment)>
@sreanik https://github.com/sreanik Can you add the tool as well?
— Reply to this email directly, view it on GitHub <#2664 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARKUOPYFBI4CBV73LXOEKPT23IX5PAVCNFSM6AAAAAB3UEUIUSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDQMZQGM4TCMZUHE . You are receiving this because you were mentioned.Message ID: @.***>
Yes, sorry I missed that. Thanks.
@sreanik I'm missing args_schema in your Tool. Could you please try this tutorial? or using the @tool decorator?
@lucasgomide thanks for your response. I had initially tried with the @tool decorator and it had failed.
@lucasgomide thanks for your response. I had initially tried with the @tool decorator and it had failed.
Are you using args_schema this helps generating the type of input response which is required for calling the tool.
@Vidit-Ostwal is this mandatory to be used in the version 0.114.0, asking as it worked without it in 0.108.0.
Tbh, in my opinion no, args schema was the standard way to create the any tool description from the very start.
Still any maintainer from crewai can help on this matter whether this functionality has been changed recently or not.
It's recommend to define it, for sure
@sreanik I just ran your crew using default LLM (gpt-4) and everything works pretty well
I had to modify some parameters on your _run because they are not being used. I removed the task: str
from crewai import Agent, Task, Crew
from crewai.tools import BaseTool
from crewai.llm import LLM
import requests
import json
SAMPLE_API_BASE_URL = "https://jsonplaceholder.typicode.com"
class SampleAPITool(BaseTool):
"""Tool for interacting with the sample JSONPlaceholder API."""
name: str = "sample_api_caller"
description: str = "Useful for fetching or creating sample data using the JSONPlaceholder API."
def _run(self, params: dict) -> str:
"""Executes the API call based on the task and provided arguments."""
try:
print("---------Tool Invoked---------")
endpoint = "/todos"
response = requests.get(f"{SAMPLE_API_BASE_URL}{endpoint}", params=params)
response.raise_for_status()
return json.dumps(response.json(), indent=2)
except requests.exceptions.RequestException as e:
return f"Error communicating with the Sample API: {e}"
except json.JSONDecodeError:
return f"Error decoding JSON response from the Sample API."
except Exception as e:
return f"An unexpected error occurred: {e}"
sample_api_tool = SampleAPITool()
api_interaction_agent = Agent(
role="API User",
goal="Interact with the sample JSONPlaceholder API to retrieve and manage todo items.",
backstory="An expert in consuming RESTful APIs to fetch and manipulate data.",
verbose=True,
allow_delegation=False,
tools=[sample_api_tool],
)
get_all_todos_task = Task(
description="Use the 'sample_api_caller' tool to fetch a list of all todo items from the API.",
agent=api_interaction_agent,
expected_output="get all todo items"
)
api_crew = Crew(
agents=[api_interaction_agent],
tasks=[get_all_todos_task],
verbose=True
)
result = api_crew.kickoff()
print(result)
This is the generated output (running with verbose=True) .. I dropped the JSON to make shorter, but the response.
╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── Crew Execution Started ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ │
│ Crew Execution Started │
│ Name: crew │
│ ID: 28eb69a6-6d92-4272-8b56-31db69d2bccd │
│ │
│ │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
# Agent: API User
## Task: Use the 'sample_api_caller' tool to fetch a list of all todo items from the API.
---------Tool Invoked---------
# Agent: API User
## Thought: I need to fetch a list of all todo items from the JSONPlaceholder API to meet the task requirements.
## Using tool: sample_api_caller
## Tool Input:
"{\"params\": {\"description\": \"Fetch all todo items\", \"type\": \"dict\"}}"
## Tool Output:
[
{
"userId": 1,
"id": 1,
"title": "delectus aut autem",
"completed": false
},
{
"userId": 1,
"id": 2,
"title": "quis ut nam facilis et officia qui",
"completed": false
},
{
"userId": 1,
"id": 3,
"title": "fugiat veniam minus",
"completed": false
},
{
"userId": 1,
"id": 4,
"title": "et porro tempora",
"completed": true
},
{
"userId": 1,
"id": 5,
"title": "laboriosam mollitia et enim quasi adipisci quia provident illum",
"completed": false
},
{
"userId": 1,
"id": 6,
"title": "qui ullam ratione quibusdam voluptatem quia omnis",
"completed": false
},
{
"userId": 1,
"id": 7,
"title": "illo expedita consequatur quia in",
"completed": false
},
{
"userId": 1,
"id": 8,
"title": "quo adipisci enim quam ut ab",
"completed": true
},
{
"userId": 1,
"id": 9,
"title": "molestiae perspiciatis ipsa",
"completed": false
},
{
"userId": 1,
"id": 10,
"title": "illo est ratione doloremque quia maiores aut",
"completed": true
},
{
"userId": 1,
"id": 11,
"title": "vero rerum temporibus dolor",
"completed": true
},
{
"userId": 1,
"id": 12,
"title": "ipsa repellendus fugit nisi",
"completed": true
},
..
]
# Agent: API User
## Final Answer:
[
{
"userId": 1,
"id": 1,
"title": "delectus aut autem",
"completed": false
},
{
"userId": 1,
"id": 2,
"title": "quis ut nam facilis et officia qui",
"completed": false
},
{
"userId": 1,
"id": 3,
"title": "fugiat veniam minus",
"completed": false
},
{
"userId": 1,
"id": 4,
"title": "et porro tempora",
"completed": true
},
{
"userId": 1,
"id": 5,
"title": "laboriosam mollitia et enim quasi adipisci quia provident illum",
"completed": false
},
{
"userId": 1,
"id": 6,
"title": "qui ullam ratione quibusdam voluptatem quia omnis",
"completed": false
},
{
"userId": 1,
"id": 7,
"title": "illo expedita consequatur quia in",
"completed": false
},
{
"userId": 1,
"id": 8,
"title": "quo adipisci enim quam ut ab",
"completed": true
},
{
"userId": 1,
"id": 9,
"title": "molestiae perspiciatis ipsa",
"completed": false
},
{
"userId": 1,
"id": 10,
"title": "illo est ratione doloremque quia maiores aut",
"completed": true
},
{
"userId": 1,
"id": 11,
"title": "vero rerum temporibus dolor",
"completed": true
},
{
"userId": 1,
"id": 12,
"title": "ipsa repellendus fugit nisi",
"completed": true
},
..
]
🚀 Crew: crew
└── 📋 Task: 9c8f9851-ca19-49ad-aca1-a0c2e45c564a
Assigned to: API User
Status: ✅ Completed
└── 🔧 Used sample_api_caller (1)╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── Task Completion ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ │
│ Task Completed │
│ Name: 9c8f9851-ca19-49ad-aca1-a0c2e45c564a │
│ Agent: API User │
│ │
│ │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── Crew Completion ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ │
│ Crew Execution Completed │
│ Name: crew │
│ ID: 28eb69a6-6d92-4272-8b56-31db69d2bccd │
│ │
│ │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Given that I will close this issue, let me know if you still facing this issue