Commit 226af7c3 authored by Your Name's avatar Your Name

Add debug mode to FuzzyToolBreaker - shows tool call counts when --debug is used

parent 9770f21e
...@@ -301,8 +301,9 @@ class FuzzyToolBreaker: ...@@ -301,8 +301,9 @@ class FuzzyToolBreaker:
repeatedly trying the same failing tool call. repeatedly trying the same failing tool call.
""" """
def __init__(self, threshold=2): def __init__(self, threshold=2, debug=False):
self.threshold = threshold self.threshold = threshold
self.debug = debug
self.history = {} # Key: (tool_name, normalized_args_hash) -> Count self.history = {} # Key: (tool_name, normalized_args_hash) -> Count
def _normalize(self, data): def _normalize(self, data):
...@@ -340,6 +341,9 @@ class FuzzyToolBreaker: ...@@ -340,6 +341,9 @@ class FuzzyToolBreaker:
self.history[key] = self.history.get(key, 0) + 1 self.history[key] = self.history.get(key, 0) + 1
count = self.history[key] count = self.history[key]
if self.debug:
print(f"DEBUG FuzzyToolBreaker: {tool_name}({arguments}) -> count={count}, threshold={self.threshold}")
if count > self.threshold: if count > self.threshold:
return True, ( return True, (
f"STOP: You've attempted {tool_name} with these parameters {count} times. " f"STOP: You've attempted {tool_name} with these parameters {count} times. "
......
...@@ -542,7 +542,7 @@ class CoderClient: ...@@ -542,7 +542,7 @@ class CoderClient:
self.session_name: Optional[str] = None self.session_name: Optional[str] = None
self.input_history: List[str] = [] # Track user inputs for readline self.input_history: List[str] = [] # Track user inputs for readline
# Initialize circuit breaker for detecting repetitive tool calls # Initialize circuit breaker for detecting repetitive tool calls
self.tool_breaker = FuzzyToolBreaker(threshold=2) self.tool_breaker = FuzzyToolBreaker(threshold=2, debug=self.config.debug)
def chat(self, message: str, stream: bool = True) -> str: def chat(self, message: str, stream: bool = True) -> str:
"""Send a message to the API and get response.""" """Send a message to the API and get response."""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment