While the LLM is a powerful reasoning engine, it has significant limitations. By itself, an LLM is a closed system; it cannot access real-time information from the web, perform precise mathematical calculations, execute code, or interact with external APIs. To overcome these limitations and build truly capable agents, agents are equipped with tools.
A tool is simply a function that an agent can decide to call to perform a specific action. This could be anything from a simple calculator to a complex integration with a company's internal database. By providing an agent with a set of tools, you give it the ability to interact with the external environment, gather information, and perform actions to achieve its goal. The LLM's role shifts from trying to know the answer to knowing how to find the answer.
In the Kerb toolkit, a tool is more than just a Python function. It's a structured object that provides the LLM with all the necessary information to understand and use it effectively. Each tool consists of several important components:
calculator, web_search). The LLM uses this name to specify which tool it wants to use.Action Input correctly.There are two primary ways to define a tool: using the Tool class directly or with the create_tool helper function. Let's start with the Tool class to build a simple calculator.
First, define the Python function that will perform the work:
def calculate(expression: str) -> str:
"""A simple calculator tool."""
try:
# Using eval() for simplicity, but use safer methods in production
result = eval(expression)
return f"Result: {result}"
except Exception as e:
return f"Error: {str(e)}"
Next, wrap this function in a Tool object. This provides the necessary metadata for the agent's LLM to understand how to use it.
from kerb.agent import Tool
calc_tool = Tool(
name="calculator",
description="Performs mathematical calculations on a given expression. Use this for any math-related questions.",
func=calculate,
parameters={
"expression": {
"type": "string",
"description": "The mathematical expression to evaluate (e.g., '15 * 7')."
}
}
)
Notice how the description is written for the LLM. It clearly states the tool's purpose ("Performs mathematical calculations") and provides guidance on when to use it ("Use this for any math-related questions"). The parameters dictionary defines the input expression that the calculate function expects.
create_tool HelperFor a more concise way to define tools, you can use the create_tool function. It achieves the same result with a slightly simpler syntax. Let's define another tool, this time for a mock web search.
from kerb.agent import create_tool
def search(query: str) -> str:
"""A mock search tool."""
# In a real application, this would call a search API
if "python" in query.lower():
return "Python is a high-level programming language."
return f"No results found for: {query}"
search_tool = create_tool(
name="search",
description="Searches for information on a given topic. Use this to find up-to-date information.",
func=search,
parameters={
"query": {
"type": "string",
"description": "The topic or question to search for."
}
}
)
Both Tool(...) and create_tool(...) produce the same type of object that can be passed to an agent. Choose the one that best fits your coding style.
Once you have defined your tools, you need to make the agent aware of them. You do this by passing a list of Tool objects to the agent's constructor.
from kerb.agent.patterns import ReActAgent
# A mock LLM function for demonstration
def mock_llm_react(prompt: str) -> str:
if "calculate 15 * 7" in prompt:
return """Thought: I need to calculate 15 multiplied by 7. I should use the calculator tool.
Action: calculator
Action Input: 15 * 7"""
elif "105" in prompt:
return """Thought: I have the result of the calculation. I can now provide the final answer.
Final Answer: The result of 15 * 7 is 105."""
else:
return "Thought: I will think about this. \nFinal Answer: I am not sure what to do."
# Create an agent and provide it with the tools we defined
agent = ReActAgent(
name="MathAgent",
llm_func=mock_llm_react,
tools=[calc_tool, search_tool],
max_iterations=5
)
print(f"Agent created with tools: {[t.name for t in agent.tools]}")
When the ReActAgent is initialized, it incorporates the names and descriptions of the provided tools into its internal system prompt. This allows the LLM, on each reasoning step, to see the available tools and decide if one of them can help achieve the user's goal.
With the agent equipped with tools, let's trace the full execution loop for a goal like "What is 15 * 7?".
goal = "What is 15 * 7?"
result = agent.run(goal)
# Display the ReAct loop
for i, step in enumerate(result.steps, 1):
print(f"\n[Step {i}]")
if step.thought:
print(f"Thought: {step.thought}")
if step.action:
# The agent framework parses 'calculator' as the action
print(f"Action: {step.action}({step.action_input})")
if step.observation:
# The observation is the output of the calculate() function
print(f"Observation: {step.observation}")
print(f"\nFinal Answer: {result.output}")
This interaction unfolds as follows:
llm_func receives a prompt containing the goal and the definitions of the calculator and search tools. The LLM reasons that the calculator tool is appropriate and formulates a plan. It outputs its thought: "I need to calculate 15 multiplied by 7. I should use the calculator tool."Action: calculator with Action Input: 15 * 7.calculator as the tool to run and "15 * 7" as the input. It then calls our Python function: calculate("15 * 7").calculate function executes eval("15 * 7"), which returns 105. The agent captures this return value as the observation for this step.This loop of thought, action, and observation is the fundamental mechanism that allows agents to extend their capabilities far past the inherent knowledge of the LLM itself.
How you design your tools has a significant impact on your agent's performance.
description is your primary way of communicating with the LLM. Write clear, unambiguous descriptions that explain what the tool does, what it's good for, and any important constraints. For example, for a search tool, a good description might be "Searches for real-time information on public websites. Best for recent events, news, and general knowledge questions."search_web and read_file than using a single research_and_summarize_topic tool.Was this section helpful?
© 2026 ApX Machine LearningEngineered with