Skip to content

Commit 2c8f72f

Browse files
DateFormat_backend
1 parent c1c41ba commit 2c8f72f

File tree

4 files changed

+39
-5
lines changed

4 files changed

+39
-5
lines changed

src/backend/kernel_agents/group_chat_manager.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from context.cosmos_memory_kernel import CosmosMemoryContext
66
from event_utils import track_event_if_configured
77
from kernel_agents.agent_base import BaseAgent
8+
from utils_date import format_date_for_user
89
from models.messages_kernel import (ActionRequest, AgentMessage, AgentType,
910
HumanFeedback, HumanFeedbackStatus, InputTask,
1011
Plan, Step, StepStatus)
@@ -222,7 +223,9 @@ class Step(BaseDataModel):
222223
received_human_feedback_on_step = ""
223224

224225
# Provide generic context to the model
225-
general_information = f"Today's date is {datetime.now().date()}."
226+
current_date = datetime.now().strftime("%Y-%m-%d")
227+
formatted_date = format_date_for_user(current_date)
228+
general_information = f"Today's date is {formatted_date}."
226229

227230
# Get the general background information provided by the user in regards to the overall plan (not the steps) to add as context.
228231
plan = await self._memory_store.get_plan_by_session(

src/backend/kernel_tools/hr_tools.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from models.messages_kernel import AgentType
66
import json
77
from typing import get_type_hints
8+
from utils_date import format_date_for_user
89

910

1011
class HrTools:
@@ -15,12 +16,15 @@ class HrTools:
1516
@staticmethod
1617
@kernel_function(description="Schedule an orientation session for a new employee.")
1718
async def schedule_orientation_session(employee_name: str, date: str) -> str:
19+
formatted_date = format_date_for_user(date)
20+
1821
return (
1922
f"##### Orientation Session Scheduled\n"
2023
f"**Employee Name:** {employee_name}\n"
21-
f"**Date:** {date}\n\n"
24+
f"**Date:** {formatted_date}\n\n"
2225
f"Your orientation session has been successfully scheduled. "
2326
f"Please mark your calendar and be prepared for an informative session.\n"
27+
f"AGENT SUMMARY: I scheduled the orientation session for {employee_name} on {formatted_date}, as part of her onboarding process.\n"
2428
f"{HrTools.formatting_instructions}"
2529
)
2630

src/backend/kernel_tools/product_tools.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from models.messages_kernel import AgentType
1010
import json
1111
from typing import get_type_hints
12+
from utils_date import format_date_for_user
1213

1314

1415
class ProductTools:
@@ -23,10 +24,11 @@ class ProductTools:
2324
async def add_mobile_extras_pack(new_extras_pack_name: str, start_date: str) -> str:
2425
"""Add an extras pack/new product to the mobile plan for the customer. For example, adding a roaming plan to their service. The arguments should include the new_extras_pack_name and the start_date as strings. You must provide the exact plan name, as found using the get_product_info() function."""
2526
formatting_instructions = "Instructions: returning the output of this function call verbatim to the user in markdown. Then write AGENT SUMMARY: and then include a summary of what you did."
27+
formatted_date = format_date_for_user(start_date)
2628
analysis = (
2729
f"# Request to Add Extras Pack to Mobile Plan\n"
2830
f"## New Plan:\n{new_extras_pack_name}\n"
29-
f"## Start Date:\n{start_date}\n\n"
31+
f"## Start Date:\n{formatted_date}\n\n"
3032
f"These changes have been completed and should be reflected in your app in 5-10 minutes."
3133
f"\n\n{formatting_instructions}"
3234
)
@@ -81,7 +83,8 @@ async def get_billing_date() -> str:
8183
now = datetime.now()
8284
start_of_month = datetime(now.year, now.month, 1)
8385
start_of_month_string = start_of_month.strftime("%Y-%m-%d")
84-
return f"## Billing Date\nYour most recent billing date was **{start_of_month_string}**."
86+
formatted_date = format_date_for_user(start_of_month_string)
87+
return f"## Billing Date\nYour most recent billing date was **{formatted_date}**."
8588

8689
@staticmethod
8790
@kernel_function(
@@ -130,7 +133,8 @@ async def update_product_price(product_name: str, price: float) -> str:
130133
@kernel_function(description="Schedule a product launch event on a specific date.")
131134
async def schedule_product_launch(product_name: str, launch_date: str) -> str:
132135
"""Schedule a product launch on a specific date."""
133-
message = f"## Product Launch Scheduled\nProduct **'{product_name}'** launch scheduled on **{launch_date}**."
136+
formatted_date = format_date_for_user(launch_date)
137+
message = f"## Product Launch Scheduled\nProduct **'{product_name}'** launch scheduled on **{formatted_date}**."
134138

135139
return message
136140

src/backend/utils_date.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import locale
2+
from datetime import datetime
3+
import logging
4+
from typing import Optional
5+
6+
def format_date_for_user(date_str: str, user_locale: Optional[str] = None) -> str:
7+
"""
8+
Format date based on user's desktop locale preference.
9+
10+
Args:
11+
date_str (str): Date in ISO format (YYYY-MM-DD).
12+
user_locale (str, optional): User's locale string, e.g., 'en_US', 'en_GB'.
13+
14+
Returns:
15+
str: Formatted date respecting locale or raw date if formatting fails.
16+
"""
17+
try:
18+
date_obj = datetime.strptime(date_str, "%Y-%m-%d")
19+
locale.setlocale(locale.LC_TIME, user_locale or '')
20+
return date_obj.strftime("%B %d, %Y")
21+
except Exception as e:
22+
logging.warning(f"Date formatting failed for '{date_str}': {e}")
23+
return date_str

0 commit comments

Comments
 (0)