Step 1: Identify the Need for a Tool. Determine what external capability your agent requires. For instance, if an agent needs current market data, a web search tool is necessary. If it needs to send an email, an email client tool is required.
Step 2: Choose or Create the Appropriate Tool. CrewAI provides a growing library of pre-built tools (e.g., TavilySearchTool, SerperDevTool). For unique functionalities, you'll need to create a custom tool by defining a Python function and wrapping it with @tool decorator.
Step 3: Install Required Libraries. If using a pre-built tool, ensure its associated library is installed (e.g., pip install 'crewai[tavily]' for TavilySearchTool). For custom tools, ensure any external dependencies are installed.
Step 4: Configure API Keys (if applicable). Many external tools require API keys for authentication. Store these securely, typically as environment variables (e.g., TAVILY_API_KEY='your_api_key').
Step 5: Import and Initialize the Tool. Import the tool class from crewai_tools (or your custom tool module). Instantiate the tool, passing any necessary parameters during initialization. For TavilySearchTool, you might specify search_depth.
Step 6: Assign the Tool to an Agent. When defining your Agent instance, pass a list of initialized tool objects to the tools parameter. An agent can be assigned multiple tools.
Step 7: Reference the Tool in a Task Description. Within the Task description or expected_output, explicitly instruct the agent to use the tool. For example, 'Use the search tool to find the latest Q3 earnings report for Company X.' The agent's LLM will interpret this instruction and decide when to invoke the assigned tool.
Step 8: Execute the Crew and Observe Tool Usage. Run your Crew and monitor the verbose output. You will see when the agent decides to use a tool, what query it sends, and the output it receives. This allows for debugging and understanding agent decision-making.
Step 9: Refine Tool Parameters and Agent Instructions. Based on observed behavior, adjust tool parameters (e.g., max_results for search) or refine the task description to guide the agent toward more effective tool usage. Ensure the agent's goal and backstory align with its assigned tools.