mirror of
https://github.com/temporal-community/temporal-ai-agent.git
synced 2026-03-16 22:48:09 +01:00
improved money movement scenario
This commit is contained in:
@@ -43,3 +43,8 @@ GOAL_CATEGORIES=hr,travel,fin # default is all
|
|||||||
|
|
||||||
# Set if the UI should force a user confirmation step or not
|
# Set if the UI should force a user confirmation step or not
|
||||||
SHOW_CONFIRM=True
|
SHOW_CONFIRM=True
|
||||||
|
|
||||||
|
# Money Scenarios:
|
||||||
|
# Set if you want it to really start workflows - otherwise it'll fake it
|
||||||
|
# if you want it to be real you'll need moneytransfer and early return workers running
|
||||||
|
FIN_START_REAL_WORKFLOW=FALSE
|
||||||
6
todo.md
6
todo.md
@@ -1,7 +1,7 @@
|
|||||||
# todo list
|
# todo list
|
||||||
[ ] try claude-3-7-sonnet-20250219, see [tool_activities.py](./activities/tool_activities.py) <br />
|
[ ] try claude-3-7-sonnet-20250219, see [tool_activities.py](./activities/tool_activities.py) <br />
|
||||||
[x] make agent respond to name of goals and not just numbers <br />
|
[x] make agent respond to name of goals and not just numbers <br />
|
||||||
[ ] josh to do fintech scenarios <br />
|
[x] josh to do fintech scenarios <br />
|
||||||
[ ] expand [tests](./tests/agent_goal_workflow_test.py)<br />
|
[ ] expand [tests](./tests/agent_goal_workflow_test.py)<br />
|
||||||
|
|
||||||
[ ] fintech goals <br />
|
[ ] fintech goals <br />
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
- Personalized Financial Advice - An AI agent analyzes a customer’s financial data (e.g., income, spending habits, savings, investments) and provides tailored advice, such as budgeting tips, investment options, or debt repayment strategies.<br />
|
- Personalized Financial Advice - An AI agent analyzes a customer’s financial data (e.g., income, spending habits, savings, investments) and provides tailored advice, such as budgeting tips, investment options, or debt repayment strategies.<br />
|
||||||
- Portfolio Management and Rebalancing - The AI monitors a customer’s investment portfolio, rebalancing it automatically based on market trends, risk tolerance, and financial goals (e.g., shifting assets between stocks, bonds, or crypto).<br />
|
- Portfolio Management and Rebalancing - The AI monitors a customer’s investment portfolio, rebalancing it automatically based on market trends, risk tolerance, and financial goals (e.g., shifting assets between stocks, bonds, or crypto).<br />
|
||||||
[x] money movement - start money transfer <br />
|
[x] money movement - start money transfer <br />
|
||||||
[ ] todo use env vars to do connect to local or non-local
|
[x] todo use env vars to do connect to local or non-local
|
||||||
[x] account balance - <br />
|
[x] account balance - <br />
|
||||||
[ ] new loan/fraud check/update with start <br />
|
[ ] new loan/fraud check/update with start <br />
|
||||||
|
|
||||||
@@ -24,4 +24,4 @@
|
|||||||
|
|
||||||
[ ] change initial goal selection prompt to list capabilities and prompt more nicely - not a bulleted list - see how that works
|
[ ] change initial goal selection prompt to list capabilities and prompt more nicely - not a bulleted list - see how that works
|
||||||
|
|
||||||
[ ] todo use env vars to do connect to local or non-local cloud for activities for money scenarios
|
[x] todo use env vars to do connect to local or non-local cloud for activities for money scenarios
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import json
|
import json
|
||||||
from temporalio.client import Client
|
from temporalio.client import Client
|
||||||
@@ -5,6 +6,8 @@ from dataclasses import dataclass
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
import asyncio
|
import asyncio
|
||||||
from temporalio.exceptions import WorkflowAlreadyStartedError
|
from temporalio.exceptions import WorkflowAlreadyStartedError
|
||||||
|
from shared.config import get_temporal_client
|
||||||
|
|
||||||
|
|
||||||
from enum import Enum, auto
|
from enum import Enum, auto
|
||||||
|
|
||||||
@@ -45,9 +48,10 @@ async def move_money(args: dict) -> dict:
|
|||||||
|
|
||||||
for account in account_list:
|
for account in account_list:
|
||||||
if account["email"] == account_key or account["account_id"] == account_key:
|
if account["email"] == account_key or account["account_id"] == account_key:
|
||||||
amount_str: str = str(amount)
|
amount_str: str = str(amount) # LLM+python gets sassy about types but we need it to be str
|
||||||
|
from_account_combo = account_key + account_type
|
||||||
|
|
||||||
transfer_workflow_id = await start_workflow(amount_cents=str_dollars_to_cents(amount_str),from_account_name=account_key, to_account_name=destinationaccount)
|
transfer_workflow_id = await start_workflow(amount_cents=str_dollars_to_cents(amount_str),from_account_name=from_account_combo, to_account_name=destinationaccount)
|
||||||
|
|
||||||
account_type_key = 'checking_balance'
|
account_type_key = 'checking_balance'
|
||||||
if(account_type.casefold() == "checking" ):
|
if(account_type.casefold() == "checking" ):
|
||||||
@@ -66,7 +70,7 @@ async def move_money(args: dict) -> dict:
|
|||||||
with open(file_path, 'w') as file:
|
with open(file_path, 'w') as file:
|
||||||
json.dump(data, file, indent=4)
|
json.dump(data, file, indent=4)
|
||||||
|
|
||||||
return {'status': "money movement complete", 'confirmation id': transfer_workflow_id, 'new_balance': account["checking_balance"]}
|
return {'status': "money movement complete", 'confirmation id': transfer_workflow_id, 'new_balance': account[account_type_key]}
|
||||||
|
|
||||||
return_msg = "Account not found with for " + account_key
|
return_msg = "Account not found with for " + account_key
|
||||||
return {"error": return_msg}
|
return {"error": return_msg}
|
||||||
@@ -76,30 +80,37 @@ async def start_workflow(amount_cents: int, from_account_name: str, to_account_n
|
|||||||
|
|
||||||
|
|
||||||
# Connect to Temporal
|
# Connect to Temporal
|
||||||
# todo use env vars to do connect to local or non-local
|
|
||||||
client:Client = await Client.connect("localhost:7233")
|
|
||||||
|
|
||||||
# Create the parameter object
|
|
||||||
params = MoneyMovementWorkflowParameterObj(
|
|
||||||
amount=amount_cents*100,
|
|
||||||
scenario="HAPPY_PATH"
|
|
||||||
)
|
|
||||||
|
|
||||||
workflow_id="TRANSFER-ACCT-" + from_account_name + "-TO-" + to_account_name # business-relevant workflow ID
|
client = await get_temporal_client()
|
||||||
|
start_real_workflow = os.getenv("FIN_START_REAL_WORKFLOW")
|
||||||
|
if start_real_workflow is not None and start_real_workflow.lower() == "false":
|
||||||
|
START_REAL_WORKFLOW = False
|
||||||
|
else:
|
||||||
|
START_REAL_WORKFLOW = True
|
||||||
|
|
||||||
try:
|
if START_REAL_WORKFLOW:
|
||||||
handle = await client.start_workflow(
|
# Create the parameter object
|
||||||
"moneyTransferWorkflow", # Workflow name
|
params = MoneyMovementWorkflowParameterObj(
|
||||||
params, # Workflow parameters
|
amount=amount_cents,
|
||||||
id=workflow_id,
|
scenario="HAPPY_PATH"
|
||||||
task_queue="MoneyTransferJava" # Task queue name
|
|
||||||
)
|
)
|
||||||
return handle.id
|
|
||||||
except WorkflowAlreadyStartedError as e:
|
|
||||||
existing_handle = client.get_workflow_handle(workflow_id=workflow_id)
|
|
||||||
return existing_handle.id
|
|
||||||
|
|
||||||
|
workflow_id="TRANSFER-ACCT-" + from_account_name + "-TO-" + to_account_name # business-relevant workflow ID
|
||||||
|
|
||||||
|
try:
|
||||||
|
handle = await client.start_workflow(
|
||||||
|
"moneyTransferWorkflow", # Workflow name
|
||||||
|
params, # Workflow parameters
|
||||||
|
id=workflow_id,
|
||||||
|
task_queue="MoneyTransferJava" # Task queue name
|
||||||
|
)
|
||||||
|
return handle.id
|
||||||
|
except WorkflowAlreadyStartedError as e:
|
||||||
|
existing_handle = client.get_workflow_handle(workflow_id=workflow_id)
|
||||||
|
return existing_handle.id
|
||||||
|
else:
|
||||||
|
return "TRANSFER-ACCT-" + from_account_name + "-TO-" + to_account_name + "not-real"
|
||||||
|
|
||||||
|
|
||||||
#cleans a string dollar amount description to cents value
|
#cleans a string dollar amount description to cents value
|
||||||
|
|||||||
Reference in New Issue
Block a user