File size: 2,301 Bytes
39afcd3
 
 
b8196ed
 
39afcd3
 
 
 
 
b8196ed
 
39afcd3
bb5095f
b8196ed
 
 
39afcd3
 
 
 
 
 
 
 
 
 
 
 
 
b8196ed
39afcd3
 
 
 
 
 
 
 
 
 
 
 
b8196ed
 
 
 
 
 
 
 
bb5095f
 
 
b8196ed
 
 
39afcd3
 
 
 
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
# 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()