peargent.

Tools

Enable agents to perform actions beyond text generation with tools.

Tools are actions that agents can perform to interact with the real world. They allow agents to go beyond text generation by enabling operations such as querying databases, calling APIs, performing calculations, reading files, or executing any Python function you define.

Think of tools as the hands and eyes of your agent, while the model provides the reasoning (the brain). Tools give the agent the ability to actually act and produce real results.

When you create an Agent, you pass in a list of available Tools, and during execution the agent decides whether a tool is needed and invokes it automatically based on the model’s response.

Creating a Tool

Use create_tool() to wrap a Python function into a tool that an agent can call. Every tool must define a name, description, input_parameters, and a call_function. The call_function is the underlying Python function that will be executed when the agent invokes the tool.

Below is a simple example tool that converts Celsius to Fahrenheit:

from peargent import create_tool

def celsius_to_fahrenheit(c: float):
    return (c * 9/5) + 32

temperature_tool = create_tool(
    name="CelsiusToFahrenheit",
    description="Convert Celsius temperature to Fahrenheit",
    call_function=celsius_to_fahrenheit,
    input_parameters={"c": float}, # Important 
    output_schema=float
)

Input Parameters Matter

The input_parameters serve two critical purposes:

  1. Type Validation - Peargent validates that the LLM provides the correct types before executing your function, preventing runtime errors
  2. LLM Guidance - The parameter types help the LLM understand what arguments to provide when calling the tool

Using Tools with Agents

Tools can be passed to an agent during creation. The agent will automatically decide when a tool is needed and call it as part of its reasoning process.

from peargent import create_agent
from peargent.models import openai

agent = create_agent(
    name="UtilityAgent",
    description="Handles multiple utility tasks",
    persona="You are a helpful assistant.",
    model=openai("gpt-5"),
    tools=[ # You can pass one or multiple tools here
      temperature_tool, 
      count_words_tool, 
      summary_tool] 
)

response = agent.run("Convert 25 degrees Celsius to Fahrenheit.")
# Agent automatically calls the tool and uses the result

Parameters

ParameterTypeDescriptionRequired
namestrTool identifierYes
descriptionstrWhat the tool does (helps LLM decide when to use it)Yes
input_parametersdict[str, type]Parameter names and types (e.g., {"city": str})Yes
call_functionCallableThe Python function to executeYes
timeoutfloat | NoneMax execution time in seconds (default: None)No
max_retriesintRetry attempts on failure (default: 0)No
retry_delayfloatInitial delay between retries in seconds (default: 1.0)No
retry_backoffboolUse exponential backoff (default: True)No
on_errorstrError handling: "raise", "return_error", or "return_none" (default: "raise")No
output_schemaType[BaseModel]Pydantic model for output validationNo

For advanced configuration like timeouts, retries, error-handling, and output validation, see the Advanced Features.