File size: 2,602 Bytes
3295172
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""AutoStream AI Sales Agent — interactive CLI."""
from __future__ import annotations
import os
from dotenv import load_dotenv

load_dotenv()

from langchain_core.messages import HumanMessage, AIMessage
from agent.graph import get_app
from agent.state import AgentState

_BANNER = """
╔══════════════════════════════════════════════════════╗
║        AutoStream  AI  Sales  Assistant              ║
║        Automated Video Editing for Creators          ║
╚══════════════════════════════════════════════════════╝
  Type 'quit' or press Ctrl-C to exit.
  Set DEBUG=1 in .env to see intent + lead state.
"""


def _initial_state() -> AgentState:
    return {
        "messages": [],
        "intent": "unknown",
        "collecting_lead": False,
        "lead_name": None,
        "lead_email": None,
        "lead_platform": None,
        "lead_captured": False,
        "rag_context": "",
    }


def run() -> None:
    print(_BANNER)
    app = get_app()
    state = _initial_state()
    debug = bool(os.getenv("DEBUG"))

    while True:
        try:
            user_input = input("You: ").strip()
        except (KeyboardInterrupt, EOFError):
            print("\nAgent: Thanks for chatting — bye!")
            break

        if not user_input:
            continue
        if user_input.lower() in ("quit", "exit", "bye", "q"):
            print("Agent: Thanks for chatting — bye!")
            break

        # Append user message then invoke
        invoke_state = {
            **state,
            "messages": list(state["messages"]) + [HumanMessage(content=user_input)],
        }
        state = app.invoke(invoke_state)

        # Print latest AI message
        for msg in reversed(state["messages"]):
            if isinstance(msg, AIMessage):
                print(f"\nAgent: {msg.content}\n")
                break

        if debug:
            print(
                f"  [DEBUG] intent={state['intent']} | collecting={state['collecting_lead']} | "
                f"name={state['lead_name']} | email={state['lead_email']} | "
                f"platform={state['lead_platform']} | captured={state['lead_captured']}"
            )

        if state.get("lead_captured"):
            print("─" * 54)
            print("  Lead capture complete. Session ended.")
            print("─" * 54)
            break


if __name__ == "__main__":
    run()