-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_agent.py
More file actions
66 lines (51 loc) · 2.44 KB
/
Copy pathtest_agent.py
File metadata and controls
66 lines (51 loc) · 2.44 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
57
58
59
60
61
62
63
64
65
66
import os
import sys
from dotenv import load_dotenv
# Load env
load_dotenv()
def run_simulation():
print("=== STARTING SIMULATED CONVERSATION TEST ===")
try:
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
from langchain_core.messages import HumanMessage
from agent.rag import AutoStreamRAG
from agent.graph import build_agent_graph
# Initialize
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
embeddings = OpenAIEmbeddings(model="text-embedding-3-small")
script_dir = os.path.dirname(os.path.abspath(__file__))
kb_path = os.path.join(script_dir, "data", "knowledge_base.md")
rag = AutoStreamRAG(kb_path, embeddings)
compiled_graph = build_agent_graph(llm, rag)
config = {"configurable": {"thread_id": "test-session-001"}}
# Turns simulation
turns = [
"Hi",
"Tell me about your pricing.",
"That sounds good, I want to try the Pro plan for my YouTube channel.",
"Praneeth",
"praneeth@gmail.com"
]
for i, user_message in enumerate(turns):
print(f"\nTurn {i+1} - User: {user_message}")
state_input = {"messages": [HumanMessage(content=user_message)]}
state_output = compiled_graph.invoke(state_input, config)
# Print state details
intent = state_output.get("current_intent", "Unknown")
stage = state_output.get("lead_collection_stage", "none")
name = state_output.get("lead_name") or "None"
email = state_output.get("lead_email") or "None"
platform = state_output.get("lead_platform") or "None"
print(f"[State] Intent: {intent} | Stage: {stage} | Slots: Name={name}, Email={email}, Platform={platform}")
messages = state_output.get("messages", [])
if messages:
print(f"Bot: {messages[-1].content}")
print("\n=== SIMULATED CONVERSATION TEST COMPLETE ===")
except Exception as e:
print(f"\n❌ TEST ERROR: {e}")
sys.exit(1)
if __name__ == "__main__":
if not os.getenv("OPENAI_API_KEY") or os.getenv("OPENAI_API_KEY") == "your_openai_api_key_here":
print("❌ Test cancelled: OPENAI_API_KEY is not configured in .env file.")
sys.exit(0)
run_simulation()