Spaces:
Build error
Build error
File size: 1,540 Bytes
715112a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
import time
from smolagents import (
CodeAgent,
ToolCallingAgent,
)
class PausingCodeAgent(CodeAgent):
"""
A custom CodeAgent that pauses for a specified duration after each LLM call.
"""
def __init__(self, pause_duration=20, *args, **kwargs):
super().__init__(*args, **kwargs)
self.pause_duration = pause_duration
def step(self, memory_step):
"""
Executes a single step of the agent's reasoning, then pauses.
"""
# Pause for the specified duration
print(f"Pausing for {self.pause_duration} seconds after LLM call...")
time.sleep(self.pause_duration)
# Call the original step method to perform the LLM call and get the action
result = super().step(memory_step)
return result
class PausingToolCallingAgent(ToolCallingAgent):
"""
A custom CodeAgent that pauses for a specified duration after each LLM call.
"""
def __init__(self, pause_duration=20, *args, **kwargs):
super().__init__(*args, **kwargs)
self.pause_duration = pause_duration
def step(self, memory_step):
"""
Executes a single step of the agent's reasoning, then pauses.
"""
# Call the original step method to perform the LLM call and get the action
result = super().step(memory_step)
# Pause for the specified duration
print(f"Pausing for {self.pause_duration} seconds after LLM call...")
time.sleep(self.pause_duration)
return result |