AI Model Wiki

    Skip to main content
    40 min
    Lesson 2 of 5

    Tools & Agent Capabilities

    From the course CrewAI: Multi-Agent Frameworks

    Equipping Agents with Tools

    Built-in Tools

    from crewai_tools import SerperDevTool, ScrapeWebsiteTool, FileReadTool
    
    search_tool = SerperDevTool()
    scrape_tool = ScrapeWebsiteTool()
    file_tool = FileReadTool()
    
    agent = Agent(
        role="Researcher",
        goal="Find accurate information",
        tools=[search_tool, scrape_tool, file_tool],
    )
    

    Custom Tools

    from crewai.tools import tool
    
    @tool("Database Query")
    def query_database(sql: str) -> str:
        """Execute a SQL query against the analytics database.
        Use this to retrieve data about users, orders, or products."""
        return execute_query(sql)
    
    agent = Agent(
        role="Data Analyst",
        tools=[query_database],
    )
    

    Tool Design Principles

    • Clear descriptions — agents use the docstring to decide when to use a tool
    • Specific inputs — define parameter types and constraints
    • Useful outputs — return structured, actionable data
    • Error messages — return helpful errors, not stack traces

    Agent Configuration

    Fine-tune agent behavior:

    • allow_delegation: Let agents pass tasks to other agents
    • max_iter: Maximum reasoning iterations before stopping
    • max_rpm: Rate limit for API calls
    • memory: Enable conversation memory across tasks

    Common Pitfall: Missing Tool Docstrings

    Agents use the tool's docstring to decide when and how to use it. A tool with no docstring or a vague docstring like """Use this tool.""" will be called incorrectly or not at all. Write docstrings that answer three questions: What does it do? What inputs does it expect? What does it return?

    @tool("Search Company Database")
    def search_companies(name: str) -> str:
        """
        Search the internal company database for organizations matching the given name.
        Input: A company name or partial name (e.g. 'Google', 'Open').
        Returns: A JSON list of matching companies with fields: id, name, industry, revenue_usd.
        Use this when the user mentions a specific company and you need its financial details.
        """
        return query_db(f"SELECT * FROM companies WHERE name ILIKE '%{name}%'")
    

    Best Practice: Log Task Outputs for Debugging

    Crew task outputs are available after crew.kickoff() completes via the output attribute of each task:

    result = crew.kickoff()
    for task in crew.tasks:
        print(f"--- {task.description[:50]} ---")
        print(task.output.raw)
        print()
    

    This makes it easy to identify which agent produced a poor result without re-running the entire crew.

    Named Product Reference: Groq for Fast CrewAI Inference

    CrewAI supports any LangChain-compatible LLM. Groq's inference API (groq.com) runs open-weight models like Llama 3.1 at speeds of 300–800 tokens/second — 10x faster than standard GPU inference. For CrewAI workflows where multiple agents take many turns, Groq's speed dramatically reduces wall-clock time. Use it by setting llm="groq/llama-3.1-70b-versatile" in agent configuration.

    Key Takeaways

    • •Agents use tools based on their descriptions and the task requirements
    • •Custom tools connect agents to databases, APIs, and external systems
    • •Clear tool descriptions are critical for correct tool selection
    • •Configure delegation, iteration limits, and memory per agent
    0 of 5 lessons marked complete

    Progress is kept in this browser only.