mirror of
https://github.com/temporal-community/temporal-ai-agent.git
synced 2026-03-16 14:38:08 +01:00
Add in bare bones yet functional HR goal: goal_hr_schedule_pto
This commit is contained in:
@@ -8,6 +8,11 @@ from .list_agents import list_agents
|
||||
from .change_goal import change_goal
|
||||
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 import future_pto
|
||||
|
||||
|
||||
def get_handler(tool_name: str):
|
||||
if tool_name == "SearchFixtures":
|
||||
@@ -28,5 +33,13 @@ def get_handler(tool_name: str):
|
||||
return change_goal
|
||||
if tool_name == "TransferControl":
|
||||
return transfer_control
|
||||
if tool_name == "CurrentPTO":
|
||||
return current_pto
|
||||
if tool_name == "BookPTO":
|
||||
return book_pto
|
||||
if tool_name == "CalendarConflict":
|
||||
return calendar_conflict
|
||||
if tool_name == "FuturePTO":
|
||||
return future_pto
|
||||
|
||||
raise ValueError(f"Unknown tool: {tool_name}")
|
||||
|
||||
9
tools/book_pto.py
Normal file
9
tools/book_pto.py
Normal file
@@ -0,0 +1,9 @@
|
||||
def book_pto(args: dict) -> dict:
|
||||
|
||||
email = args.get("email")
|
||||
start_date = args.get("start_date")
|
||||
end_date = args.get("end_date")
|
||||
|
||||
return {
|
||||
"status": "success"
|
||||
}
|
||||
17
tools/calendar_conflict.py
Normal file
17
tools/calendar_conflict.py
Normal file
@@ -0,0 +1,17 @@
|
||||
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,
|
||||
}
|
||||
14
tools/current_pto.py
Normal file
14
tools/current_pto.py
Normal file
@@ -0,0 +1,14 @@
|
||||
def current_pto(args: dict) -> dict:
|
||||
|
||||
email = args.get("email")
|
||||
if email == "bob.johnson@emailzzz.com":
|
||||
num_hours = 40
|
||||
else:
|
||||
num_hours = 20
|
||||
|
||||
num_days = float(num_hours/8)
|
||||
|
||||
return {
|
||||
"num_hours": num_hours,
|
||||
"num_days": num_days,
|
||||
}
|
||||
17
tools/future_pto.py
Normal file
17
tools/future_pto.py
Normal file
@@ -0,0 +1,17 @@
|
||||
def future_pto(args: dict) -> dict:
|
||||
|
||||
start_date = args.get("start_date")
|
||||
end_date = args.get("end_date")
|
||||
|
||||
# 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
|
||||
|
||||
# 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
|
||||
|
||||
return {
|
||||
"enough_pto": True,
|
||||
"pto_hrs_remaining_after": 410,
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
from typing import List
|
||||
from models.tool_definitions import AgentGoal
|
||||
from tools.tool_registry import (
|
||||
import tools.tool_registry as tool_registry
|
||||
'''from tools.tool_registry import (
|
||||
search_fixtures_tool,
|
||||
search_flights_tool,
|
||||
search_trains_tool,
|
||||
@@ -8,8 +9,12 @@ from tools.tool_registry import (
|
||||
create_invoice_tool,
|
||||
find_events_tool,
|
||||
change_goal_tool,
|
||||
list_agents_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"
|
||||
|
||||
@@ -18,8 +23,8 @@ goal_choose_agent_type = AgentGoal(
|
||||
agent_name="Choose Agent",
|
||||
agent_friendly_description="Choose the type of agent to assist you today.",
|
||||
tools=[
|
||||
list_agents_tool,
|
||||
change_goal_tool,
|
||||
tool_registry.list_agents_tool,
|
||||
tool_registry.change_goal_tool,
|
||||
],
|
||||
description="The user wants to choose which type of agent they will interact with. "
|
||||
"Help the user gather args for these tools, in order: "
|
||||
@@ -46,11 +51,11 @@ goal_match_train_invoice = AgentGoal(
|
||||
agent_name="UK Premier League Match Trip Booking",
|
||||
agent_friendly_description="Book a trip to a city in the UK around the dates of a premier league match.",
|
||||
tools=[
|
||||
search_fixtures_tool,
|
||||
search_trains_tool,
|
||||
book_trains_tool,
|
||||
create_invoice_tool,
|
||||
list_agents_tool, #last tool must be list_agents to fasciliate changing back to picking an agent again at the end
|
||||
tool_registry.search_fixtures_tool,
|
||||
tool_registry.search_trains_tool,
|
||||
tool_registry.book_trains_tool,
|
||||
tool_registry.create_invoice_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="The user wants to book a trip to a city in the UK around the dates of a premier league match. "
|
||||
"Help the user find a premier league match to attend, search and book trains for that match and offers to invoice them for the cost of train tickets. "
|
||||
@@ -93,10 +98,10 @@ goal_event_flight_invoice = AgentGoal(
|
||||
agent_name="Australia and New Zealand Event Flight Booking",
|
||||
agent_friendly_description="Book a trip to a city in Australia or New Zealand around the dates of events in that city.",
|
||||
tools=[
|
||||
find_events_tool,
|
||||
search_flights_tool,
|
||||
create_invoice_tool,
|
||||
list_agents_tool, #last tool must be list_agents to fasciliate changing back to picking an agent again at the end
|
||||
tool_registry.find_events_tool,
|
||||
tool_registry.search_flights_tool,
|
||||
tool_registry.create_invoice_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: "
|
||||
"1. FindEvents: Find an event to travel to "
|
||||
@@ -126,8 +131,53 @@ 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.",
|
||||
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: "
|
||||
"1. CurrentPTO: Tell the user how much PTO they currently have "
|
||||
"2. FuturePTO: 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 "
|
||||
"4. BookPTO: Book PTO ",
|
||||
starter_prompt=starter_prompt_generic,
|
||||
example_conversation_history="\n ".join(
|
||||
[
|
||||
"user: I'd like to schedule some time off",
|
||||
"agent: Sure! Let's start by determining how much PTO you currently have. May I have your email address?",
|
||||
"user: bob.johnson@emailzzz.com",
|
||||
"agent: Great! I can tell you how much PTO you currently have accrued.",
|
||||
"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_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 "
|
||||
"user: both ",
|
||||
"agent: Okay, checking both calendars for conflicts ",
|
||||
"user_confirmed_tool_run: <user clicks confirm on CheckCalendarConflict tool>",
|
||||
'tool_result: { "calendar": "self", "title": "Meeting with Karen", "date": "2025-12-02", "time": "10:00AM"}',
|
||||
"agent: On your calendar, you have a conflict: Meeting with Karen at 10AM Dec 2, 2025. Do you want to book the PTO?"
|
||||
"user: yes "
|
||||
"user_confirmed_tool_run: <user clicks confirm on BookPTO tool>",
|
||||
'tool_result: { "status": "success" }',
|
||||
"agent: PTO successfully booked! Would you like to speak to another agent? ",
|
||||
]
|
||||
),
|
||||
)
|
||||
|
||||
#Add the goals to a list for more generic processing, like listing available agents
|
||||
goal_list: List[AgentGoal] = []
|
||||
goal_list.append(goal_choose_agent_type)
|
||||
goal_list.append(goal_event_flight_invoice)
|
||||
goal_list.append(goal_match_train_invoice)
|
||||
goal_list.append(goal_hr_schedule_pto)
|
||||
|
||||
@@ -142,3 +142,74 @@ find_events_tool = ToolDefinition(
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
current_pto_tool = ToolDefinition(
|
||||
name="CurrentPTO",
|
||||
description="Find how much PTO a user currently has accrued. "
|
||||
"Returns the number of hours and (calculated) number of days of PTO. ",
|
||||
arguments=[
|
||||
ToolArgument(
|
||||
name="email",
|
||||
type="string",
|
||||
description="name of user, used to look up current PTO",
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
future_pto_calc_tool = ToolDefinition(
|
||||
name="FuturePTO",
|
||||
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. ",
|
||||
arguments=[
|
||||
ToolArgument(
|
||||
name="start_date",
|
||||
type="string",
|
||||
description="Start date of proposed PTO",
|
||||
),
|
||||
ToolArgument(
|
||||
name="end_date",
|
||||
type="string",
|
||||
description="End date of proposed PTO",
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
calendar_conflict_tool = ToolDefinition(
|
||||
name="CalendarConflict",
|
||||
description="Determine if the proposed PTO date(s) have conflicts. Returns list of conflicts. ",
|
||||
arguments=[
|
||||
ToolArgument(
|
||||
name="check_self_calendar",
|
||||
type="boolean",
|
||||
description="Check self calendar for conflicts?",
|
||||
),
|
||||
ToolArgument(
|
||||
name="check_team_calendar",
|
||||
type="boolean",
|
||||
description="Check team calendar for conflicts?",
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
book_pto_tool = ToolDefinition(
|
||||
name="BookPTO",
|
||||
description="Book PTO start and end date. Either 1) makes calendar item, or 2) sends calendar invite to self and boss? "
|
||||
"Returns a success indicator. ",
|
||||
arguments=[
|
||||
ToolArgument(
|
||||
name="start_date",
|
||||
type="string",
|
||||
description="Start date of proposed PTO",
|
||||
),
|
||||
ToolArgument(
|
||||
name="end_date",
|
||||
type="string",
|
||||
description="End date of proposed PTO",
|
||||
),
|
||||
ToolArgument(
|
||||
name="email",
|
||||
type="string",
|
||||
description="Email address of user, used to look up current PTO",
|
||||
),
|
||||
],
|
||||
)
|
||||
Reference in New Issue
Block a user