naman1102 commited on
Commit
76dd605
·
1 Parent(s): 3eb0a80

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -5
app.py CHANGED
@@ -36,7 +36,19 @@ llm = ChatOpenAI(model_name="gpt-4.1-mini")
36
  # excel_tool_node = ToolNode([parse_excel])
37
 
38
  # image_tool_node = ToolNode([ocr_image])
39
- tool_node = ToolNode([ocr_image, parse_excel, web_search])
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
  # 5) Build the StateGraph
42
  graph = StateGraph(AgentState)
@@ -48,16 +60,14 @@ graph.add_node("tools", tool_node)
48
  # Wrap the user_input into state["messages"]
49
  graph.add_edge(
50
  START,
51
- "agent",
52
- lambda state, user_input: {"messages": [user_input]}
53
  )
54
 
55
  # Edge C: "tools" → "agent"
56
  # Whatever string the tool returns becomes the next prompt to the LLM
57
  graph.add_edge(
58
  "tools",
59
- "agent",
60
- lambda state, tool_output: tool_output
61
  )
62
 
63
  # 7) Use add_conditional_edges out of "agent" instead of two separate edges
 
36
  # excel_tool_node = ToolNode([parse_excel])
37
 
38
  # image_tool_node = ToolNode([ocr_image])
39
+ t_node = ToolNode([ocr_image, parse_excel, web_search])
40
+
41
+ def tool_node(state: AgentState, agent_output)-> AgentState:
42
+ """
43
+ Wrap ToolNode so it matches (state, agent_output) → next_state.
44
+ `agent_output` is expected to be a dict like {"tool": "...", ...}.
45
+ """
46
+ # Let the ToolNode run with that dict (ToolNode.run(dict) returns a string)
47
+ tool_result: str = tool_node.run(agent_output)
48
+ # Now you might want the LLM to reason over tool_result, but for simplicity...
49
+ # We'll just store tool_result in messages.
50
+ return {"messages": [tool_result]}
51
+
52
 
53
  # 5) Build the StateGraph
54
  graph = StateGraph(AgentState)
 
60
  # Wrap the user_input into state["messages"]
61
  graph.add_edge(
62
  START,
63
+ "agent"
 
64
  )
65
 
66
  # Edge C: "tools" → "agent"
67
  # Whatever string the tool returns becomes the next prompt to the LLM
68
  graph.add_edge(
69
  "tools",
70
+ "agent"
 
71
  )
72
 
73
  # 7) Use add_conditional_edges out of "agent" instead of two separate edges