Spaces:
Sleeping
Sleeping
Download test_agent.py from bagustenan/backend: direct link, hf CLI and curl.
- Browser
- Download file 2.31 kB
-
https://huggingface.co/spaces/bagustenan/backend/resolve/main/test_agent.py
- Command line
-
hf download hf://spaces/bagustenan/backend/test_agent.py
-
curl -L -o test_agent.py https://huggingface.co/spaces/bagustenan/backend/resolve/main/test_agent.py
2.31 kB
| 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.") | |