"""Simple Tools Demo - Custom Python Functions as Tools"""
import os
from datetime import datetime
from kuralit.server.agent_session import AgentSession
from kuralit.server.websocket_server import create_app
from kuralit.tools import Toolkit
# Define custom tool functions
def calculate(expression: str) -> str:
"""Calculate a mathematical expression."""
try:
result = eval(expression)
return str(result)
except Exception as e:
return f"Error: {str(e)}"
def get_current_time() -> str:
"""Get the current time."""
now = datetime.now()
return now.strftime("%H:%M:%S")
def get_weather(location: str) -> str:
"""Get weather information for a location."""
mock_weather = {
"london": "Cloudy, 15°C",
"new york": "Sunny, 22°C",
}
return f"Weather in {location}: {mock_weather.get(location.lower(), 'Partly cloudy, 20°C')}"
def convert_currency(amount: float, from_currency: str, to_currency: str) -> str:
"""Convert currency from one type to another."""
exchange_rates = {
"USD": {"EUR": 0.85, "GBP": 0.73},
"EUR": {"USD": 1.18, "GBP": 0.86},
}
# Implementation here...
return f"{amount} {from_currency} = {converted} {to_currency}"
# Create toolkit
utility_tools = Toolkit(
name="utility_tools",
tools=[calculate, get_current_time, get_weather, convert_currency],
instructions="Utility tools for calculations, time, weather, and currency conversion."
)
# Create agent with tools
agent_session = AgentSession(
stt="deepgram/nova-2:en-US",
llm="gemini/gemini-2.0-flash-001",
vad="silero/v3",
turn_detection="multilingual/v1",
tools=[utility_tools],
instructions="You are a helpful assistant with utility tools.",
)
# Create and run server
app = create_app(
api_key_validator=lambda key: key == "demo-key",
agent_session=agent_session,
)