# File Objective : Interactive CLI for the Vantage agent. # Scope : Dev script — verify routing, multi-hop, and multi-turn memory. # What it does : 1. REPL loop; one thread_id keeps conversation memory across turns. # 2. Streams LangGraph updates to log each ReAct step live. # 3. Support --graph argument to output Mermaid markup. # What it does not: Expose HTTP or persist memory beyond the process. from __future__ import annotations import sys import time from vantage_core.agent.graph import build_agent from vantage_core.agent.trace import log_step from vantage_core.log import get_logger log = get_logger("agent_cli") _CONFIG = {"configurable": {"thread_id": "cli"}} # stable id → memory persists across turns def main() -> None: agent = build_agent() if "--graph" in sys.argv: print("\n── LangGraph Agent Mermaid Export ──────────────────────────────") print(agent.get_graph().draw_mermaid()) print("────────────────────────────────────────────────────────────────\n") return print("\n── Vantage Market Intelligence Agent ────────────────────────────") print(" Ready for multi-turn research chat. Type 'exit' to quit.\n") while True: try: question = input("You: ").strip() except (KeyboardInterrupt, EOFError): print() break if question.lower() in {"exit", "quit", ""}: break log.info("── turn start q=%r", question[:120]) t0 = time.perf_counter() final = "" for chunk in agent.stream( {"messages": [("user", question)]}, _CONFIG, stream_mode="updates" ): for _node, update in chunk.items(): _tools, step_final = log_step(update) if step_final: final = step_final log.info("── turn done elapsed=%.2fs", time.perf_counter() - t0) print(f"\nVantage: {final}\n") if __name__ == "__main__": main()