mirror of
https://github.com/temporal-community/temporal-ai-agent.git
synced 2026-03-15 14:08:08 +01:00
Add source mocked data file, make current_pto tool functional, rename future_pto to future_pto_calc
This commit is contained in:
@@ -11,7 +11,7 @@ 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
|
||||
from .future_pto_calc import future_pto_calc
|
||||
|
||||
|
||||
def get_handler(tool_name: str):
|
||||
@@ -39,7 +39,7 @@ def get_handler(tool_name: str):
|
||||
return book_pto
|
||||
if tool_name == "CalendarConflict":
|
||||
return calendar_conflict
|
||||
if tool_name == "FuturePTO":
|
||||
return future_pto
|
||||
if tool_name == "FuturePTOCalc":
|
||||
return future_pto_calc
|
||||
|
||||
raise ValueError(f"Unknown tool: {tool_name}")
|
||||
|
||||
@@ -1,14 +1,26 @@
|
||||
from pathlib import Path
|
||||
import json
|
||||
|
||||
|
||||
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)
|
||||
file_path = Path(__file__).resolve().parent / "data" / "employee_pto_data.json"
|
||||
if not file_path.exists():
|
||||
return {"error": "Data file not found."}
|
||||
|
||||
data = json.load(open(file_path))
|
||||
employee_list = data["theCompany"]["employees"]
|
||||
|
||||
return {
|
||||
"num_hours": num_hours,
|
||||
"num_days": num_days,
|
||||
}
|
||||
for employee in employee_list:
|
||||
if employee["email"] == email:
|
||||
num_hours = int(employee["currentPTOHrs"])
|
||||
num_days = float(num_hours/8)
|
||||
return {
|
||||
"num_hours": num_hours,
|
||||
"num_days": num_days,
|
||||
}
|
||||
|
||||
return_msg = "Employee not found with email address " + email
|
||||
return {"error": return_msg}
|
||||
18
tools/data/employee_pto_data.json
Normal file
18
tools/data/employee_pto_data.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"theCompany": {
|
||||
"weLove": "theCompany",
|
||||
"accrualPer": "month",
|
||||
"employees": [
|
||||
{
|
||||
"email": "josh.smith@temporal.io",
|
||||
"currentPTOHrs": 400,
|
||||
"accrualHrsRate": 8
|
||||
},
|
||||
{
|
||||
"email": "laine.smith@awesome.com",
|
||||
"currentPTOHrs": 40,
|
||||
"accrualHrsRate": 12
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
def future_pto(args: dict) -> dict:
|
||||
def future_pto_calc(args: dict) -> dict:
|
||||
|
||||
start_date = args.get("start_date")
|
||||
end_date = args.get("end_date")
|
||||
@@ -131,6 +131,7 @@ goal_event_flight_invoice = AgentGoal(
|
||||
),
|
||||
)
|
||||
|
||||
# This goal uses the data/employee_pto_data.json file as dummy data.
|
||||
goal_hr_schedule_pto = AgentGoal(
|
||||
id = "goal_hr_schedule_pto",
|
||||
agent_name="Schedule PTO",
|
||||
@@ -144,8 +145,8 @@ goal_hr_schedule_pto = AgentGoal(
|
||||
],
|
||||
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 "
|
||||
"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 ",
|
||||
starter_prompt=starter_prompt_generic,
|
||||
example_conversation_history="\n ".join(
|
||||
@@ -170,7 +171,7 @@ goal_hr_schedule_pto = AgentGoal(
|
||||
"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? ",
|
||||
"agent: PTO successfully booked! ",
|
||||
]
|
||||
),
|
||||
)
|
||||
|
||||
@@ -157,7 +157,7 @@ current_pto_tool = ToolDefinition(
|
||||
)
|
||||
|
||||
future_pto_calc_tool = ToolDefinition(
|
||||
name="FuturePTO",
|
||||
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. ",
|
||||
arguments=[
|
||||
|
||||
Reference in New Issue
Block a user