Spaces:
Runtime error
Runtime error
File size: 1,340 Bytes
465fb49 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
from agentpro.tools import Tool
from typing import Any
import datetime
import pytz
class CurrentDateTimeTool(Tool):
# 1) Class attributes (Pydantic fields)
name: str = "Current DateTime"
description: str = "Get the current day, time, year, and month"
action_type: str = "current_date_time_pst"
input_format: str = "Any input; this tool returns the current date/time."
def run(self, input_text: Any) -> str:
"""
Ignores the input_text and returns:
• Current weekday name (e.g., Monday)
• Current time (HH:MM:SS) in Pakistan Standard Time
• Current year (YYYY)
• Current month name (e.g., June)
"""
now_pkt = datetime.datetime.now()
weekday = now_pkt.strftime("%A") # e.g., "Friday"
time_str = now_pkt.strftime("%I:%M %p") # e.g., "07:45 PM"
year_str = now_pkt.strftime("%Y") # e.g., "2025"
month = now_pkt.strftime("%B") # e.g., "June"
date_str = now_pkt.strftime("%d %B %Y") # e.g., "05 June 2025"
return (
f"Day of week: {weekday}\n"
f"Current time: {time_str}\n"
f"Date: {date_str}\n"
f"Year: {year_str}\n"
f"Month: {month}"
) |