|
17 | 17 | from openhands.events.action.agent import RecallAction
|
18 | 18 | from openhands.events.event import RecallType
|
19 | 19 | from openhands.events.observation import (
|
| 20 | + AgentStateChangedObservation, |
20 | 21 | ErrorObservation,
|
21 | 22 | )
|
22 | 23 | from openhands.events.observation.agent import RecallObservation
|
@@ -217,9 +218,17 @@ def on_event_memory(event: Event):
|
217 | 218 | print(f'state: {state}')
|
218 | 219 | events = list(test_event_stream.get_events())
|
219 | 220 | print(f'event_stream: {events}')
|
| 221 | + error_observations = test_event_stream.get_matching_events( |
| 222 | + reverse=True, limit=1, event_types=(AgentStateChangedObservation) |
| 223 | + ) |
| 224 | + assert len(error_observations) == 1 |
| 225 | + error_observation = error_observations[0] |
220 | 226 | assert state.iteration == 3
|
221 | 227 | assert state.agent_state == AgentState.ERROR
|
222 | 228 | assert state.last_error == 'AgentStuckInLoopError: Agent got stuck in a loop'
|
| 229 | + assert ( |
| 230 | + error_observation.reason == 'AgentStuckInLoopError: Agent got stuck in a loop' |
| 231 | + ) |
223 | 232 | assert len(events) == 11
|
224 | 233 |
|
225 | 234 |
|
@@ -622,6 +631,17 @@ def on_event_memory(event: Event):
|
622 | 631 | state.last_error
|
623 | 632 | == 'RuntimeError: Agent reached maximum iteration in headless mode. Current iteration: 3, max iteration: 3'
|
624 | 633 | )
|
| 634 | + error_observations = test_event_stream.get_matching_events( |
| 635 | + reverse=True, limit=1, event_types=(AgentStateChangedObservation) |
| 636 | + ) |
| 637 | + assert len(error_observations) == 1 |
| 638 | + error_observation = error_observations[0] |
| 639 | + |
| 640 | + assert ( |
| 641 | + error_observation.reason |
| 642 | + == 'RuntimeError: Agent reached maximum iteration in headless mode. Current iteration: 3, max iteration: 3' |
| 643 | + ) |
| 644 | + |
625 | 645 | assert (
|
626 | 646 | state.metrics.accumulated_cost == 10.0 * 3
|
627 | 647 | ), f'Expected accumulated cost to be 30.0, but got {state.metrics.accumulated_cost}'
|
@@ -896,6 +916,16 @@ def on_event_memory(event: Event):
|
896 | 916 | == 'LLMContextWindowExceedError: Conversation history longer than LLM context window limit. Consider turning on enable_history_truncation config to avoid this error'
|
897 | 917 | )
|
898 | 918 |
|
| 919 | + error_observations = test_event_stream.get_matching_events( |
| 920 | + reverse=True, limit=1, event_types=(AgentStateChangedObservation) |
| 921 | + ) |
| 922 | + assert len(error_observations) == 1 |
| 923 | + error_observation = error_observations[0] |
| 924 | + assert ( |
| 925 | + error_observation.reason |
| 926 | + == 'LLMContextWindowExceedError: Conversation history longer than LLM context window limit. Consider turning on enable_history_truncation config to avoid this error' |
| 927 | + ) |
| 928 | + |
899 | 929 | # Check that the context window exceeded error was raised during the run
|
900 | 930 | assert step_state.has_errored
|
901 | 931 |
|
|
0 commit comments