File size: 2,749 Bytes
28fad98 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | from google.adk.tools.tool_context import ToolContext
def update_user_profile(name: str, language: str, currency: str, tool_context: ToolContext) -> dict:
"""
Udate current user name
Use only when user name is not provided.
Args:
name (str): User name
Returns:
dict: A dictionary confirming the action was successful and report updated balance
"""
tool_context.state["user:name"] = name
tool_context.state["user:language"] = language
tool_context.state["user:currency"] = currency
return {
"status": "success",
"message": "User Profile Successfully Created"
}
def add_financial_goals(goals: str, tool_context: ToolContext) -> dict:
"""
Add new user financial goals
Args:
goals (str): String of user defined financial goals
Returns:
dict: A dictionary confirming the action was successful
"""
user_goals = tool_context.state.get("user:financial_goals", [])
user_goals.append(goals)
tool_context.state["user:financial_goals"] = user_goals
return {
"status": "success",
"message": f"New user financial goals added: {goals}"
}
def update_balance(transaction_amount: int, tool_context: ToolContext) -> dict:
"""
Udate current user balance based on incoming transaction
Args:
transaction_amount (int): Amount of recent user transaction.
Positive (plus) if an income, negative (minus) if an expense
Returns:
dict: A dictionary confirming the action was successful and report updated balance
"""
balance = tool_context.state.get("user:balance", 0)
balance += transaction_amount
tool_context.state["user:balance"] = balance
return {
"status": "success",
"message": f"Current user balance: {balance}"
}
def check_balance(tool_context: ToolContext) -> dict:
"""
Check current user balance
Returns:
dics: A dictionary contains status and report of current user balance
"""
balance = tool_context.state.get("user:balance", 0)
if balance >= 0:
return {
"status": "success",
"report": f"Current user balance: {balance}"
}
else:
return {
"status": "ValueError",
"report": "There is an error in user balance value"
}
def set_budget(salary: int, tool_context: ToolContext, **kwargs):
tool_context.state["user:budget"] = {
"salary": salary,
**kwargs
}
def insert_liabilites(new_liability: dict, tool_context: ToolContext) -> dict:
"""
Insert some liabilities
"""
liabilities = tool_context.state.get("user:liabilites", [])
pass
|