Local tools allow agents to call Python functions during conversations. Define functions, add them to agents, and the agent will execute them when needed.
The simplest way to add tools is to pass a function directly:
from lyzr import Studiostudio = Studio(api_key="your-api-key")# Define a function with type hints and docstringdef get_weather(city: str) -> str: """Get current weather for a city""" # Your implementation return f"Weather in {city}: Sunny, 72°F"def search_products(query: str, limit: int = 10) -> list: """Search products by query""" # Your implementation return [{"name": "Product A", "price": 29.99}]# Create agentagent = studio.create_agent( name="Assistant", provider="gpt-4o", role="Helpful assistant", goal="Help users with various tasks")# Add functions as tools - SDK auto-infers parameters from type hintsagent.add_tool(get_weather)agent.add_tool(search_products)# Run - agent will call the functions when neededresponse = agent.run("What's the weather in Tokyo?")print(response.response) # Uses get_weather("Tokyo") internally
When passing a function directly, the ADK automatically infers the tool name, description (from docstring), and parameters (from type hints).
def calculate_tip(bill: float, percentage: int = 18) -> float: """Calculate tip amount for a bill""" return bill * percentage / 100agent.add_tool(calculate_tip)
from lyzr.tools import Tooldef get_weather(city: str) -> str: """Get weather for a city""" return f"Weather in {city}: Sunny, 72°F"weather_tool = Tool( name="get_weather", description="Get current weather for a city. Returns temperature and conditions.", parameters={ "type": "object", "properties": { "city": {"type": "string", "description": "City name (e.g., Tokyo, New York)"} }, "required": ["city"] }, function=get_weather)agent.add_tool(weather_tool)
from lyzr.tools import Tooltool = Tool( name="unique_name", # Unique identifier description="What it does", # For LLM understanding parameters={...}, # JSON schema for inputs function=my_function # Python function to call)
from lyzr.tools import ToolRegistryregistry = ToolRegistry()registry.add(tool1)registry.add(tool2)# List all toolsfor tool in registry.list(): print(tool.name)