Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -743,19 +743,14 @@ def should_continue(state: AgentState):
|
|
| 743 |
|
| 744 |
# 3. If last message is AIMessage with tool calls
|
| 745 |
if isinstance(last_message, AIMessage) and last_message.tool_calls:
|
| 746 |
-
#
|
| 747 |
-
|
| 748 |
-
|
| 749 |
-
print(f"π§ Tool call detected: '{tool_name}'")
|
| 750 |
-
|
| 751 |
-
# ONLY end if it's explicitly final_answer_tool
|
| 752 |
-
if tool_name == "final_answer_tool":
|
| 753 |
-
print(f"β
final_answer_tool confirmed β ending")
|
| 754 |
-
return END
|
| 755 |
|
| 756 |
-
|
| 757 |
-
|
| 758 |
-
|
|
|
|
| 759 |
|
| 760 |
# 4. If AIMessage but no tool calls (reasoning text)
|
| 761 |
if isinstance(last_message, AIMessage) and not last_message.tool_calls:
|
|
@@ -898,18 +893,24 @@ REMEMBER: One tool per turn. No reasoning without tools. Exact answer format.
|
|
| 898 |
|
| 899 |
print("Initializing Groq LLM...")
|
| 900 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 901 |
# Use tool_choice="any" to FORCE tool usage
|
| 902 |
-
|
| 903 |
-
|
| 904 |
-
|
| 905 |
-
|
| 906 |
-
|
| 907 |
-
timeout=60
|
| 908 |
-
).bind_tools(self.tools, tool_choice="
|
| 909 |
print("β
LLM initialized with FORCED tool usage.")
|
| 910 |
|
| 911 |
except Exception as e:
|
| 912 |
-
print(f"β Error initializing
|
| 913 |
raise
|
| 914 |
|
| 915 |
# Agent Node with AGGRESSIVE tool forcing
|
|
|
|
| 743 |
|
| 744 |
# 3. If last message is AIMessage with tool calls
|
| 745 |
if isinstance(last_message, AIMessage) and last_message.tool_calls:
|
| 746 |
+
# Only check the FIRST tool call, not all of them
|
| 747 |
+
first_tool = last_message.tool_calls[0]
|
| 748 |
+
tool_name = first_tool.get("name", "")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 749 |
|
| 750 |
+
if tool_name == "final_answer_tool":
|
| 751 |
+
return END
|
| 752 |
+
else:
|
| 753 |
+
return "tools"
|
| 754 |
|
| 755 |
# 4. If AIMessage but no tool calls (reasoning text)
|
| 756 |
if isinstance(last_message, AIMessage) and not last_message.tool_calls:
|
|
|
|
| 893 |
|
| 894 |
print("Initializing Groq LLM...")
|
| 895 |
try:
|
| 896 |
+
#. Initialize the LLM ()
|
| 897 |
+
self.llm_with_tools = HuggingFaceEndpoint(
|
| 898 |
+
repo_id="HuggingFaceH4/zephyr-7b-beta", # Changed model
|
| 899 |
+
huggingfacehub_api_token=HUGGINGFACEHUB_API_TOKEN,
|
| 900 |
+
max_new_tokens=2048, # Increased token limit for potentially longer reasoning/tool use
|
| 901 |
+
temperature=0.01, # Keep temperature low for factual tasks
|
| 902 |
# Use tool_choice="any" to FORCE tool usage
|
| 903 |
+
# self.llm_with_tools = ChatGroq(
|
| 904 |
+
# temperature=0,
|
| 905 |
+
# groq_api_key=GROQ_API_KEY,
|
| 906 |
+
# model_name="llama-3.3-70b-versatile",
|
| 907 |
+
# max_tokens=4096,
|
| 908 |
+
#timeout=60
|
| 909 |
+
).bind_tools(self.tools, tool_choice="auto") # FORCE tool calls
|
| 910 |
print("β
LLM initialized with FORCED tool usage.")
|
| 911 |
|
| 912 |
except Exception as e:
|
| 913 |
+
print(f"β Error initializing HuggingFace: {e}")
|
| 914 |
raise
|
| 915 |
|
| 916 |
# Agent Node with AGGRESSIVE tool forcing
|