File size: 2,024 Bytes
bf6dbfa
 
 
 
 
 
 
 
 
0643073
bf6dbfa
 
 
 
 
 
 
 
 
0643073
bf6dbfa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0643073
bf6dbfa
 
0643073
bf6dbfa
 
0643073
bf6dbfa
 
0643073
bf6dbfa
 
0643073
bf6dbfa
 
 
0643073
 
bf6dbfa
 
0643073
bf6dbfa
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
from dotenv import load_dotenv
from agent.graph import app
from agent.state import AgentState

def print_header(title):
    print(f"\n{'='*50}\n{title}\n{'='*50}")

def main():

    load_dotenv()

    if not os.environ.get("OPENAI_API_KEY"):
        print("Warning: OPENAI_API_KEY is not set. The agent will not be able to call the LLM.")
        print("Please set it in your environment or create a .env file.")

    print_header("AutoStream AI Sales Assistant")
    print("Type 'quit' or 'exit' to end the conversation.\n")


    state = AgentState(
        conversation_history=[],
        current_message="",
        detected_intent=None,
        retrieved_documents=[],
        user_name=None,
        user_email=None,
        creator_platform=None,
        lead_ready=False,
        response=""
    )

    while True:
        try:
            user_input = input("\nYou: ")
            if user_input.lower() in ['quit', 'exit']:
                break


            state["current_message"] = user_input


            print("\n[Agent is thinking...]")


            result_state = app.invoke(state)


            state = result_state


            state["conversation_history"].append({"role": "user", "content": user_input})
            state["conversation_history"].append({"role": "assistant", "content": state["response"]})


            if len(state["conversation_history"]) > 12:
                state["conversation_history"] = state["conversation_history"][-12:]


            print(f"[Detected Intent]: {state.get('detected_intent', 'UNKNOWN')}")

            if state.get("retrieved_documents") and state.get("detected_intent") in ["PRODUCT_QUERY", "PRICING_QUERY"]:
                print(f"[RAG Retrieval]: Found {len(state['retrieved_documents'])} relevant knowledge chunks.")

            print(f"\nAgent: {state['response']}")

        except KeyboardInterrupt:
            break
        except Exception as e:
            print(f"\nAn error occurred: {e}")

if __name__ == "__main__":
    main()