Hey folks, hit another migration snag, but this time it's not between CRMs... it's inside CrewAI itself. I feel like I'm back trying to get Zoho to talk to Salesforce via a wonky middleware again. 😅
I've been building a crew to automate some lead enrichment, pulling data from a few sources. I have a custom tool I wrote—it's simple, it fetches company details from an external API. I've tested it in isolation, and it works perfectly every time. I can run it from a script, no errors, returns the JSON data I expect.
But when I assign it to an agent and kick off the task, I consistently get that dreaded `'Agent failed to execute tool'` error. The logs aren't super helpful; they just state the failure without the underlying exception. I've triple-checked the obvious:
* The tool is correctly defined and decorated with `@tool`.
* It's properly passed to the agent in the `tools` list.
* The function signature is simple, with clear docstrings for the LLM.
* No async weirdness—it's a standard function.
Here's a simplified version of my setup. The agent is defined to use this tool for its task:
```python
# This is the tool that works in isolation but fails in the agent
@tool("fetch_company_profile")
def fetch_company_profile(company_name: str) -> str:
"""Fetches the company profile and key details for a given company name."""
# My actual API call logic here, which works fine
data = make_api_call(company_name)
return json.dumps(data)
# Agent creation
researcher = Agent(
role='Company Researcher',
goal='Find detailed information about companies',
backstory='You are a meticulous research assistant.',
tools=[fetch_company_profile],
verbose=True
)
```
The task is straightforward: "Research {company_name}." The agent thinks, decides to use the tool, and then... failure. No output from the tool itself in the logs, just the execution error.
Has anyone else fought this battle? I'm getting serious flashbacks to mapping custom fields in HubSpot only for them to vanish during the sync. I'm wondering:
* Is there a common pitfall with how CrewAI's LLM interprets the tool's description versus its actual input?
* Could it be a memory/context issue where the agent isn't formatting the input argument correctly for the function?
* Are there specific logging flags to surface the *real* Python error hiding behind this generic message?
Any war stories or debugging tips would be a lifesaver. I really don't want to have to scrap this crew and "migrate" to a different framework—I've done enough of that this year already!
Hopefully last migration,
The logs being unhelpful is the real killer here. CrewAI's error handling can swallow exceptions, especially from custom tools. You need to force it to cough up the real traceback.
Wrap your tool function in a try-except that logs the full exception, or even better, use `logging.exception` inside the tool. Like this:
```python
import logging
@tool
def fetch_company_details(query: str) -> str:
try:
# your API call here
return result
except Exception as e:
logging.exception(f"Tool failed internally: {e}")
raise # Re-raise so CrewAI still sees a failure
```
Nine times out of ten, it's something the agent is passing to your tool that you didn't expect - a malformed string, a None, or the LLM is calling it with arguments your function signature doesn't accept. The isolation test proves the tool's logic, not its integration with the agent's reasoning layer.