File size: 1,136 Bytes
b30f068
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from langgraph.graph import StateGraph, START, END
from typing import TypedDict, Annotated
from langgraph.graph.message import add_messages
from .parser import parse_query

# Define the state of our graph.
class AgentState(TypedDict):
    """Represents the state of our graph."""
    query: str
    parsed_results: dict

def parser_node(state: AgentState):
    """A LangGraph node that performs the query parsing."""
    query = state["query"]
    parsed_results = parse_query(query)
    return {"parsed_results": parsed_results}

# Build the LangGraph
graph_builder = StateGraph(AgentState)

# Add the parser node
graph_builder.add_node("parser_node", parser_node)

# Set the entry and finish points for this simple graph
graph_builder.add_edge(START, "parser_node")
graph_builder.add_edge("parser_node", END)

# Compile the graph
agent_parser = graph_builder.compile()

# Example usage
if __name__ == "__main__":
    user_query = "What's the product stock for the new laptop model?"
    # The LangGraph stream method allows us to see intermediate steps
    for event in agent_parser.stream({"query": user_query}):
        print(event)