diff --git a/src/backend/kernel_agents/group_chat_manager.py b/src/backend/kernel_agents/group_chat_manager.py index 69abae8c5..19215c34c 100644 --- a/src/backend/kernel_agents/group_chat_manager.py +++ b/src/backend/kernel_agents/group_chat_manager.py @@ -5,6 +5,7 @@ from context.cosmos_memory_kernel import CosmosMemoryContext from event_utils import track_event_if_configured from kernel_agents.agent_base import BaseAgent +from utils_date import format_date_for_user from models.messages_kernel import (ActionRequest, AgentMessage, AgentType, HumanFeedback, HumanFeedbackStatus, InputTask, Plan, Step, StepStatus) @@ -222,7 +223,9 @@ class Step(BaseDataModel): received_human_feedback_on_step = "" # Provide generic context to the model - general_information = f"Today's date is {datetime.now().date()}." + current_date = datetime.now().strftime("%Y-%m-%d") + formatted_date = format_date_for_user(current_date) + general_information = f"Today's date is {formatted_date}." # Get the general background information provided by the user in regards to the overall plan (not the steps) to add as context. plan = await self._memory_store.get_plan_by_session( diff --git a/src/backend/kernel_tools/hr_tools.py b/src/backend/kernel_tools/hr_tools.py index 7eb74c4f4..9951c0a1a 100644 --- a/src/backend/kernel_tools/hr_tools.py +++ b/src/backend/kernel_tools/hr_tools.py @@ -5,6 +5,7 @@ from models.messages_kernel import AgentType import json from typing import get_type_hints +from utils_date import format_date_for_user class HrTools: @@ -15,12 +16,15 @@ class HrTools: @staticmethod @kernel_function(description="Schedule an orientation session for a new employee.") async def schedule_orientation_session(employee_name: str, date: str) -> str: + formatted_date = format_date_for_user(date) + return ( f"##### Orientation Session Scheduled\n" f"**Employee Name:** {employee_name}\n" - f"**Date:** {date}\n\n" + f"**Date:** {formatted_date}\n\n" f"Your orientation session has been successfully scheduled. " f"Please mark your calendar and be prepared for an informative session.\n" + f"AGENT SUMMARY: I scheduled the orientation session for {employee_name} on {formatted_date}, as part of her onboarding process.\n" f"{HrTools.formatting_instructions}" ) diff --git a/src/backend/kernel_tools/product_tools.py b/src/backend/kernel_tools/product_tools.py index 5a30dee34..b5c119b76 100644 --- a/src/backend/kernel_tools/product_tools.py +++ b/src/backend/kernel_tools/product_tools.py @@ -9,6 +9,7 @@ from models.messages_kernel import AgentType import json from typing import get_type_hints +from utils_date import format_date_for_user class ProductTools: @@ -23,10 +24,11 @@ class ProductTools: async def add_mobile_extras_pack(new_extras_pack_name: str, start_date: str) -> str: """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.""" 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." + formatted_date = format_date_for_user(start_date) analysis = ( f"# Request to Add Extras Pack to Mobile Plan\n" f"## New Plan:\n{new_extras_pack_name}\n" - f"## Start Date:\n{start_date}\n\n" + f"## Start Date:\n{formatted_date}\n\n" f"These changes have been completed and should be reflected in your app in 5-10 minutes." f"\n\n{formatting_instructions}" ) @@ -81,7 +83,8 @@ async def get_billing_date() -> str: now = datetime.now() start_of_month = datetime(now.year, now.month, 1) start_of_month_string = start_of_month.strftime("%Y-%m-%d") - return f"## Billing Date\nYour most recent billing date was **{start_of_month_string}**." + formatted_date = format_date_for_user(start_of_month_string) + return f"## Billing Date\nYour most recent billing date was **{formatted_date}**." @staticmethod @kernel_function( @@ -130,7 +133,8 @@ async def update_product_price(product_name: str, price: float) -> str: @kernel_function(description="Schedule a product launch event on a specific date.") async def schedule_product_launch(product_name: str, launch_date: str) -> str: """Schedule a product launch on a specific date.""" - message = f"## Product Launch Scheduled\nProduct **'{product_name}'** launch scheduled on **{launch_date}**." + formatted_date = format_date_for_user(launch_date) + message = f"## Product Launch Scheduled\nProduct **'{product_name}'** launch scheduled on **{formatted_date}**." return message diff --git a/src/backend/utils_date.py b/src/backend/utils_date.py new file mode 100644 index 000000000..d346e3cd0 --- /dev/null +++ b/src/backend/utils_date.py @@ -0,0 +1,24 @@ +import locale +from datetime import datetime +import logging +from typing import Optional + + +def format_date_for_user(date_str: str, user_locale: Optional[str] = None) -> str: + """ + Format date based on user's desktop locale preference. + + Args: + date_str (str): Date in ISO format (YYYY-MM-DD). + user_locale (str, optional): User's locale string, e.g., 'en_US', 'en_GB'. + + Returns: + str: Formatted date respecting locale or raw date if formatting fails. + """ + try: + date_obj = datetime.strptime(date_str, "%Y-%m-%d") + locale.setlocale(locale.LC_TIME, user_locale or '') + return date_obj.strftime("%B %d, %Y") + except Exception as e: + logging.warning(f"Date formatting failed for '{date_str}': {e}") + return date_str