mirror of
https://github.com/temporal-community/temporal-ai-agent.git
synced 2026-03-15 14:08:08 +01:00
Add functionality to future_pto_calc, remove calendar_conflict step from goal
This commit is contained in:
@@ -9,7 +9,7 @@ The agent is set up to allow for multiple goals and to switch back to choosing a
|
||||
- `agent_name`: user-facing name for the agent/chatbot
|
||||
- `agent_friendly_description`: user-facing description of what the agent/chatbot does
|
||||
- `tools`: the list of tools the goal will walk the user through.
|
||||
- Important! The last tool listed must be `list_agents_tool`
|
||||
- Important! The last tool listed must be `list_agents_tool`. This allows the AI to let the user go back to choosing from the list of available goals.
|
||||
- `description`:
|
||||
- `starter-prompt`:
|
||||
- `example_conversation_history`:
|
||||
|
||||
@@ -10,7 +10,6 @@ from .transfer_control import transfer_control
|
||||
|
||||
from .current_pto import current_pto
|
||||
from .book_pto import book_pto
|
||||
from .calendar_conflict import calendar_conflict
|
||||
from .future_pto_calc import future_pto_calc
|
||||
|
||||
|
||||
@@ -37,8 +36,6 @@ def get_handler(tool_name: str):
|
||||
return current_pto
|
||||
if tool_name == "BookPTO":
|
||||
return book_pto
|
||||
if tool_name == "CalendarConflict":
|
||||
return calendar_conflict
|
||||
if tool_name == "FuturePTOCalc":
|
||||
return future_pto_calc
|
||||
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
def calendar_conflict(args: dict) -> dict:
|
||||
|
||||
check_self = args.get("check_self_calendar")
|
||||
check_team = args.get("check_team_calendar")
|
||||
|
||||
conflict_list = []
|
||||
conflict = {
|
||||
"calendar": "self",
|
||||
"title": "Meeting with Karen",
|
||||
"date": "2025-12-02",
|
||||
"time": "10:00AM",
|
||||
}
|
||||
conflict_list.append(conflict)
|
||||
|
||||
return {
|
||||
"conflicts": conflict_list,
|
||||
}
|
||||
@@ -1,17 +1,16 @@
|
||||
{
|
||||
"theCompany": {
|
||||
"weLove": "theCompany",
|
||||
"accrualPer": "month",
|
||||
"employees": [
|
||||
{
|
||||
"email": "josh.smith@temporal.io",
|
||||
"currentPTOHrs": 400,
|
||||
"accrualHrsRate": 8
|
||||
"hrsAddedPerMonth": 8
|
||||
},
|
||||
{
|
||||
"email": "laine.smith@awesome.com",
|
||||
"currentPTOHrs": 40,
|
||||
"accrualHrsRate": 12
|
||||
"hrsAddedPerMonth": 12
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,17 +1,57 @@
|
||||
import json
|
||||
import pandas
|
||||
from pathlib import Path
|
||||
from datetime import date, datetime
|
||||
from dateutil.relativedelta import relativedelta
|
||||
|
||||
|
||||
def future_pto_calc(args: dict) -> dict:
|
||||
|
||||
start_date = args.get("start_date")
|
||||
end_date = args.get("end_date")
|
||||
file_path = Path(__file__).resolve().parent / "data" / "employee_pto_data.json"
|
||||
if not file_path.exists():
|
||||
return {"error": "Data file not found."}
|
||||
|
||||
# get rate of accrual - need email?
|
||||
# get total hrs of PTO available as of start date (accrual * time between today and start date)
|
||||
# take into account other booked PTO??
|
||||
# calculate number of business hours of PTO: between start date and end date
|
||||
start_date = datetime.strptime(args.get("start_date"), "%Y-%m-%d").date()
|
||||
end_date = datetime.strptime(args.get("end_date"), "%Y-%m-%d").date()
|
||||
email = args.get("email")
|
||||
|
||||
# enough_pto = total PTO as of start date - num biz hours of PTO > 0
|
||||
# pto_hrs_remaining_after = total PTO as of start date - num biz hours of PTO
|
||||
#Next, set up the ability to calculate how much PTO will be added to the user's total by the start of the PTO request
|
||||
today = date.today()
|
||||
|
||||
return {
|
||||
"enough_pto": True,
|
||||
"pto_hrs_remaining_after": 410,
|
||||
}
|
||||
if today > start_date:
|
||||
return_msg = "PTO start date " + args.get("start_date") + "cannot be in the past"
|
||||
return {"error": return_msg}
|
||||
|
||||
if end_date < start_date:
|
||||
return_msg = "PTO end date " + args.get("end_date") + " must be after PTO start date " + args.get("start_date")
|
||||
return {"error": return_msg}
|
||||
|
||||
#Get the number of business days, and then business hours (assume 8 hr biz day), included in the PTO request
|
||||
biz_days_of_request = len(pandas.bdate_range(start=start_date, end=end_date, inclusive="both"))
|
||||
biz_hours_of_request = biz_days_of_request * 8
|
||||
|
||||
#Assume PTO is added on the first of every month - month math compares rolling dates, so compare the PTO request with the first day of the current month.
|
||||
today_first_of_month = date(today.year, today.month, 1)
|
||||
time_difference = relativedelta(start_date, today_first_of_month)
|
||||
months_to_accrue = time_difference.years * 12 + time_difference.months
|
||||
|
||||
data = json.load(open(file_path))
|
||||
employee_list = data["theCompany"]["employees"]
|
||||
|
||||
enough_pto = False
|
||||
|
||||
for employee in employee_list:
|
||||
if employee["email"] == email:
|
||||
current_pto_hours = int(employee["currentPTOHrs"])
|
||||
hrs_added_per_month = int(employee["hrsAddedPerMonth"])
|
||||
pto_available_at_start = current_pto_hours + (months_to_accrue * hrs_added_per_month)
|
||||
pto_hrs_remaining_after = pto_available_at_start - biz_hours_of_request
|
||||
if pto_hrs_remaining_after >= 0:
|
||||
enough_pto = True
|
||||
return {
|
||||
"enough_pto": enough_pto,
|
||||
"pto_hrs_remaining_after": str(pto_hrs_remaining_after),
|
||||
}
|
||||
|
||||
return_msg = "Employee not found with email address " + email
|
||||
return {"error": return_msg}
|
||||
|
||||
@@ -1,22 +1,8 @@
|
||||
from typing import List
|
||||
from models.tool_definitions import AgentGoal
|
||||
import tools.tool_registry as tool_registry
|
||||
'''from tools.tool_registry import (
|
||||
search_fixtures_tool,
|
||||
search_flights_tool,
|
||||
search_trains_tool,
|
||||
book_trains_tool,
|
||||
create_invoice_tool,
|
||||
find_events_tool,
|
||||
change_goal_tool,
|
||||
list_agents_tool,
|
||||
current_pto_tool,
|
||||
future_pto_calc_tool,
|
||||
calendar_conflict_tool,
|
||||
book_pto_tool,
|
||||
)'''
|
||||
|
||||
starter_prompt_generic = "Welcome me, give me a description of what you can do, then ask me for the details you need to do your job"
|
||||
starter_prompt_generic = "Welcome me, give me a description of what you can do, then ask me for the details you need to do your job. "
|
||||
|
||||
goal_choose_agent_type = AgentGoal(
|
||||
id = "goal_choose_agent_type",
|
||||
@@ -28,14 +14,13 @@ goal_choose_agent_type = AgentGoal(
|
||||
],
|
||||
description="The user wants to choose which type of agent they will interact with. "
|
||||
"Help the user gather args for these tools, in order: "
|
||||
"1. ListAgents: List agents available to interact with "
|
||||
"1. ListAgents: List agents available to interact with. Do not ask for user confirmation for this tool. "
|
||||
"2. ChangeGoal: Change goal of agent "
|
||||
"After these tools are complete, change your goal to the new goal as chosen by the user. ",
|
||||
starter_prompt=starter_prompt_generic,
|
||||
starter_prompt=starter_prompt_generic + "Begin by providing the output for the first tool included in this goal. ",
|
||||
example_conversation_history="\n ".join(
|
||||
[
|
||||
"user: I'd like to choose an agent",
|
||||
"agent: Sure! Would you like me to list the available agents?",
|
||||
"agent: Here are the currently available agents.",
|
||||
"user_confirmed_tool_run: <user clicks confirm on ListAgents tool>",
|
||||
"tool_result: { 'agent_name': 'Event Flight Finder', 'goal_id': 'goal_event_flight_invoice', 'agent_description': 'Helps users find interesting events and arrange travel to them' }",
|
||||
"agent: The available agents are: 1. Event Flight Finder. Which agent would you like to speak to?",
|
||||
@@ -135,19 +120,17 @@ goal_event_flight_invoice = AgentGoal(
|
||||
goal_hr_schedule_pto = AgentGoal(
|
||||
id = "goal_hr_schedule_pto",
|
||||
agent_name="Schedule PTO",
|
||||
agent_friendly_description="Schedule PTO based on your available time, personal calendar, and team calendar.",
|
||||
agent_friendly_description="Schedule PTO based on your available PTO.",
|
||||
tools=[
|
||||
tool_registry.current_pto_tool,
|
||||
tool_registry.future_pto_calc_tool,
|
||||
tool_registry.calendar_conflict_tool,
|
||||
tool_registry.book_pto_tool,
|
||||
tool_registry.list_agents_tool, #last tool must be list_agents to fasciliate changing back to picking an agent again at the end
|
||||
],
|
||||
description="Help the user gather args for these tools in order: "
|
||||
description="The user wants to schedule paid time off (PTO) after today's date. To assist with that goal, help the user gather args for these tools in order: "
|
||||
"1. CurrentPTO: Tell the user how much PTO they currently have "
|
||||
"2. FuturePTOCalc: Tell the user how much PTO they will have as of the prospective date "
|
||||
"3. CalendarConflict: Tell the user what conflicts if any exist around the prospective date on a list of calendars. This step is optional and can be skipped by moving to the next tool. "
|
||||
"4. BookPTO: Book PTO ",
|
||||
"2. FuturePTOCalc: Tell the user how much PTO they will have as of the prospective future date "
|
||||
"3. BookPTO: Book PTO after user types 'yes'",
|
||||
starter_prompt=starter_prompt_generic,
|
||||
example_conversation_history="\n ".join(
|
||||
[
|
||||
@@ -158,8 +141,8 @@ goal_hr_schedule_pto = AgentGoal(
|
||||
"user_confirmed_tool_run: <user clicks confirm on CurrentPTO tool>",
|
||||
"tool_result: { 'num_hours': 400, 'num_days': 50 }",
|
||||
"agent: You have 400 hours, or 50 days, of PTO available. What dates would you like to take your time off? ",
|
||||
"user: Dec 1 2025 through Dec 5 2025",
|
||||
"agent: Let's check if you'll have enough PTO accrued by Dec 1 to accomodate that.",
|
||||
"user: Dec 1 through Dec 5",
|
||||
"agent: Let's check if you'll have enough PTO accrued by Dec 1 of this year to accomodate that.",
|
||||
"user_confirmed_tool_run: <user clicks confirm on FuturePTO tool>"
|
||||
'tool_result: {"enough_pto": True, "pto_hrs_remaining_after": 410}',
|
||||
"agent: You do in fact have enough PTO to accommodate that, and will have 410 hours remaining after you come back. Do you want to check calendars for conflicts? If so, please provide one of the following: self, team, or both "
|
||||
|
||||
@@ -151,15 +151,15 @@ current_pto_tool = ToolDefinition(
|
||||
ToolArgument(
|
||||
name="email",
|
||||
type="string",
|
||||
description="name of user, used to look up current PTO",
|
||||
description="email address of user",
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
future_pto_calc_tool = ToolDefinition(
|
||||
name="FuturePTOCalc",
|
||||
description="Calculate if the user will have enough PTO as of their proposed date to accommodate the request. Returns a boolean enough_pto and "
|
||||
"how many hours of PTO they will have if they take the proposed dates. ",
|
||||
description="Calculate if the user will have enough PTO as of their proposed date to accommodate the request. The proposed start and end dates should be in the future. "
|
||||
"Returns a boolean enough_pto and how many hours of PTO they will have remaining if they take the proposed dates. ",
|
||||
arguments=[
|
||||
ToolArgument(
|
||||
name="start_date",
|
||||
@@ -171,6 +171,11 @@ future_pto_calc_tool = ToolDefinition(
|
||||
type="string",
|
||||
description="End date of proposed PTO",
|
||||
),
|
||||
ToolArgument(
|
||||
name="email",
|
||||
type="string",
|
||||
description="email address of user",
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -211,5 +216,10 @@ book_pto_tool = ToolDefinition(
|
||||
type="string",
|
||||
description="Email address of user, used to look up current PTO",
|
||||
),
|
||||
ToolArgument(
|
||||
name="userConfirmation",
|
||||
type="string",
|
||||
description="Indication of user's desire to book PTO",
|
||||
),
|
||||
],
|
||||
)
|
||||
Reference in New Issue
Block a user