-
Notifications
You must be signed in to change notification settings - Fork 286
[FEATURE] Tool for relative date calculation #422
Description
Problem Statement
Currently, Strands does not any tool for calculating relative dates/time like :
- "what was the date 3 months ago?" or
- "which contract was active(based on data retreived from DB) last year in January?"
In such cases, Strands does not have in-built support and clients have to write their custom tool for relative date calculation.
Proposed Solution
Add a tool say calculate_date which will return the dates in ISO format for cases like :
from strands_tools import calculate_date
# Get today's date (agents should call this instead of guessing)
calculate_date(offset_type="days", offset_value=0)
# → {"date": "2026-03-23"}
# 6 months ago
calculate_date(offset_type="months", offset_value=-6)
# → {"date": "2025-09-23"}
# 90 days from a specific date
calculate_date(offset_type="days", offset_value=90, base_date="2024-01-15")
# → {"date": "2024-04-14"}
Use Case
Analytics/reporting agents ("compare this month vs last month")
Scheduling/calendar agents ("book something 2 weeks from now")
Compliance/audit agents ("show records from the past 90 days")
Financial agents ("what was the rate on January 15 last year?")
Any agent chaining with time-filtered APIs or databases
Alternatives Solutions
No response
Additional Context
Edge Cases Handled
- Month-end clamping: Jan 31 + 1 month → Feb 28 (or 29 in leap years)
- Leap year transitions: Feb 29, 2024 + 1 year → Feb 28, 2025
- Year rollovers: Jan 15 - 2 months → Nov 15 (previous year)
Dependency: python-dateutil (already widely used, handles relativedelta for months/years)
Would fit naturally alongside existing strands_tools like file_read, shell, etc.
We've deployed this in a production Strands agent and validated it handles all the edge cases above
Happy to contribute a PR if the team is open to it