Repository navigation
Expand file tree
/
Copy pathtest_interactive.py
More file actions
86 lines (69 loc) · 2.69 KB
/
Copy pathtest_interactive.py
File metadata and controls
86 lines (69 loc) · 2.69 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import asyncio
import logging
from dotenv import load_dotenv
from database import Database
from config import Config
from ai_agent import SwiftLogisticsAgent
# Configure logging to show only errors to keep console clean
logging.basicConfig(level=logging.ERROR)
async def main():
# Load environment variables from .env
load_dotenv()
print("Initializing Database...")
try:
config = Config()
db = Database(config.database_url)
await db.initialize()
except Exception as e:
print(f"Error connecting to database: {e}")
print("Please check your .env file and ensure PostgreSQL is running.")
return
print("Initializing AI Agent...")
try:
agent = SwiftLogisticsAgent(db)
except Exception as e:
print(f"Error initializing agent: {e}")
return
# Initial state
current_state = 'greeting'
context = {}
print("\n" + "="*50)
print(" TRACKING AI AGENT - TEXT TEST CONSOLE")
print("="*50)
print("Type 'quit' or 'exit' to stop.")
print("-" * 50)
# Simulate the initial greeting
print("\nAI: Hello! Welcome to Rocket Shipment. I'm your Rocket Shipment AI agent. How can I help you today?")
while True:
try:
user_input = input("\nYou: ")
if user_input.lower() in ('quit', 'exit'):
print("\nExiting...")
break
if not user_input.strip():
continue
# Process the message through the AI agent
# We bypass the Speech-to-Text and Text-to-Speech layers here
response = await agent.process_message(user_input, current_state, context)
print(f"AI: {response['message']}")
# Print debug info about state changes (optional, good for testing)
# print(f" [Debug state: {current_state} -> {response['next_state']}]")
# Update state and context for next turn
current_state = response['next_state']
context = response['context']
if not response['continue_conversation']:
print("\n--- Call Ended ---")
# Reset for a new "call" simulation
current_state = 'greeting'
context = {}
print("\nAI: (New Call) Hello! Welcome to Rocket Shipment. How can I help you?")
except KeyboardInterrupt:
break
except Exception as e:
print(f"Error processing message: {e}")
await db.close()
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
pass