Spaces:
Running
Running
File size: 1,557 Bytes
0001f12 | 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 | import uuid
from agent_graph import stock_agent_app
def start_interactive_session():
print("=== Stock AI Agent Ready ===")
print("Type 'exit' to quit.\n")
# Generate a unique session ID for this run
# This allows the SQLite database to track this specific conversation
session_id = str(uuid.uuid4())
config = {"configurable": {"thread_id": session_id}}
print(f"Session started with ID: {session_id}\n")
while True:
user_input = input("User: ")
if user_input.lower() in ['exit', 'quit', 'q']:
print("Closing session...")
break
# The 'messages' list is appended in the graph state
initial_state = {"messages": [("user", user_input)]}
# IMPORTANT: Pass the 'config' variable as the second argument
# This triggers the SqliteSaver to save/load memory for this thread_id
for event in stock_agent_app.stream(initial_state, config):
for node_name, output in event.items():
print(f"\n[Executing Node: {node_name}]")
# Retrieve the last message produced by this node
if "messages" in output:
last_msg = output["messages"][-1]
# Only print if there is text content (ignore tool-call metadata)
if hasattr(last_msg, 'content') and last_msg.content:
print(f"AI: {last_msg.content}")
if __name__ == "__main__":
start_interactive_session() |