gabejavitt commited on
Commit
46d109c
Β·
verified Β·
1 Parent(s): 1d49677

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -20
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
- # Check each tool call explicitly
747
- for tc in last_message.tool_calls:
748
- tool_name = tc.get("name", "")
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
- # Not final answer, route to tools
757
- print(f"πŸ”„ Routing to tools node")
758
- return "tools"
 
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
- self.llm_with_tools = ChatGroq(
903
- temperature=0,
904
- groq_api_key=GROQ_API_KEY,
905
- model_name="llama-3.3-70b-versatile",
906
- max_tokens=4096,
907
- timeout=60
908
- ).bind_tools(self.tools, tool_choice="any") # FORCE tool calls
909
  print("βœ… LLM initialized with FORCED tool usage.")
910
 
911
  except Exception as e:
912
- print(f"❌ Error initializing Groq: {e}")
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