Skip to content

πŸ™Œ OpenHands: AI-Driven Development

Make sure we print the observation in the same way as the LLM sees it

Xingyao Wange03855cd7fe4
diff --git a/openhands/controller/agent_controller.py b/openhands/controller/agent_controller.py
index 29bb27e220..2b76a82a57 100644
--- a/openhands/controller/agent_controller.py
+++ b/openhands/controller/agent_controller.py
@@ -1,4 +1,5 @@
import asyncio
+import copy
import traceback
from typing import Type
@@ -36,6 +37,7 @@ from openhands.events.observation import (
ErrorObservation,
Observation,
)
+from openhands.events.serialization.event import truncate_content
from openhands.llm.llm import LLM
from openhands.runtime.utils.shutdown_listener import should_continue
@@ -220,7 +222,13 @@ class AgentController:
):
return
- logger.info(observation, extra={'msg_type': 'OBSERVATION'})
+ # Make sure we print the observation in the same way as the LLM sees it
+ observation_to_print = copy.deepcopy(observation)
+ if len(observation_to_print.content) > self.agent.llm.config.max_message_chars:
+ observation_to_print.content = truncate_content(
+ observation_to_print.content, self.agent.llm.config.max_message_chars
+ )
+ logger.info(observation_to_print, extra={'msg_type': 'OBSERVATION'})
if self._pending_action and self._pending_action.id == observation.cause:
self._pending_action = None
if self.state.agent_state == AgentState.USER_CONFIRMED: