Luigi D'Addona commited on
Commit
7cfe271
·
1 Parent(s): ba25c91

aggiunto delay tra le invocazioni ai tool

Browse files
Files changed (1) hide show
  1. agent.py +9 -1
agent.py CHANGED
@@ -1,6 +1,7 @@
1
  import os
2
  from dotenv import load_dotenv
3
  import traceback
 
4
 
5
  from typing import Annotated,Sequence, TypedDict
6
 
@@ -22,6 +23,8 @@ GEMINI_MODEL = os.environ.get("GEMINI_MODEL")
22
  GEMINI_BASE_URL = os.environ.get("GEMINI_BASE_URL")
23
  GEMINI_TEMPERATURE = float(os.environ.get("GEMINI_TEMPERATURE"))
24
 
 
 
25
  #
26
  # Inizializza il modello e gli associa i tool
27
  #
@@ -59,7 +62,7 @@ class AgentState(TypedDict):
59
  def call_tool(state: AgentState):
60
  outputs = []
61
  # Iterate over the tool calls in the last message
62
- for tool_call in state["messages"][-1].tool_calls:
63
  # Get the tool by name
64
  tool_result = tools_by_name[tool_call["name"]].invoke(tool_call["args"])
65
 
@@ -74,6 +77,11 @@ def call_tool(state: AgentState):
74
  tool_call_id=tool_call["id"],
75
  )
76
  )
 
 
 
 
 
77
  return {"messages": outputs}
78
 
79
 
 
1
  import os
2
  from dotenv import load_dotenv
3
  import traceback
4
+ import time
5
 
6
  from typing import Annotated,Sequence, TypedDict
7
 
 
23
  GEMINI_BASE_URL = os.environ.get("GEMINI_BASE_URL")
24
  GEMINI_TEMPERATURE = float(os.environ.get("GEMINI_TEMPERATURE"))
25
 
26
+ TOOLS_CALL_DELAY = 1.5
27
+
28
  #
29
  # Inizializza il modello e gli associa i tool
30
  #
 
62
  def call_tool(state: AgentState):
63
  outputs = []
64
  # Iterate over the tool calls in the last message
65
+ for i, tool_call in enumerate(state["messages"][-1].tool_calls):
66
  # Get the tool by name
67
  tool_result = tools_by_name[tool_call["name"]].invoke(tool_call["args"])
68
 
 
77
  tool_call_id=tool_call["id"],
78
  )
79
  )
80
+
81
+ # Add a delay after each tool call, but not after the very last one
82
+ if i < len(state["messages"][-1].tool_calls) - 1:
83
+ time.sleep(TOOLS_CALL_DELAY)
84
+
85
  return {"messages": outputs}
86
 
87