-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
136 lines (112 loc) · 4.62 KB
/
main.py
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import os, asyncio
from dotenv import load_dotenv
from agents.cra.agent import cra_agent
from agents.utils.agent_utils import stream_graph_updates, _visualize_graph
from agents.utils.tableau import authenticate_tableau_user
from agents.utils.other import _set_env
async def main():
"""
TABLEAU AGENT STAGING PLATFORM
Stage individual LangGraph Agents and Tableau AI tools to test functionality such as:
- Metrics (canonical source of truth for metrics, includes machine learning insights generated by Tableau Pulse)
- Workbooks (contains analytics such as dashboards and charts that server as canonical interfaces for data exploration)
- Data Sources (describes sources of data available for querying and exploration)
- Headless BI (can query a data source for on-demand data sets including aggregations, filters and calculations)
- Web Search (can incorporate external knowledge from the web)
Execute behavior within different agentic architectures
"""
# environment variables available to current process and sub processes
load_dotenv()
# checks for values in .env, else prompts user before initializing
_set_env('OPENAI_API_KEY')
_set_env('TABLEAU_DOMAIN')
_set_env('TABLEAU_SITE')
_set_env('PINECONE_API_KEY')
_set_env('PINECONE_ENVIRONMENT')
_set_env('RETRIEVER_MODEL')
domain = os.environ['TABLEAU_DOMAIN']
site = os.environ['TABLEAU_SITE']
datasource_luid = '0965e61b-a072-43cf-994c-8c6cf526940d'
# define required authorizations to Tableau resources to support Agent operations
access_scopes = [
"tableau:content:read", # for quering Tableau Metadata API
"tableau:viz_data_service:read" # for querying VizQL Data Service
]
tableau_auth = await authenticate_tableau_user(
jwt_client_id=os.environ['TABLEAU_JWT_CLIENT_ID'],
jwt_secret_id=os.environ['TABLEAU_JWT_SECRET_ID'],
jwt_secret=os.environ['TABLEAU_JWT_SECRET'],
tableau_api=os.environ['TABLEAU_API'],
tableau_user=os.environ['TABLEAU_USER'],
tableau_domain=domain,
tableau_site=site,
scopes=access_scopes
)
tableau_session = tableau_auth['credentials']['token']
sample_inputs = {
'tableau_credentials': {
"session": tableau_session,
"url": domain,
"site": site,
},
'datasource': {
"luid": datasource_luid,
"name": None,
"description": None
},
'workbook': {
"luid": None,
"name": None,
"description": None,
'sheets': None,
'viz_url': None
},
'rag': {
'analytics': {
"metrics": None,
"workbooks": None,
"datasources": None
},
'knowledge_base': {
"tableau": None,
"agent": None,
'app': None
}
}
}
# initialize one of the repo's custom agents
agent = cra_agent
# outputs a mermaid diagram of the graph in png format
_visualize_graph(agent)
print("\nWelcome to the Tableau Agent Staging Environment!")
print("Enter a prompt or type 'exit' to end \n")
# User input loop
while True:
try:
user_input = input("User: \n").strip() # Use .strip() to remove leading/trailing whitespace
if user_input.lower() in ["quit", "exit", "q", "stop", "end"]:
print("Exiting Tableau Agent Staging Environment...")
print("Goodbye!")
break
# If user input is empty, set to default string
if not user_input:
user_input = "show me average discount, total sales and profits by region sorted by profit\n"
print("Test input: " + user_input)
message = {
"user_message": user_input,
"agent_inputs": sample_inputs
}
stream_graph_updates(message, agent)
except Exception as e:
print(f"An error occurred: {e}")
# Use diagnostic string in case of an error
diagnostic_input = f"The previous operation '{user_input}', failed with this error: {e}.\n Write a query to test this tool again and describe the issue"
print("Retrying with diagnostics input: " + diagnostic_input)
message = {
"user_message": diagnostic_input,
"agent_inputs": sample_inputs
}
stream_graph_updates(message, agent)
break
if __name__ == "__main__":
asyncio.run(main())