Skip to content

Commit 9e6be22

Browse files
committed
remove hardcoded user id
1 parent df47361 commit 9e6be22

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

examples/a2a/hr_agent/agent.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,32 +30,40 @@
3030
audience=os.getenv('HR_API_AUTH0_AUDIENCE'),
3131
binding_message='Please authorize the sharing of your employee details.',
3232
# 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
3434
)
3535

3636
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"))
3737

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+
"""
3948
user = Auth0(
4049
domain=get_token.domain,
4150
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]
4352
return user["user_id"] if user else None
4453

4554
@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]:
4756
"""Confirm whether a person is an active employee of the company.
4857
4958
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.
5362
5463
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.
5665
"""
5766
try:
58-
user_id = get_user_id_by_email(work_email)
5967
credentials = get_ciba_credentials()
6068
response = requests.get(f"{os.getenv('HR_API_BASE_URL')}/employees/{user_id}", headers={
6169
"Authorization": f"{credentials['token_type']} {credentials['access_token']}",
@@ -97,6 +105,7 @@ def __init__(self):
97105
self.model = ChatGoogleGenerativeAI(model='gemini-2.0-flash')
98106
self.tools = ToolNode(
99107
[
108+
get_employee_id_by_email,
100109
with_async_user_confirmation(is_active_employee),
101110
],
102111
handle_tool_errors=False

examples/a2a/hr_agent/prompt.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
44
Do not attempt to answer unrelated questions or use tools for other purposes.
55
6+
If you are asked about a person's employee status using their employee ID, use the `is_active_employee` tool.
7+
If they provide a work email instead, first call the `get_employee_id_by_email` tool to get the employee ID, and then use `is_active_employee`.
8+
69
Set response status to input_required if the user needs to authorize the request.
710
Set response status to error if there is an error while processing the request.
811
Set response status to completed if the request is complete.

0 commit comments

Comments
 (0)