File size: 1,555 Bytes
1870dee
df07284
 
1870dee
 
 
 
 
 
 
 
 
df07284
 
 
 
 
 
1870dee
df07284
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from langchain_core.messages import HumanMessage
from .graph import graph

# -> return updates from each Node as it finishes
# for update in graph.stream(
#     initial_state,
#     stream_mode="updates"
# ):
#     print(update)

# stream("updates") → Each Node's State updates.
# stream("values") → Full accumulated State at each step.

def main():
    config = {
        "configurable": {
            "thread_id": "restaurant-test-1"
        }
    }

    # First user message
    result = graph.invoke(
        {
            "messages": [
                HumanMessage(
                    content="Book a table at Olive Garden for 4 people"
                )
            ],
            "global_params": {},
            "selected_tool": None,
            "missing_params": [],
            "tool_args": {},
            "tool_result": None
        },
        config=config
    )

    print("ASSISTANT:", result["messages"][-1].content)

    # Second user message
    result = graph.invoke(
        {
            "messages": [
                HumanMessage(content="Tomorrow at 7 PM")
            ]
        },
        config=config
    )

    print("SELECTED TOOL:", result["selected_tool"])
    print("TOOL ARGS:", result["tool_args"])
    print("TOOL RESULT:", result["tool_result"])
    print("ASSISTANT:", result["messages"][-1].content)

    # Generate Graph image
    with open("agent_graph.png", "wb") as f:
        f.write(graph.get_graph().draw_mermaid_png())

    print("Graph saved to agent_graph.png")


if __name__ == "__main__":
    main()