Spaces:
Sleeping
Sleeping
google-labs-jules[bot]
feat: implement AutoStream conversational AI sales agent with LangGraph
0643073 | 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() | |