π OpenHands: AI-Driven Development
Support multiline and default user messages (#5400)
Engel Nyst1146b6248bb8
diff --git a/openhands/core/config/utils.py b/openhands/core/config/utils.pyindex 00f41dc1da..6f29066019 100644--- a/openhands/core/config/utils.py+++ b/openhands/core/config/utils.py@@ -376,6 +376,11 @@ def get_parser() -> argparse.ArgumentParser:type=str,help='The comma-separated list (in quotes) of IDs of the instances to evaluate',)+ parser.add_argument(+ '--no-auto-continue',+ action='store_true',+ help='Disable automatic "continue" responses. Will read from stdin instead.',+ )return parserdiff --git a/openhands/core/main.py b/openhands/core/main.pyindex d55aa01751..3be74235ba 100644--- a/openhands/core/main.py+++ b/openhands/core/main.py@@ -188,7 +188,9 @@ async def run_controller(if exit_on_message:message = '/exit'elif fake_user_response_fn is None:- message = input('Request user input >> ')+ # read until EOF (Ctrl+D on Unix, Ctrl+Z on Windows)+ print('Request user input (press Ctrl+D/Z when done) >> ')+ message = sys.stdin.read().rstrip()else:message = fake_user_response_fn(controller.get_state())action = MessageAction(content=message)@@ -241,6 +243,17 @@ def generate_sid(config: AppConfig, session_name: str | None = None) -> str:return f'{session_name}-{hash_str[:16]}'+def auto_continue_response(+ state: State,+ encapsulate_solution: bool = False,+ try_parse: Callable[[Action | None], str] | None = None,+) -> str:+ """Default function to generate user responses.+ Returns 'continue' to tell the agent to proceed without asking for more input.+ """+ return 'continue'++if __name__ == '__main__':args = parse_arguments()@@ -284,5 +297,8 @@ if __name__ == '__main__':config=config,initial_user_action=initial_user_action,sid=sid,+ fake_user_response_fn=None+ if args.no_auto_continue+ else auto_continue_response,))diff --git a/tests/unit/test_arg_parser.py b/tests/unit/test_arg_parser.pyindex 6788904ced..45b9a47374 100644--- a/tests/unit/test_arg_parser.py+++ b/tests/unit/test_arg_parser.py@@ -19,6 +19,7 @@ def test_parser_default_values():assert args.eval_note is Noneassert args.llm_config is Noneassert args.name == 'default'+ assert not args.no_auto_continuedef test_parser_custom_values():@@ -49,6 +50,7 @@ def test_parser_custom_values():'gpt4','-n','test_session',+ '--no-auto-continue',])@@ -64,6 +66,7 @@ def test_parser_custom_values():assert args.eval_note == 'Test run'assert args.llm_config == 'gpt4'assert args.name == 'test_session'+ assert args.no_auto_continuedef test_parser_file_overrides_task():@@ -124,10 +127,11 @@ def test_help_message(capsys):'-l LLM_CONFIG, --llm-config LLM_CONFIG','-n NAME, --name NAME','--config-file CONFIG_FILE',+ '--no-auto-continue',]for element in expected_elements:assert element in help_output, f"Expected '{element}' to be in the help message"option_count = help_output.count(' -')- assert option_count == 15, f'Expected 15 options, found {option_count}'+ assert option_count == 16, f'Expected 16 options, found {option_count}'