Tools

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Decision-making is great, but that’s only half of the story. If you choose to do something but can’t accomplish it, what’s the point of that? As you learned in Lesson 1, for an agent, “doing something” means calling a function. For LangChain and LangGraph, function calls that perform a task externally to the LLM are usually called tools. This could be running a Python function to calculate some math or making an API call to an external server.

Prebuilt Tools

The LangChain and LangGraph community have already built many tools. Here are a few category examples:

import some_tool

tool = SomeTool()
llm.bind_tools([tool])

Creating Tools

It isn’t difficult to create your own tool, either. LangGraph just needs to know the following details:

@tool
def count_characters(text: str) -> int:
  """Counts the number of characters in the text"""
  return len(text)
llm.bind_tools([count_characters])

Using Tools in a Graph

A convenient way to incorporate a tool in a graph is to use a ToolNode:

graph.add_node("tools", ToolNode([tool]))
See forum comments
Download course materials from Github
Previous: Decision Making Demo Next: Tools Demo