Skip to content

Commit

Permalink
Merge branch 'main' into mh/rel0210
Browse files Browse the repository at this point in the history
  • Loading branch information
mamoodi authored Jan 21, 2025
2 parents 932db86 + 318c811 commit a4ee454
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
4 changes: 2 additions & 2 deletions evaluation/benchmarks/swe_bench/eval_infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def process_git_patch(patch):
return patch


def get_config(instance: pd.Series) -> AppConfig:
def get_config(metadata: EvalMetadata, instance: pd.Series) -> AppConfig:
# We use a different instance image for the each instance of swe-bench eval
base_container_image = get_instance_docker_image(instance['instance_id'])
logger.info(
Expand Down Expand Up @@ -132,7 +132,7 @@ def process_instance(
else:
logger.info(f'Starting evaluation for instance {instance.instance_id}.')

config = get_config(instance)
config = get_config(metadata, instance)
instance_id = instance.instance_id
model_patch = instance['model_patch']
test_spec: TestSpec = instance['test_spec']
Expand Down
9 changes: 2 additions & 7 deletions openhands/agenthub/codeact_agent/codeact_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,16 +277,11 @@ def get_observation_message(
# if it doesn't have tool call metadata, it was triggered by a user action
if obs.tool_call_metadata is None:
text = truncate_content(
f'\nObserved result of command executed by user:\n{obs.content}',
f'\nObserved result of command executed by user:\n{obs.to_agent_observation()}',
max_message_chars,
)
else:
text = truncate_content(
obs.content
+ f'\n[Python Interpreter: {obs.metadata.py_interpreter_path}]',
max_message_chars,
)
text += f'\n[Command finished with exit code {obs.exit_code}]'
text = truncate_content(obs.to_agent_observation(), max_message_chars)
message = Message(role='user', content=[TextContent(text=text)])
elif isinstance(obs, IPythonRunCellObservation):
text = obs.content
Expand Down
6 changes: 4 additions & 2 deletions openhands/events/observation/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,18 @@ def __str__(self) -> str:
f'**CmdOutputObservation (source={self.source}, exit code={self.exit_code}, '
f'metadata={json.dumps(self.metadata.model_dump(), indent=2)})**\n'
'--BEGIN AGENT OBSERVATION--\n'
f'{self._to_agent_observation()}\n'
f'{self.to_agent_observation()}\n'
'--END AGENT OBSERVATION--'
)

def _to_agent_observation(self) -> str:
def to_agent_observation(self) -> str:
ret = f'{self.metadata.prefix}{self.content}{self.metadata.suffix}'
if self.metadata.working_dir:
ret += f'\n[Current working directory: {self.metadata.working_dir}]'
if self.metadata.py_interpreter_path:
ret += f'\n[Python interpreter: {self.metadata.py_interpreter_path}]'
if self.metadata.exit_code != -1:
ret += f'\n[Command finished with exit code {self.metadata.exit_code}]'
return ret


Expand Down
2 changes: 1 addition & 1 deletion openhands/runtime/impl/docker/docker_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init__(
headless_mode: bool = True,
):
global _atexit_registered
if not _atexit_registered:
if not _atexit_registered and not config.sandbox.keep_runtime_alive:
_atexit_registered = True
atexit.register(remove_all_runtime_containers)

Expand Down
13 changes: 10 additions & 3 deletions tests/unit/test_codeact_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def agent() -> CodeActAgent:
agent = CodeActAgent(llm=LLM(LLMConfig()), config=config)
agent.llm = Mock()
agent.llm.config = Mock()
agent.llm.config.max_message_chars = 100
agent.llm.config.max_message_chars = 1000
return agent


Expand All @@ -65,19 +65,26 @@ def test_cmd_output_observation_message(agent: CodeActAgent):
content='Command output',
metadata=CmdOutputMetadata(
exit_code=0,
prefix='[THIS IS PREFIX]',
suffix='[THIS IS SUFFIX]',
),
)

results = agent.get_observation_message(obs, tool_call_id_to_message={})
tool_call_id_to_message = {}
results = agent.get_observation_message(
obs, tool_call_id_to_message=tool_call_id_to_message
)
assert len(results) == 1

result = results[0]
assert result is not None
assert result.role == 'user'
assert len(result.content) == 1
assert isinstance(result.content[0], TextContent)
assert 'Command output' in result.content[0].text
assert 'Observed result of command executed by user:' in result.content[0].text
assert '[Command finished with exit code 0]' in result.content[0].text
assert '[THIS IS PREFIX]' in result.content[0].text
assert '[THIS IS SUFFIX]' in result.content[0].text


def test_ipython_run_cell_observation_message(agent: CodeActAgent):
Expand Down

0 comments on commit a4ee454

Please sign in to comment.