Skip to main content
Use the @tool decorator to convert any Python function into an agent-callable tool.
from definable.tool.decorator import tool

@tool
def get_weather(city: str) -> str:
    """Get the current weather for a city."""
    return f"Sunny, 72F in {city}"
Definable automatically:
  1. Uses the function name as the tool name.
  2. Parses the docstring as the tool description.
  3. Generates a JSON Schema from type hints.
  4. Makes the tool available to any agent.

Decorator Options

@tool(
    name="weather",                    # Override tool name
    description="Get current weather",  # Override description
    show_result=True,                   # Show result in streaming output
    stop_after_tool_call=True,          # Return immediately after this tool
    instructions="Use for weather queries only.",
)
def get_weather(city: str) -> str:
    """Get current weather for a city."""
    return f"Sunny, 72F in {city}"
OptionTypeDefaultDescription
namestrFunction nameTool name shown to the model
descriptionstrFrom docstringTool description
strictboolFalseStrict parameter validation
instructionsstrNoneUsage instructions added to system prompt
show_resultboolFalseShow result in streaming output
stop_after_tool_callboolFalseStop agent loop after this tool
requires_confirmationboolFalseRequire user confirmation before executing
pre_hookCallableNoneRun before tool execution
post_hookCallableNoneRun after tool execution
cache_resultsboolFalseCache results for identical arguments
cache_ttlint3600Cache TTL in seconds

Learn More

Parameters

Type hints, descriptions, and JSON Schema.

Hooks

Run logic before and after execution.

Caching

Cache results for identical arguments.

Async Tools

Non-blocking I/O operations.

Dependencies

Inject services and state into tools.