Spaces:
Sleeping
Sleeping
toolcount
Browse files
app.py
CHANGED
|
@@ -111,6 +111,9 @@ def tool_node(state: AgentState) -> AgentState:
|
|
| 111 |
- excel_path → parse_excel_tool
|
| 112 |
- audio_path → audio_transcriber_tool
|
| 113 |
"""
|
|
|
|
|
|
|
|
|
|
| 114 |
if state.get("wiki_query"):
|
| 115 |
return wikipedia_search_tool(state)
|
| 116 |
if state.get("web_search_query"):
|
|
@@ -155,7 +158,7 @@ def inspect_node(state: AgentState) -> AgentState:
|
|
| 155 |
question = msg.content
|
| 156 |
break
|
| 157 |
messages_for_llm.append(SystemMessage(content=f"USER_QUESTION: {question}"))
|
| 158 |
-
|
| 159 |
# 2) Add any tool results
|
| 160 |
if sr := state.get("web_search_result"):
|
| 161 |
messages_for_llm.append(SystemMessage(content=f"WEB_SEARCH_RESULT: {sr}"))
|
|
@@ -304,7 +307,7 @@ def respond_to_input(user_input: str, task_id) -> str:
|
|
| 304 |
)
|
| 305 |
human_msg = HumanMessage(content=user_input)
|
| 306 |
|
| 307 |
-
initial_state: AgentState = {"messages": [system_msg, human_msg], "task_id": task_id}
|
| 308 |
final_state = compiled_graph.invoke(initial_state)
|
| 309 |
return final_state.get("final_answer", "Error: No final answer generated.")
|
| 310 |
|
|
|
|
| 111 |
- excel_path → parse_excel_tool
|
| 112 |
- audio_path → audio_transcriber_tool
|
| 113 |
"""
|
| 114 |
+
tool_counter = state.get("tool_counter", 0)
|
| 115 |
+
if tool_counter > 5:
|
| 116 |
+
return {}
|
| 117 |
if state.get("wiki_query"):
|
| 118 |
return wikipedia_search_tool(state)
|
| 119 |
if state.get("web_search_query"):
|
|
|
|
| 158 |
question = msg.content
|
| 159 |
break
|
| 160 |
messages_for_llm.append(SystemMessage(content=f"USER_QUESTION: {question}"))
|
| 161 |
+
|
| 162 |
# 2) Add any tool results
|
| 163 |
if sr := state.get("web_search_result"):
|
| 164 |
messages_for_llm.append(SystemMessage(content=f"WEB_SEARCH_RESULT: {sr}"))
|
|
|
|
| 307 |
)
|
| 308 |
human_msg = HumanMessage(content=user_input)
|
| 309 |
|
| 310 |
+
initial_state: AgentState = {"messages": [system_msg, human_msg], "task_id": task_id, "tool_counter": 0}
|
| 311 |
final_state = compiled_graph.invoke(initial_state)
|
| 312 |
return final_state.get("final_answer", "Error: No final answer generated.")
|
| 313 |
|
state.py
CHANGED
|
@@ -18,4 +18,5 @@ class AgentState(TypedDict, total=False):
|
|
| 18 |
audio_transcript: str
|
| 19 |
wiki_query: str
|
| 20 |
wiki_result: str
|
| 21 |
-
task_id: str
|
|
|
|
|
|
| 18 |
audio_transcript: str
|
| 19 |
wiki_query: str
|
| 20 |
wiki_result: str
|
| 21 |
+
task_id: str
|
| 22 |
+
tool_counter: int
|