Moved context generation to base agent instead of system_metrics
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import List
|
||||
import xml.etree.ElementTree as ET
|
||||
import time
|
||||
|
||||
from .llm_engine import LlmEngine
|
||||
from .response_parser import ResponseParser
|
||||
@@ -27,7 +28,6 @@ class BaseAgent(ABC):
|
||||
"""
|
||||
Initialize agent with required components.
|
||||
"""
|
||||
# Initialize components
|
||||
self._working_memory = working_memory
|
||||
self._metrics = system_metrics
|
||||
self._llm = llm
|
||||
@@ -48,9 +48,27 @@ class BaseAgent(ABC):
|
||||
Returns:
|
||||
str: Complete context as XML string
|
||||
"""
|
||||
# Get memory context and calculate size
|
||||
memory_context = self._working_memory.generate_context()
|
||||
context_size = len(memory_context) / 100
|
||||
context = self._metrics.generate_context(context_size, self._parser.io_buffer.buffer_length())
|
||||
|
||||
# Get system metrics
|
||||
metrics_data = self._metrics.get_metrics()
|
||||
|
||||
# Create context element with metrics
|
||||
context = ET.Element("context")
|
||||
context.set("time", metrics_data["timestamp"])
|
||||
context.set("cpu", str(metrics_data["cpu"]))
|
||||
context.set("gpu", str(metrics_data["gpu"]))
|
||||
context.set("memory_used", str(metrics_data["memory_used"]))
|
||||
context.set("memory_total", str(metrics_data["memory_total"]))
|
||||
context.set("disk_used", str(metrics_data["disk_used"]))
|
||||
context.set("disk_total", str(metrics_data["disk_total"]))
|
||||
context.set("context", str(round(context_size * 100)))
|
||||
context.set("stdin", str(self._parser.io_buffer.buffer_length()))
|
||||
|
||||
# Add memory entries
|
||||
for entry in memory_context:
|
||||
context.append(entry)
|
||||
return pretty_print_element(context)
|
||||
|
||||
return pretty_print_element(context)
|
||||
|
||||
Reference in New Issue
Block a user