Selaa lähdekoodia

add error obs to codeact SWE (#3392)

Engel Nyst 1 vuosi sitten
vanhempi
sitoutus
463c66a372
1 muutettua tiedostoa jossa 10 lisäystä ja 2 poistoa
  1. 10 2
      agenthub/codeact_swe_agent/codeact_swe_agent.py

+ 10 - 2
agenthub/codeact_swe_agent/codeact_swe_agent.py

@@ -19,6 +19,7 @@ from opendevin.events.observation import (
     CmdOutputObservation,
     IPythonRunCellObservation,
 )
+from opendevin.events.observation.error import ErrorObservation
 from opendevin.events.observation.observation import Observation
 from opendevin.events.serialization.event import truncate_content
 from opendevin.llm.llm import LLM
@@ -66,7 +67,7 @@ class CodeActSWEAgent(Agent):
         self,
         llm: LLM,
     ) -> None:
-        """Initializes a new instance of the CodeActAgent class.
+        """Initializes a new instance of the CodeActSWEAgent class.
 
         Parameters:
         - llm (LLM): The llm to be used by this agent
@@ -122,7 +123,14 @@ class CodeActSWEAgent(Agent):
             text = '\n'.join(splitted)
             text = truncate_content(text, max_message_chars)
             return Message(role='user', content=[TextContent(text=text)])
-        return None
+        elif isinstance(obs, ErrorObservation):
+            text = 'OBSERVATION:\n' + truncate_content(obs.content, max_message_chars)
+            text += '\n[Error occurred in processing last action]'
+            return Message(role='user', content=[TextContent(text=text)])
+        else:
+            # If an observation message is not returned, it will cause an error
+            # when the LLM tries to return the next message
+            raise ValueError(f'Unknown observation type: {type(obs)}')
 
     def reset(self) -> None:
         """Resets the CodeAct Agent."""