File size: 2,313 Bytes
495399f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import sys
from dotenv import load_dotenv
from langchain_core.messages import HumanMessage

# Load environment variables
load_dotenv()

# Add the backend directory to sys.path to allow imports
sys.path.append(os.path.dirname(os.path.abspath(__file__)))

try:
    from agent.graph import app
    print("Successfully imported agent graph.")
except ImportError as e:
    print(f"Error importing agent graph: {e}")
    print("Please ensure all dependencies are installed via Anaconda.")
    sys.exit(1)

if __name__ == "__main__":
    print("Starting Agent Verification with Memory...")
    
    # Define a thread ID to maintain conversation state
    # In a real app, this would come from the frontend (e.g., user session ID)
    thread_id = "test_thread_1"
    config = {"configurable": {"thread_id": thread_id}, "recursion_limit": 50}
    
    print(f"\nUsing Thread ID: {thread_id}")
    
    # --- Turn 1: Context Setting ---
    # query1 = "Siapa kepala BPS Sumut saat ini?"
    # print(f"\n--- Turn 1: {query1} ---")
    # inputs = {"messages": [HumanMessage(content=query1)]}
    # result = app.invoke(inputs, config=config)
    # print(f"Agent Response: {result['messages'][-1].content}")
    
    # # --- Turn 2: Follow-up (Requires Memory) ---
    # # The agent should know "kantornya" refers to BPS Sumut from Turn 1
    # query2 = "Dimana alamat kantornya?"
    # print(f"\n--- Turn 2: {query2} (Menguji Memori) ---")
    # inputs = {"messages": [HumanMessage(content=query2)]}
    # result = app.invoke(inputs, config=config)
    # print(f"Agent Response: {result['messages'][-1].content}")
    
    # --- Turn 3: Data Request (RAG) ---
    query3 = "Berapa jumlah pariwisata yang datang ke sumut tahun 2020?"
    print(f"\n--- Turn 3: {query3} ---")
    inputs = {"messages": [HumanMessage(content=query3)]}
    result = app.invoke(inputs, config=config)
    print(f"Agent Response: {result['messages'][-1].content}")

    # --- Turn 4: Excel Export (Supabase) ---
    query4 = "Tolong export data tersebut ke excel."
    print(f"\n--- Turn 4: {query4} (Menguji Export & Memori) ---")
    inputs = {"messages": [HumanMessage(content=query4)]}
    result = app.invoke(inputs, config=config)
    print(f"Agent Response: {result['messages'][-1].content}")

    print("\nVerification Complete.")