Beginner-Friendly Topic
Take your time - it's perfectly normal to re-read this topic 2-3 times. Try the interactive code editor below to run code yourself. Use the Q&A section to check your understanding before moving on.You've got this!
Tools
Tools are the functions that agents call to interact with the real world. Every tool has a name, a description, input parameters, and an output. The agent selects which tool to use based on its goal and current state.
What Is a Tool?
A tool is a function that the agent can call. The agent does not have access to everything on the internet. It can only do what its registered tools allow.
Every tool has:
- A name: how the agent refers to it (e.g. 'web_search')
- A description: what the tool does, in plain language so the controller understands when to use it
- Input parameters: what data the tool needs to run
- Output: what the tool returns after it runs
Tools can be simple (a calculator function) or complex (a full API integration with authentication and error handling).
Tool Definition Example
# Tool definition structure
web_search_tool = {
"name": "web_search",
"description": "Search the web for information about a topic. Use this tool when you need current information that is not already in the agent state.",
"parameters": {
"query": {
"type": "string",
"description": "The search query to send to the search engine",
"required": True
},
"max_results": {
"type": "integer",
"description": "Maximum number of results to return",
"default": 5
}
},
"returns": "List of search results with title, URL, and snippet"
}
# The controller (language model) reads this definition
# and knows when and how to use the tool
print("Tool registered:", web_search_tool["name"])
print("Description:", web_search_tool["description"])