-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli_runner.py
More file actions
56 lines (43 loc) · 1.77 KB
/
Copy pathcli_runner.py
File metadata and controls
56 lines (43 loc) · 1.77 KB
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
import os
from dotenv import load_dotenv
from langchain_core.messages import HumanMessage
# Load .env BEFORE importing modules that need environment variables
load_dotenv()
from src.config import get_user_context
from src.agent import app
def run_chat_session():
print("--- INTERNAL SUPPORT AGENT (CLI MODE) ---")
print("Select User Persona:")
print("1. Alice (Intern) - Restricted Access")
print("2. Bob (CTO) - Admin Access")
choice = input("Enter 1 or 2: ")
user_id = "u_intern" if choice == "1" else "u_cto"
user_ctx = get_user_context(user_id)
print(f"\nLogged in as: {user_ctx['name']} ({user_ctx['role']})")
print("Type 'quit' to exit.\n")
chat_history = []
while True:
user_input = input("You: ")
if user_input.lower() in ["quit", "exit"]:
break
current_state = {
"messages": chat_history + [HumanMessage(content=user_input)],
"user_id": user_id,
"user_name": user_ctx.get("name", "Valued Employee"),
"user_email": user_ctx["email"],
"user_role": user_ctx["role"]
}
print("... Agent thinking ...")
# Run the graph and get the final output
events = list(app.stream(current_state, stream_mode="values"))
final_response = events[-1]["messages"][-1]
print(f"Agent: {final_response.content}\n")
# Simple history update for the demo loop
chat_history.append(HumanMessage(content=user_input))
chat_history.append(final_response)
if __name__ == "__main__":
# --- CHECK FOR NEW KEY NAME ---
if not os.environ.get("AIMLAPI_KEY"):
print("ERROR: Please set AIMLAPI_KEY in .env")
else:
run_chat_session()