-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
84 lines (67 loc) · 2.54 KB
/
main.py
File metadata and controls
84 lines (67 loc) · 2.54 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
"""
main.py — AutoStream Agent CLI
Run this file to start an interactive conversation with the AutoStream AI agent.
Usage:
python main.py
Environment variables (set in .env):
LLM_PROVIDER = anthropic | openai | google (default: anthropic)
ANTHROPIC_API_KEY / OPENAI_API_KEY / GOOGLE_API_KEY
"""
import sys
import os
import copy
from pathlib import Path
# Allow imports from project root
sys.path.insert(0, str(Path(__file__).parent))
from langchain_core.messages import HumanMessage, AIMessage
from agent.agent import build_graph, AgentState
BANNER = """
╔══════════════════════════════════════════════════════════╗
║ AutoStream AI Assistant ║
║ Powered by LangGraph + RAG | Type 'quit' to exit ║
╚══════════════════════════════════════════════════════════╝
"""
INITIAL_STATE: AgentState = {
"messages": [],
"intent": "greeting",
"lead_stage": "none",
"lead_name": "",
"lead_email": "",
"lead_platform": "",
"rag_context": "",
}
def run_cli():
print(BANNER)
graph = build_graph()
state = copy.deepcopy(INITIAL_STATE)
while True:
try:
user_input = input("You: ").strip()
except (EOFError, KeyboardInterrupt):
print("\nGoodbye! ")
break
if not user_input:
continue
if user_input.lower() in ("quit", "exit", "bye"):
print("Agent: Thanks for chatting with AutoStream! Have a great day 🚀")
break
# Append user message to state
state = {**state, "messages": state["messages"] + [HumanMessage(content=user_input)]}
# Run one step of the graph
try:
result = graph.invoke(state)
state = result # persist updated state (memory across turns)
except Exception as e:
print(f"\nAgent: Oops, something went wrong — {e}\n")
# Roll back the last human message so the user can retry
state = {**state, "messages": state["messages"][:-1]}
continue
# Print latest AI message
last_ai = next(
(m.content for m in reversed(state["messages"])
if isinstance(m, AIMessage)),
"(no response)"
)
print(f"\nAgent: {last_ai}\n")
if __name__ == "__main__":
run_cli()