Time Tool¶
The CurrentTimeTool provides time-related operations and utilities for agents in the Bedrock Swarm framework. It handles current time retrieval, timezone conversions, and time offsets.
Class Documentation¶
Bases: BaseTool
Tool for getting current time and calculating future times.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Name of the tool
TYPE:
|
description
|
Description of the tool
TYPE:
|
Source code in src/bedrock_swarm/tools/time.py
Attributes¶
name: str
property
¶
Get tool name.
description: str
property
¶
Get tool description.
Functions¶
get_schema() -> Dict[str, Any]
¶
Get JSON schema for the time tool.
Source code in src/bedrock_swarm/tools/time.py
_normalize_timezone(timezone: str) -> str
¶
Normalize timezone name.
| PARAMETER | DESCRIPTION |
|---|---|
timezone
|
Timezone name to normalize
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Normalized timezone name |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If timezone is invalid |
Source code in src/bedrock_swarm/tools/time.py
_execute_impl(*, timezone: Optional[str] = None, minutes_offset: Optional[int] = None, **kwargs: Any) -> str
¶
Execute the time tool.
| PARAMETER | DESCRIPTION |
|---|---|
timezone
|
Timezone to get time in (defaults to local timezone)
TYPE:
|
minutes_offset
|
Optional number of minutes to add to current time
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Current or future time in specified timezone |
Source code in src/bedrock_swarm/tools/time.py
Features¶
The time tool provides:
- Current time operations:
- Get current time in any timezone
- Support for timezone aliases (EST, PST, etc.)
-
Optional time offset in minutes
-
Time formatting:
- ISO-like format (YYYY-MM-DD HH:MM:SS TZ)
-
Timezone information included
-
Timezone handling:
- Support for all IANA timezone names
- Common timezone aliases
- Flexible timezone name matching
Usage Examples¶
from bedrock_swarm.tools import CurrentTimeTool
# Initialize the tool
time_tool = CurrentTimeTool()
# Get current time in local timezone
result = time_tool.execute()
print(result) # Output: 2024-02-29 15:30:45 PST
# Get current time in UTC
result = time_tool.execute(timezone="UTC")
print(result) # Output: 2024-02-29 23:30:45 UTC
# Get time with offset
result = time_tool.execute(timezone="EST", minutes_offset=30)
print(result) # Output: 2024-02-29 18:00:45 EST
# Using timezone aliases
result = time_tool.execute(timezone="PST") # Automatically maps to America/Los_Angeles
print(result) # Output: 2024-02-29 15:30:45 PST
Error Handling¶
The time tool handles various error cases:
- Invalid timezone names
- Timezone conversion errors
- Invalid time offsets
- General execution errors
Implementation Details¶
The time tool:
- Uses Python's
datetimeandzoneinfolibraries - Supports all IANA timezone names
- Provides common timezone aliases
- Includes timezone name normalization
- Handles timezone-aware datetime objects