<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def update_agent_requirements(req_file, check, newline):
 """ Replace the requirements line for the given check """

    package_name = get_package_name(check)
    lines = read_file_lines(req_file)

    for i, line in enumerate(lines):
        current_package_name = line.split('==')[0]

        if current_package_name == package_name:
            lines[i] = '{}\n'.format(newline)
            break

    write_file_lines(req_file, sorted(lines))