Refactor: Clean up obsolete files and organize codebase structure
This commit removes deprecated modules and reorganizes code into logical directories: Deleted files (superseded by newer systems): - claude_code_server.py (replaced by agent-sdk direct integration) - heartbeat.py (superseded by scheduled_tasks.py) - pulse_brain.py (unused in production) - config/pulse_brain_config.py (obsolete config) Created directory structure: - examples/ (7 example files: example_*.py, demo_*.py) - tests/ (5 test files: test_*.py) Updated imports: - agent.py: Removed heartbeat module and all enable_heartbeat logic - bot_runner.py: Removed heartbeat parameter from Agent initialization - llm_interface.py: Updated deprecated claude_code_server message Preserved essential files: - hooks.py (for future use) - adapters/skill_integration.py (for future use) - All Google integration tools (Gmail, Calendar, Contacts) - GLM provider code (backward compatibility) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
22
agent.py
22
agent.py
@@ -3,7 +3,6 @@
|
||||
import threading
|
||||
from typing import List, Optional
|
||||
|
||||
from heartbeat import Heartbeat
|
||||
from hooks import HooksSystem
|
||||
from llm_interface import LLMInterface
|
||||
from memory_system import MemorySystem
|
||||
@@ -11,7 +10,7 @@ from self_healing import SelfHealingSystem
|
||||
from tools import TOOL_DEFINITIONS, execute_tool
|
||||
|
||||
# Maximum number of recent messages to include in LLM context
|
||||
MAX_CONTEXT_MESSAGES = 3 # Reduced from 5 to save tokens
|
||||
MAX_CONTEXT_MESSAGES = 10 # Increased for better context retention
|
||||
# Maximum characters of agent response to store in memory
|
||||
MEMORY_RESPONSE_PREVIEW_LENGTH = 200
|
||||
# Maximum conversation history entries before pruning
|
||||
@@ -19,13 +18,12 @@ MAX_CONVERSATION_HISTORY = 50
|
||||
|
||||
|
||||
class Agent:
|
||||
"""AI Agent with memory, LLM, heartbeat, and hooks."""
|
||||
"""AI Agent with memory, LLM, and hooks."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
provider: str = "claude",
|
||||
workspace_dir: str = "./memory_workspace",
|
||||
enable_heartbeat: bool = False,
|
||||
) -> None:
|
||||
self.memory = MemorySystem(workspace_dir)
|
||||
self.llm = LLMInterface(provider)
|
||||
@@ -37,12 +35,6 @@ class Agent:
|
||||
self.memory.sync()
|
||||
self.hooks.trigger("agent", "startup", {"workspace_dir": workspace_dir})
|
||||
|
||||
self.heartbeat: Optional[Heartbeat] = None
|
||||
if enable_heartbeat:
|
||||
self.heartbeat = Heartbeat(self.memory, self.llm)
|
||||
self.heartbeat.on_alert = self._on_heartbeat_alert
|
||||
self.heartbeat.start()
|
||||
|
||||
def _get_context_messages(self, max_messages: int) -> List[dict]:
|
||||
"""Get recent messages without breaking tool_use/tool_result pairs.
|
||||
|
||||
@@ -91,10 +83,6 @@ class Agent:
|
||||
|
||||
return result
|
||||
|
||||
def _on_heartbeat_alert(self, message: str) -> None:
|
||||
"""Handle heartbeat alerts."""
|
||||
print(f"\nHeartbeat Alert:\n{message}\n")
|
||||
|
||||
def _prune_conversation_history(self) -> None:
|
||||
"""Prune conversation history to prevent unbounded growth.
|
||||
|
||||
@@ -172,7 +160,7 @@ class Agent:
|
||||
self._prune_conversation_history()
|
||||
|
||||
# Tool execution loop
|
||||
max_iterations = 5 # Reduced from 10 to save costs
|
||||
max_iterations = 15 # Increased for complex multi-step operations
|
||||
# Enable caching for Sonnet to save 90% on repeated system prompts
|
||||
use_caching = "sonnet" in self.llm.model.lower()
|
||||
|
||||
@@ -282,13 +270,9 @@ class Agent:
|
||||
def switch_model(self, provider: str) -> None:
|
||||
"""Switch LLM provider."""
|
||||
self.llm = LLMInterface(provider)
|
||||
if self.heartbeat:
|
||||
self.heartbeat.llm = self.llm
|
||||
|
||||
def shutdown(self) -> None:
|
||||
"""Cleanup and stop background services."""
|
||||
if self.heartbeat:
|
||||
self.heartbeat.stop()
|
||||
self.memory.close()
|
||||
self.hooks.trigger("agent", "shutdown", {})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user