Fixed stdin buffer length in context
This commit is contained in:
@@ -50,7 +50,7 @@ class BaseAgent(ABC):
|
||||
"""
|
||||
memory_context = self._working_memory.generate_context()
|
||||
context_size = len(memory_context) / 100
|
||||
context = self._metrics.generate_context(context_size)
|
||||
context = self._metrics.generate_context(context_size, self._parser.io_buffer.buffer_length())
|
||||
for entry in memory_context:
|
||||
context.append(entry)
|
||||
return pretty_print_element(context)
|
||||
@@ -7,8 +7,9 @@ from .command import Command
|
||||
from .delete_command import DeleteCommand
|
||||
from .stop_command import StopCommand
|
||||
|
||||
from .entry import Entry
|
||||
from .background_entry import BackgroundEntry
|
||||
from .entry import Entry
|
||||
from .io_buffer import IOBuffer
|
||||
from .parse_error_entry import ParseErrorEntry
|
||||
from .read_entry import ReadEntry
|
||||
from .reasoning_entry import ReasoningEntry
|
||||
@@ -28,14 +29,24 @@ class ResponseParser:
|
||||
io_buffer: Buffer to use for IO operations
|
||||
"""
|
||||
|
||||
def __init__(self, io_buffer):
|
||||
def __init__(self, io_buffer: IOBuffer):
|
||||
"""
|
||||
Initialize parser with IO buffer.
|
||||
|
||||
Args:
|
||||
io_buffer: Buffer to use for IO operations
|
||||
"""
|
||||
self.io_buffer = io_buffer
|
||||
self._io_buffer = io_buffer
|
||||
|
||||
@property
|
||||
def io_buffer(self) -> IOBuffer:
|
||||
"""
|
||||
Get the IO buffer used by the parser.
|
||||
|
||||
Returns:
|
||||
IOBuffer: Buffer used for IO operations
|
||||
"""
|
||||
return self._io_buffer
|
||||
|
||||
def parse(self, xml: str) -> Union[Command, Entry]:
|
||||
"""
|
||||
@@ -101,12 +112,12 @@ class ResponseParser:
|
||||
return ReasoningEntry(entry_id, timestamp, root.text)
|
||||
|
||||
elif root.tag == 'read_stdin':
|
||||
return ReadEntry(entry_id, timestamp, self.io_buffer)
|
||||
return ReadEntry(entry_id, timestamp, self._io_buffer)
|
||||
|
||||
elif root.tag == 'write_stdout':
|
||||
if len(root) != 0 or root.attrib or root.text is None or root.text.strip() == '':
|
||||
return ParseErrorEntry(entry_id, timestamp, xml, "Write stdout entry requires (only) text content")
|
||||
return WriteEntry(entry_id, timestamp, root.text, self.io_buffer)
|
||||
return WriteEntry(entry_id, timestamp, root.text, self._io_buffer)
|
||||
|
||||
else:
|
||||
return ParseErrorEntry(entry_id, timestamp, xml, f"Unknown root element: {root.tag}")
|
||||
|
||||
@@ -69,7 +69,7 @@ class SystemMetrics:
|
||||
|
||||
time.sleep(self._sample_interval)
|
||||
|
||||
def generate_context(self, context_usage: float) -> ET.Element:
|
||||
def generate_context(self, context_usage: float, stdin_buffer_length: int) -> ET.Element:
|
||||
"""
|
||||
Generate XML context element with current system metrics.
|
||||
Clears usage samples after generating averages.
|
||||
@@ -112,7 +112,7 @@ class SystemMetrics:
|
||||
context.set("context_usage", str(round(context_usage * 100)))
|
||||
|
||||
# Standard input buffer size
|
||||
context.set("stdin", "0") # Set by agent
|
||||
context.set("stdin", stdin_buffer_length)
|
||||
|
||||
return context
|
||||
|
||||
|
||||
Reference in New Issue
Block a user