Spaces:
Runtime error
Runtime error
update context manager
Browse files
app.py
CHANGED
|
@@ -589,14 +589,18 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 589 |
# Override CodeAgent run to automatically clear context periodically
|
| 590 |
original_code_agent_run = CodeAgent.run
|
| 591 |
|
| 592 |
-
def context_managed_run(self, query, max_steps=None, persist_conversation=None):
|
| 593 |
-
"""Override to periodically clear conversation context after steps"""
|
| 594 |
# Initialize step counter if not present
|
| 595 |
if not hasattr(self, '_context_step_counter'):
|
| 596 |
self._context_step_counter = 0
|
| 597 |
|
| 598 |
-
#
|
| 599 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 600 |
|
| 601 |
# Every 5 steps, perform aggressive context management
|
| 602 |
if self._context_step_counter >= 5:
|
|
@@ -620,8 +624,8 @@ def context_managed_run(self, query, max_steps=None, persist_conversation=None):
|
|
| 620 |
|
| 621 |
print(f"Conversation history trimmed from {original_length} to {len(self.conversation)} messages")
|
| 622 |
|
| 623 |
-
# Call the original run method
|
| 624 |
-
return original_code_agent_run(self, query, max_steps, persist_conversation)
|
| 625 |
|
| 626 |
# Apply the monkey patch to CodeAgent class
|
| 627 |
CodeAgent.run = context_managed_run
|
|
|
|
| 589 |
# Override CodeAgent run to automatically clear context periodically
|
| 590 |
original_code_agent_run = CodeAgent.run
|
| 591 |
|
| 592 |
+
def context_managed_run(self, query, max_steps=None, persist_conversation=None, stream=False, reset=False, additional_args=None):
|
| 593 |
+
"""Override to periodically clear conversation context after steps."""
|
| 594 |
# Initialize step counter if not present
|
| 595 |
if not hasattr(self, '_context_step_counter'):
|
| 596 |
self._context_step_counter = 0
|
| 597 |
|
| 598 |
+
# Reset counter if reset is requested
|
| 599 |
+
if reset:
|
| 600 |
+
self._context_step_counter = 0
|
| 601 |
+
else:
|
| 602 |
+
# Increment counter
|
| 603 |
+
self._context_step_counter += 1
|
| 604 |
|
| 605 |
# Every 5 steps, perform aggressive context management
|
| 606 |
if self._context_step_counter >= 5:
|
|
|
|
| 624 |
|
| 625 |
print(f"Conversation history trimmed from {original_length} to {len(self.conversation)} messages")
|
| 626 |
|
| 627 |
+
# Call the original run method with all parameters (including stream)
|
| 628 |
+
return original_code_agent_run(self, query, max_steps, persist_conversation, stream=stream, reset=reset, additional_args=additional_args)
|
| 629 |
|
| 630 |
# Apply the monkey patch to CodeAgent class
|
| 631 |
CodeAgent.run = context_managed_run
|