CrewAICrewAI 1.15 · Python 3.10 to 3.13
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
32 small wins to finish your pathNext lesson

Tools: functions an agent can use

A tool is a Python function with a name, a description and a schema for its arguments. The model never runs it; it asks for it by name, and CrewAI runs it.

Lesson 2's clerk looked orders up in a dictionary. That lookup becomes a tool, so an agent can use it.

Exampletools.py
from crewai.tools import tool

ORDERS = {"A17": "shipped on 3 March", "C40": "waiting for stock"}


@tool
def lookup_order(order_id: str) -> str:
    """Look up an order's shipping status by its id, such as A17."""
    status = ORDERS.get(order_id)
    return f"{order_id} {status}." if status else f"{order_id} is not an order we have."

@tool from crewai.tools turns the function into a tool object. It takes the name from the function, the description from the docstring, and the argument types from the type hints.

What the model is told

Example
from tools import lookup_order

print(lookup_order.name)
print(lookup_order.description)
print(lookup_order.args_schema.model_json_schema()["properties"])

This is everything a model learns about the tool. The docstring is how it decides when to use it, so it says what the tool does and what an order id looks like. The schema says to send one string called order_id.

Running a tool yourself

Example
from tools import lookup_order

print(lookup_order.run(order_id="A17"))
print(lookup_order.run(order_id="B22"))

run calls the function with keyword arguments, the way CrewAI will. B22 is not in the dictionary, so the tool says so in words a model can pass on.

A tool without a docstring

Example
from crewai.tools import tool


@tool
def lookup_order(order_id: str) -> str:
    return "unknown"

A tool with no description is refused when it is defined. Without one, a model would have nothing to decide with.

Save tools.py. Lesson 9 gives the tool to an agent, and lesson 12 adds a second tool to the file.

Try it yourself
  • Pass a name, @tool("Order lookup"), and print lookup_order.name.
  • Add a second argument, customer: str, and print the schema again.
  • Remove the type hint from order_id and print the schema.

Slow is fine. Stopping is the only problem.