Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -127,12 +127,39 @@ def finalize_node(state: AgentState) -> AgentState:
|
|
127 |
return {"final_answer": llm_response.content.strip()}
|
128 |
|
129 |
# ─── 4) Wrap tools in a ToolNode ───
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
|
137 |
# Add a node to store the previous state
|
138 |
|
|
|
127 |
return {"final_answer": llm_response.content.strip()}
|
128 |
|
129 |
# ─── 4) Wrap tools in a ToolNode ───
|
130 |
+
def tools_node(state: AgentState) -> AgentState:
|
131 |
+
"""
|
132 |
+
Inspect exactly which tool‐key was set in `state` and call that function.
|
133 |
+
Returns only the partial state (with the tool's outputs) so that merge_tool_output can combine it.
|
134 |
+
"""
|
135 |
+
# We expect exactly one of these keys to be non‐empty:
|
136 |
+
# "web_search_query", "ocr_path", "excel_path"/"excel_sheet_name", "audio_path"
|
137 |
+
# Whichever is present, call the corresponding tool and return its result.
|
138 |
+
if state.get("web_search_query"):
|
139 |
+
print(f">>> tools_node dispatching web_search_tool with query: {state['web_search_query']!r}")
|
140 |
+
out = web_search_tool(state)
|
141 |
+
return out
|
142 |
+
|
143 |
+
if state.get("ocr_path"):
|
144 |
+
print(f">>> tools_node dispatching ocr_image_tool with path: {state['ocr_path']!r}")
|
145 |
+
out = ocr_image_tool(state)
|
146 |
+
return out
|
147 |
+
|
148 |
+
if state.get("excel_path"):
|
149 |
+
# We assume plan_node always sets both excel_path and excel_sheet_name together
|
150 |
+
print(f">>> tools_node dispatching parse_excel_tool with path: {state['excel_path']!r}, sheet: {state.get('excel_sheet_name')!r}")
|
151 |
+
out = parse_excel_tool(state)
|
152 |
+
return out
|
153 |
+
|
154 |
+
if state.get("audio_path"):
|
155 |
+
print(f">>> tools_node dispatching audio_transcriber_tool with path: {state['audio_path']!r}")
|
156 |
+
out = audio_transcriber_tool(state)
|
157 |
+
return out
|
158 |
+
|
159 |
+
# If we somehow reach here, no recognized tool key was set:
|
160 |
+
print(">>> tools_node: no valid tool key found in state!")
|
161 |
+
return {}
|
162 |
+
|
163 |
|
164 |
# Add a node to store the previous state
|
165 |
|