ExaSearchTool - Unable to get it configured

Hi, can anyone help me with a simple code snippet to get CrewAI’s ExaSearchTool to work. I am really struggling use the BaseModel and the decorator approach and can’t figure it out.

Btw. I have tried this code snippet but the Crew agent keeps gettng the structure of the call to Exa_search wrong: from crewai_tools import tool
from exa_py import Exa
import os
from typing import Union, Dict, Any

@tool
def exa_search(query: str) → str:
“”"
Search the web using EXA API with optimized search parameters.
“”"
try:
# Execute search
api_key = os.getenv(“EXA_API_KEY”)
if not api_key:
return “Error: EXA API key not found in environment variables”

    exa = Exa(api_key=api_key)
    response = exa.search_and_contents(
        query=query,
        num_results=5,
        use_autoprompt=True,
        type="auto",
        text=True,
        highlights=True,
        summary=True
    )

    # Format results
    formatted_results = []
    for result in response.results:
        sections = [
            f"Title: {result.title or 'No title available'}",
            f"Link: {result.url}",
            "Snippet:"
        ]

        if hasattr(result, 'summary') and result.summary:
            sections.append("\nSummary:")
            sections.append(f"  {result.summary}")

        if hasattr(result, 'highlights') and result.highlights:
            sections.append("\nKey Points:")
            for highlight in result.highlights:
                sections.append(f"  • {highlight}")

        formatted_results.append("\n".join(sections) + "\n\n---\n")

    return "\n".join(formatted_results)

except Exception as e:
    return f"Error: {str(e)}"

exa didnt work for me too it doesnt even recognize the exa_py in the import

Try closing and reopening your IDE. This often resolves errors with unrecognized installed packages.