Skip to main content
The Function class represents a tool that can be called by an agent. It includes the function definition, parameters, hooks, and execution logic.

Core Fields

name
str
required
Name of the function (must be a-z, A-Z, 0-9, underscores, or dashes, max 64 chars).
description
str
default:"None"
Description of what the function does, used by the model to choose when to call it.
parameters
Dict[str, Any]
JSON Schema object describing function parameters.
strict
bool
default:"None"
Enable strict schema validation (for structured outputs).
entrypoint
Callable
default:"None"
The actual function to be called.

Instructions

instructions
str
default:"None"
Additional instructions for using the function.
add_instructions
bool
default:"True"
If True, adds instructions to the agent’s system message.

Display & Control

show_result
bool
default:"False"
If True, the function call result is shown along with sending it to the model.
stop_after_tool_call
bool
default:"False"
If True, the agent stops after executing this function.

Hooks

pre_hook
Callable
default:"None"
Hook that runs before the function is executed.
post_hook
Callable
default:"None"
Hook that runs after the function is executed (success or failure).
tool_hooks
List[Callable]
default:"None"
List of hooks to run around tool calls as middleware.

HITL (Human-in-the-Loop)

requires_confirmation
bool
default:"None"
If True, requires user confirmation before execution.
requires_user_input
bool
default:"None"
If True, requires user input before execution.
user_input_fields
List[str]
default:"None"
List of fields that should be provided by the user.
external_execution
bool
default:"None"
If True, the function will be executed outside the agent’s control.
approval_type
str
default:"None"
Approval type: “required” (blocking) or “audit” (non-blocking).

Caching

cache_results
bool
default:"False"
Enable result caching.
cache_dir
str
default:"None"
Directory to store cache files.
cache_ttl
int
default:"3600"
Cache time-to-live in seconds.

Methods

from_callable()

Create a Function from a callable.
from agno.tools.function import Function

def my_tool(query: str) -> str:
    """Search for information."""
    return f"Results for {query}"

func = Function.from_callable(my_tool)

to_dict()

Serialize function to dictionary.
data = function.to_dict()

from_dict()

Deserialize function from dictionary.
function = Function.from_dict(data)

FunctionCall

Represents an instance of a function being called.

Methods

execute()

Execute the function call synchronously.
result = function_call.execute()

aexecute()

Execute the function call asynchronously.
result = await function_call.aexecute()

Example Usage

from agno.tools.function import Function

def get_weather(city: str) -> str:
    """Get the weather for a city.
    
    Args:
        city: The name of the city
    """
    return f"Weather in {city}: Sunny, 72°F"

func = Function.from_callable(get_weather)

Build docs developers (and LLMs) love