|
30 | 30 | audience=os.getenv('HR_API_AUTH0_AUDIENCE'), |
31 | 31 | binding_message='Please authorize the sharing of your employee details.', |
32 | 32 | # user_id=lambda *_, **__: ensure_config().get("configurable", {}).get("user_id"), |
33 | | - user_id=lambda *_, **__: 'auth0|6810f0706577ed4aea3861c9', # TODO: find a way to get user id |
| 33 | + user_id=lambda user_id, **__: user_id |
34 | 34 | ) |
35 | 35 |
|
36 | 36 | get_token = GetToken(domain=os.getenv("HR_AUTH0_DOMAIN"), client_id=os.getenv("HR_AGENT_AUTH0_CLIENT_ID"), client_secret=os.getenv("HR_AGENT_AUTH0_CLIENT_SECRET")) |
37 | 37 |
|
38 | | -def get_user_id_by_email(email: str) -> str | None: |
| 38 | +@tool |
| 39 | +def get_employee_id_by_email(work_email: str) -> str | None: |
| 40 | + """Return the employee ID by email. |
| 41 | +
|
| 42 | + Args: |
| 43 | + work_email (str): The employee's work email. |
| 44 | +
|
| 45 | + Returns: |
| 46 | + Optional[str]: The employee ID if it exists, otherwise None. |
| 47 | + """ |
39 | 48 | user = Auth0( |
40 | 49 | domain=get_token.domain, |
41 | 50 | token=get_token.client_credentials(f"https://{os.getenv('HR_AUTH0_DOMAIN')}/api/v2/")["access_token"] |
42 | | - ).users_by_email.search_users_by_email(email=email, fields=["user_id"])[0] |
| 51 | + ).users_by_email.search_users_by_email(email=work_email, fields=["user_id"])[0] |
43 | 52 | return user["user_id"] if user else None |
44 | 53 |
|
45 | 54 | @tool |
46 | | -def is_active_employee(first_name: str, last_name: str, work_email: str) -> dict[str, Any]: |
| 55 | +def is_active_employee(first_name: str, last_name: str, user_id: str) -> dict[str, Any]: |
47 | 56 | """Confirm whether a person is an active employee of the company. |
48 | 57 |
|
49 | 58 | Args: |
50 | | - first_name (str): The employer first name. |
51 | | - last_name (str): The employer last name. |
52 | | - work_email (str): The employer work email. |
| 59 | + first_name (str): The employee's first name. |
| 60 | + last_name (str): The employee's last name. |
| 61 | + work_email (str): The employee's work email. |
53 | 62 |
|
54 | 63 | Returns: |
55 | | - A dictionary containing the employment status, or an error message if the request fails. |
| 64 | + dict: A dictionary containing the employment status, or an error message if the request fails. |
56 | 65 | """ |
57 | 66 | try: |
58 | | - user_id = get_user_id_by_email(work_email) |
59 | 67 | credentials = get_ciba_credentials() |
60 | 68 | response = requests.get(f"{os.getenv('HR_API_BASE_URL')}/employees/{user_id}", headers={ |
61 | 69 | "Authorization": f"{credentials['token_type']} {credentials['access_token']}", |
@@ -97,6 +105,7 @@ def __init__(self): |
97 | 105 | self.model = ChatGoogleGenerativeAI(model='gemini-2.0-flash') |
98 | 106 | self.tools = ToolNode( |
99 | 107 | [ |
| 108 | + get_employee_id_by_email, |
100 | 109 | with_async_user_confirmation(is_active_employee), |
101 | 110 | ], |
102 | 111 | handle_tool_errors=False |
|
0 commit comments