diff --git a/agenthub/codeact_agent/codeact_agent.py b/agenthub/codeact_agent/codeact_agent.py index 319b01e2925a..08af8ca95ab9 100644 --- a/agenthub/codeact_agent/codeact_agent.py +++ b/agenthub/codeact_agent/codeact_agent.py @@ -222,7 +222,13 @@ def _get_messages(self, state: State) -> list[dict[str, str]]: # add regular message if message: - messages.append(message) + # handle error if the message is the SAME role as the previous message + # litellm.exceptions.BadRequestError: litellm.BadRequestError: OpenAIException - Error code: 400 - {'detail': 'Only supports u/a/u/a/u...'} + # there should not have two consecutive messages from the same role + if messages and messages[-1]['role'] == message['role']: + messages[-1]['content'] += '\n\n' + message['content'] + else: + messages.append(message) # the latest user message is important: # we want to remind the agent of the environment constraints diff --git a/agenthub/codeact_swe_agent/codeact_swe_agent.py b/agenthub/codeact_swe_agent/codeact_swe_agent.py index d150af840558..67ed646ee2c2 100644 --- a/agenthub/codeact_swe_agent/codeact_swe_agent.py +++ b/agenthub/codeact_swe_agent/codeact_swe_agent.py @@ -173,7 +173,13 @@ def _get_messages(self, state: State) -> list[dict[str, str]]: # add regular message if message: - messages.append(message) + # handle error if the message is the SAME role as the previous message + # litellm.exceptions.BadRequestError: litellm.BadRequestError: OpenAIException - Error code: 400 - {'detail': 'Only supports u/a/u/a/u...'} + # there should not have two consecutive messages from the same role + if messages and messages[-1]['role'] == message['role']: + messages[-1]['content'] += '\n\n' + message['content'] + else: + messages.append(message) # the latest user message is important: # we want to remind the agent of the environment constraints diff --git a/tests/integration/mock/CodeActAgent/test_browse_internet/prompt_001.log b/tests/integration/mock/CodeActAgent/test_browse_internet/prompt_001.log index 0fdee5cca180..69b4fa0e9608 100644 --- a/tests/integration/mock/CodeActAgent/test_browse_internet/prompt_001.log +++ b/tests/integration/mock/CodeActAgent/test_browse_internet/prompt_001.log @@ -396,8 +396,6 @@ The server is running on port 5000 with PID 126. You can access the list of numb NOW, LET'S START! ----------- - Browse localhost:8000, and tell me the ultimate answer to life. Do not ask me for confirmation at any point. ENVIRONMENT REMINDER: You have 14 turns left to complete the task. When finished reply with diff --git a/tests/integration/mock/CodeActAgent/test_browse_internet/prompt_005.log b/tests/integration/mock/CodeActAgent/test_browse_internet/prompt_005.log index 645ac5d1ef0f..0f8e9046da08 100644 --- a/tests/integration/mock/CodeActAgent/test_browse_internet/prompt_005.log +++ b/tests/integration/mock/CodeActAgent/test_browse_internet/prompt_005.log @@ -396,8 +396,6 @@ The server is running on port 5000 with PID 126. You can access the list of numb NOW, LET'S START! ----------- - Browse localhost:8000, and tell me the ultimate answer to life. Do not ask me for confirmation at any point. ---------- diff --git a/tests/integration/mock/CodeActAgent/test_edits/prompt_001.log b/tests/integration/mock/CodeActAgent/test_edits/prompt_001.log index 83437bb6c130..2d38aad3653c 100644 --- a/tests/integration/mock/CodeActAgent/test_edits/prompt_001.log +++ b/tests/integration/mock/CodeActAgent/test_edits/prompt_001.log @@ -396,8 +396,6 @@ The server is running on port 5000 with PID 126. You can access the list of numb NOW, LET'S START! ----------- - Fix typos in bad.txt. Do not ask me for confirmation at any point. ENVIRONMENT REMINDER: You have 14 turns left to complete the task. When finished reply with diff --git a/tests/integration/mock/CodeActAgent/test_edits/prompt_002.log b/tests/integration/mock/CodeActAgent/test_edits/prompt_002.log index 14ca3b1ee863..7dc980e2cfbe 100644 --- a/tests/integration/mock/CodeActAgent/test_edits/prompt_002.log +++ b/tests/integration/mock/CodeActAgent/test_edits/prompt_002.log @@ -396,8 +396,6 @@ The server is running on port 5000 with PID 126. You can access the list of numb NOW, LET'S START! ----------- - Fix typos in bad.txt. Do not ask me for confirmation at any point. ---------- diff --git a/tests/integration/mock/CodeActAgent/test_edits/prompt_003.log b/tests/integration/mock/CodeActAgent/test_edits/prompt_003.log index c154368638e1..788623380816 100644 --- a/tests/integration/mock/CodeActAgent/test_edits/prompt_003.log +++ b/tests/integration/mock/CodeActAgent/test_edits/prompt_003.log @@ -396,8 +396,6 @@ The server is running on port 5000 with PID 126. You can access the list of numb NOW, LET'S START! ----------- - Fix typos in bad.txt. Do not ask me for confirmation at any point. ---------- diff --git a/tests/integration/mock/CodeActAgent/test_edits/prompt_004.log b/tests/integration/mock/CodeActAgent/test_edits/prompt_004.log index 5234b65b2aca..3c0b337c13bb 100644 --- a/tests/integration/mock/CodeActAgent/test_edits/prompt_004.log +++ b/tests/integration/mock/CodeActAgent/test_edits/prompt_004.log @@ -396,8 +396,6 @@ The server is running on port 5000 with PID 126. You can access the list of numb NOW, LET'S START! ----------- - Fix typos in bad.txt. Do not ask me for confirmation at any point. ---------- diff --git a/tests/integration/mock/CodeActAgent/test_edits/prompt_005.log b/tests/integration/mock/CodeActAgent/test_edits/prompt_005.log index 9d3c125ec7e5..42b28cbdd64c 100644 --- a/tests/integration/mock/CodeActAgent/test_edits/prompt_005.log +++ b/tests/integration/mock/CodeActAgent/test_edits/prompt_005.log @@ -396,8 +396,6 @@ The server is running on port 5000 with PID 126. You can access the list of numb NOW, LET'S START! ----------- - Fix typos in bad.txt. Do not ask me for confirmation at any point. ---------- diff --git a/tests/integration/mock/CodeActAgent/test_ipython/prompt_001.log b/tests/integration/mock/CodeActAgent/test_ipython/prompt_001.log index c0b99ce0e67f..2ad15757b95d 100644 --- a/tests/integration/mock/CodeActAgent/test_ipython/prompt_001.log +++ b/tests/integration/mock/CodeActAgent/test_ipython/prompt_001.log @@ -396,8 +396,6 @@ The server is running on port 5000 with PID 126. You can access the list of numb NOW, LET'S START! ----------- - Use Jupyter IPython to write a text file containing 'hello world' to '/workspace/test.txt'. Do not ask me for confirmation at any point. ENVIRONMENT REMINDER: You have 14 turns left to complete the task. When finished reply with diff --git a/tests/integration/mock/CodeActAgent/test_ipython/prompt_002.log b/tests/integration/mock/CodeActAgent/test_ipython/prompt_002.log index 544403208a92..42feaa6dca98 100644 --- a/tests/integration/mock/CodeActAgent/test_ipython/prompt_002.log +++ b/tests/integration/mock/CodeActAgent/test_ipython/prompt_002.log @@ -396,8 +396,6 @@ The server is running on port 5000 with PID 126. You can access the list of numb NOW, LET'S START! ----------- - Use Jupyter IPython to write a text file containing 'hello world' to '/workspace/test.txt'. Do not ask me for confirmation at any point. ---------- diff --git a/tests/integration/mock/CodeActAgent/test_ipython/prompt_003.log b/tests/integration/mock/CodeActAgent/test_ipython/prompt_003.log index 1eb6cc6274c4..152fce2f9292 100644 --- a/tests/integration/mock/CodeActAgent/test_ipython/prompt_003.log +++ b/tests/integration/mock/CodeActAgent/test_ipython/prompt_003.log @@ -396,8 +396,6 @@ The server is running on port 5000 with PID 126. You can access the list of numb NOW, LET'S START! ----------- - Use Jupyter IPython to write a text file containing 'hello world' to '/workspace/test.txt'. Do not ask me for confirmation at any point. ---------- diff --git a/tests/integration/mock/CodeActAgent/test_ipython_module/prompt_001.log b/tests/integration/mock/CodeActAgent/test_ipython_module/prompt_001.log index ed28f3b2ad5f..d67b66123373 100644 --- a/tests/integration/mock/CodeActAgent/test_ipython_module/prompt_001.log +++ b/tests/integration/mock/CodeActAgent/test_ipython_module/prompt_001.log @@ -396,8 +396,6 @@ The server is running on port 5000 with PID 126. You can access the list of numb NOW, LET'S START! ----------- - Install and import pymsgbox==1.0.9 and print it's version in /workspace/test.txt. Do not ask me for confirmation at any point. ENVIRONMENT REMINDER: You have 14 turns left to complete the task. When finished reply with diff --git a/tests/integration/mock/CodeActAgent/test_ipython_module/prompt_002.log b/tests/integration/mock/CodeActAgent/test_ipython_module/prompt_002.log index 5b67d2523375..19cfefab7e3f 100644 --- a/tests/integration/mock/CodeActAgent/test_ipython_module/prompt_002.log +++ b/tests/integration/mock/CodeActAgent/test_ipython_module/prompt_002.log @@ -396,8 +396,6 @@ The server is running on port 5000 with PID 126. You can access the list of numb NOW, LET'S START! ----------- - Install and import pymsgbox==1.0.9 and print it's version in /workspace/test.txt. Do not ask me for confirmation at any point. ---------- diff --git a/tests/integration/mock/CodeActAgent/test_ipython_module/prompt_003.log b/tests/integration/mock/CodeActAgent/test_ipython_module/prompt_003.log index a5e6549bf391..e0b458c592ee 100644 --- a/tests/integration/mock/CodeActAgent/test_ipython_module/prompt_003.log +++ b/tests/integration/mock/CodeActAgent/test_ipython_module/prompt_003.log @@ -396,8 +396,6 @@ The server is running on port 5000 with PID 126. You can access the list of numb NOW, LET'S START! ----------- - Install and import pymsgbox==1.0.9 and print it's version in /workspace/test.txt. Do not ask me for confirmation at any point. ---------- diff --git a/tests/integration/mock/CodeActAgent/test_ipython_module/prompt_004.log b/tests/integration/mock/CodeActAgent/test_ipython_module/prompt_004.log index c4c317508065..b2ccaff50395 100644 --- a/tests/integration/mock/CodeActAgent/test_ipython_module/prompt_004.log +++ b/tests/integration/mock/CodeActAgent/test_ipython_module/prompt_004.log @@ -396,8 +396,6 @@ The server is running on port 5000 with PID 126. You can access the list of numb NOW, LET'S START! ----------- - Install and import pymsgbox==1.0.9 and print it's version in /workspace/test.txt. Do not ask me for confirmation at any point. ---------- diff --git a/tests/integration/mock/CodeActAgent/test_write_simple_script/prompt_001.log b/tests/integration/mock/CodeActAgent/test_write_simple_script/prompt_001.log index 312e3661301a..1a08637d5d28 100644 --- a/tests/integration/mock/CodeActAgent/test_write_simple_script/prompt_001.log +++ b/tests/integration/mock/CodeActAgent/test_write_simple_script/prompt_001.log @@ -396,8 +396,6 @@ The server is running on port 5000 with PID 126. You can access the list of numb NOW, LET'S START! ----------- - Write a shell script 'hello.sh' that prints 'hello'. Do not ask me for confirmation at any point. ENVIRONMENT REMINDER: You have 14 turns left to complete the task. When finished reply with diff --git a/tests/integration/mock/CodeActAgent/test_write_simple_script/prompt_002.log b/tests/integration/mock/CodeActAgent/test_write_simple_script/prompt_002.log index ca4f9fe02e92..2514d8433983 100644 --- a/tests/integration/mock/CodeActAgent/test_write_simple_script/prompt_002.log +++ b/tests/integration/mock/CodeActAgent/test_write_simple_script/prompt_002.log @@ -396,8 +396,6 @@ The server is running on port 5000 with PID 126. You can access the list of numb NOW, LET'S START! ----------- - Write a shell script 'hello.sh' that prints 'hello'. Do not ask me for confirmation at any point. ---------- diff --git a/tests/integration/mock/CodeActAgent/test_write_simple_script/prompt_003.log b/tests/integration/mock/CodeActAgent/test_write_simple_script/prompt_003.log index 08061310e5b2..3efd232d5aa6 100644 --- a/tests/integration/mock/CodeActAgent/test_write_simple_script/prompt_003.log +++ b/tests/integration/mock/CodeActAgent/test_write_simple_script/prompt_003.log @@ -396,8 +396,6 @@ The server is running on port 5000 with PID 126. You can access the list of numb NOW, LET'S START! ----------- - Write a shell script 'hello.sh' that prints 'hello'. Do not ask me for confirmation at any point. ---------- diff --git a/tests/integration/mock/CodeActAgent/test_write_simple_script/prompt_004.log b/tests/integration/mock/CodeActAgent/test_write_simple_script/prompt_004.log index af83dd9d138e..a3a16528873d 100644 --- a/tests/integration/mock/CodeActAgent/test_write_simple_script/prompt_004.log +++ b/tests/integration/mock/CodeActAgent/test_write_simple_script/prompt_004.log @@ -396,8 +396,6 @@ The server is running on port 5000 with PID 126. You can access the list of numb NOW, LET'S START! ----------- - Write a shell script 'hello.sh' that prints 'hello'. Do not ask me for confirmation at any point. ---------- diff --git a/tests/integration/mock/CodeActSWEAgent/test_edits/prompt_001.log b/tests/integration/mock/CodeActSWEAgent/test_edits/prompt_001.log index 0d198ce1f0cb..a94ddeb77c7e 100644 --- a/tests/integration/mock/CodeActSWEAgent/test_edits/prompt_001.log +++ b/tests/integration/mock/CodeActSWEAgent/test_edits/prompt_001.log @@ -587,8 +587,6 @@ exit NOW, LET'S START! ----------- - Fix typos in bad.txt. Do not ask me for confirmation at any point. ENVIRONMENT REMINDER: You have 14 turns left to complete the task. diff --git a/tests/integration/mock/CodeActSWEAgent/test_edits/prompt_002.log b/tests/integration/mock/CodeActSWEAgent/test_edits/prompt_002.log index 4f046938ced7..f1df309355b8 100644 --- a/tests/integration/mock/CodeActSWEAgent/test_edits/prompt_002.log +++ b/tests/integration/mock/CodeActSWEAgent/test_edits/prompt_002.log @@ -587,8 +587,6 @@ exit NOW, LET'S START! ----------- - Fix typos in bad.txt. Do not ask me for confirmation at any point. ---------- diff --git a/tests/integration/mock/CodeActSWEAgent/test_edits/prompt_003.log b/tests/integration/mock/CodeActSWEAgent/test_edits/prompt_003.log index 0ddb465d3aad..5244d8f09ebd 100644 --- a/tests/integration/mock/CodeActSWEAgent/test_edits/prompt_003.log +++ b/tests/integration/mock/CodeActSWEAgent/test_edits/prompt_003.log @@ -587,8 +587,6 @@ exit NOW, LET'S START! ----------- - Fix typos in bad.txt. Do not ask me for confirmation at any point. ---------- diff --git a/tests/integration/mock/CodeActSWEAgent/test_edits/prompt_004.log b/tests/integration/mock/CodeActSWEAgent/test_edits/prompt_004.log index 831b0fe98d47..5f49f00dc904 100644 --- a/tests/integration/mock/CodeActSWEAgent/test_edits/prompt_004.log +++ b/tests/integration/mock/CodeActSWEAgent/test_edits/prompt_004.log @@ -587,8 +587,6 @@ exit NOW, LET'S START! ----------- - Fix typos in bad.txt. Do not ask me for confirmation at any point. ---------- diff --git a/tests/integration/mock/CodeActSWEAgent/test_edits/prompt_005.log b/tests/integration/mock/CodeActSWEAgent/test_edits/prompt_005.log index ec7273367899..bf576286c41e 100644 --- a/tests/integration/mock/CodeActSWEAgent/test_edits/prompt_005.log +++ b/tests/integration/mock/CodeActSWEAgent/test_edits/prompt_005.log @@ -587,8 +587,6 @@ exit NOW, LET'S START! ----------- - Fix typos in bad.txt. Do not ask me for confirmation at any point. ---------- @@ -601,13 +599,13 @@ open_file("bad.txt") ---------- OBSERVATION: -[File: /workspace/bad.txt (4 lines total)] -(this is the beginning of the file) -1|This is a stupid typoo. -2|Really? -3|No mor typos! -4|Enjoy! -(this is the end of the file) +[File: /workspace/bad.txt (4 lines total)] +(this is the beginning of the file) +1|This is a stupid typoo. +2|Really? +3|No mor typos! +4|Enjoy! +(this is the end of the file) ---------- @@ -629,12 +627,12 @@ edit_file_by_replace( ---------- OBSERVATION: -[No exact match found in bad.txt for -``` -This is a stupid typoo. -No mor typos! -``` -] +[No exact match found in bad.txt for +``` +This is a stupid typoo. +No mor typos! +``` +] ---------- @@ -656,14 +654,14 @@ edit_file_by_replace( ---------- OBSERVATION: -[File: /workspace/bad.txt (4 lines total after edit)] -(this is the beginning of the file) -1|This is a stupid typo. -2|Really? -3|No mor typos! -4|Enjoy! -(this is the end of the file) -[File updated (edited at line 1). Please review the changes and make sure they are correct (correct indentation, no duplicate lines, etc). Edit the file again if necessary.] +[File: /workspace/bad.txt (4 lines total after edit)] +(this is the beginning of the file) +1|This is a stupid typo. +2|Really? +3|No mor typos! +4|Enjoy! +(this is the end of the file) +[File updated (edited at line 1). Please review the changes and make sure they are correct (correct indentation, no duplicate lines, etc). Edit the file again if necessary.] ---------- @@ -680,14 +678,14 @@ edit_file_by_replace( ---------- OBSERVATION: -[File: /workspace/bad.txt (4 lines total after edit)] -(this is the beginning of the file) -1|This is a stupid typo. -2|Really? -3|No more typos! -4|Enjoy! -(this is the end of the file) -[File updated (edited at line 3). Please review the changes and make sure they are correct (correct indentation, no duplicate lines, etc). Edit the file again if necessary.] +[File: /workspace/bad.txt (4 lines total after edit)] +(this is the beginning of the file) +1|This is a stupid typo. +2|Really? +3|No more typos! +4|Enjoy! +(this is the end of the file) +[File updated (edited at line 3). Please review the changes and make sure they are correct (correct indentation, no duplicate lines, etc). Edit the file again if necessary.] ENVIRONMENT REMINDER: You have 10 turns left to complete the task. diff --git a/tests/integration/mock/CodeActSWEAgent/test_ipython/prompt_001.log b/tests/integration/mock/CodeActSWEAgent/test_ipython/prompt_001.log index 69a60d8dbb95..66c5aae295ea 100644 --- a/tests/integration/mock/CodeActSWEAgent/test_ipython/prompt_001.log +++ b/tests/integration/mock/CodeActSWEAgent/test_ipython/prompt_001.log @@ -587,8 +587,6 @@ exit NOW, LET'S START! ----------- - Use Jupyter IPython to write a text file containing 'hello world' to '/workspace/test.txt'. Do not ask me for confirmation at any point. ENVIRONMENT REMINDER: You have 14 turns left to complete the task. diff --git a/tests/integration/mock/CodeActSWEAgent/test_ipython/prompt_002.log b/tests/integration/mock/CodeActSWEAgent/test_ipython/prompt_002.log index c64727d5e108..7075c75a0a68 100644 --- a/tests/integration/mock/CodeActSWEAgent/test_ipython/prompt_002.log +++ b/tests/integration/mock/CodeActSWEAgent/test_ipython/prompt_002.log @@ -587,8 +587,6 @@ exit NOW, LET'S START! ----------- - Use Jupyter IPython to write a text file containing 'hello world' to '/workspace/test.txt'. Do not ask me for confirmation at any point. ---------- diff --git a/tests/integration/mock/CodeActSWEAgent/test_ipython_module/prompt_001.log b/tests/integration/mock/CodeActSWEAgent/test_ipython_module/prompt_001.log index 65bbb95fc39d..c226985b13da 100644 --- a/tests/integration/mock/CodeActSWEAgent/test_ipython_module/prompt_001.log +++ b/tests/integration/mock/CodeActSWEAgent/test_ipython_module/prompt_001.log @@ -587,8 +587,6 @@ exit NOW, LET'S START! ----------- - Install and import pymsgbox==1.0.9 and print it's version in /workspace/test.txt. Do not ask me for confirmation at any point. ENVIRONMENT REMINDER: You have 14 turns left to complete the task. diff --git a/tests/integration/mock/CodeActSWEAgent/test_ipython_module/prompt_002.log b/tests/integration/mock/CodeActSWEAgent/test_ipython_module/prompt_002.log index 22fe91d275f4..c9c294b01b96 100644 --- a/tests/integration/mock/CodeActSWEAgent/test_ipython_module/prompt_002.log +++ b/tests/integration/mock/CodeActSWEAgent/test_ipython_module/prompt_002.log @@ -587,8 +587,6 @@ exit NOW, LET'S START! ----------- - Install and import pymsgbox==1.0.9 and print it's version in /workspace/test.txt. Do not ask me for confirmation at any point. ---------- diff --git a/tests/integration/mock/CodeActSWEAgent/test_ipython_module/prompt_003.log b/tests/integration/mock/CodeActSWEAgent/test_ipython_module/prompt_003.log index 1542f5f3e8a9..91e38ac6d3d5 100644 --- a/tests/integration/mock/CodeActSWEAgent/test_ipython_module/prompt_003.log +++ b/tests/integration/mock/CodeActSWEAgent/test_ipython_module/prompt_003.log @@ -587,8 +587,6 @@ exit NOW, LET'S START! ----------- - Install and import pymsgbox==1.0.9 and print it's version in /workspace/test.txt. Do not ask me for confirmation at any point. ---------- diff --git a/tests/integration/mock/CodeActSWEAgent/test_write_simple_script/prompt_001.log b/tests/integration/mock/CodeActSWEAgent/test_write_simple_script/prompt_001.log index 1fcc8aae387f..e94a1922c50d 100644 --- a/tests/integration/mock/CodeActSWEAgent/test_write_simple_script/prompt_001.log +++ b/tests/integration/mock/CodeActSWEAgent/test_write_simple_script/prompt_001.log @@ -587,8 +587,6 @@ exit NOW, LET'S START! ----------- - Write a shell script 'hello.sh' that prints 'hello'. Do not ask me for confirmation at any point. ENVIRONMENT REMINDER: You have 14 turns left to complete the task. diff --git a/tests/integration/mock/CodeActSWEAgent/test_write_simple_script/prompt_002.log b/tests/integration/mock/CodeActSWEAgent/test_write_simple_script/prompt_002.log index e06f9bd513a2..ef9bb1469be4 100644 --- a/tests/integration/mock/CodeActSWEAgent/test_write_simple_script/prompt_002.log +++ b/tests/integration/mock/CodeActSWEAgent/test_write_simple_script/prompt_002.log @@ -587,8 +587,6 @@ exit NOW, LET'S START! ----------- - Write a shell script 'hello.sh' that prints 'hello'. Do not ask me for confirmation at any point. ---------- diff --git a/tests/integration/mock/CodeActSWEAgent/test_write_simple_script/prompt_003.log b/tests/integration/mock/CodeActSWEAgent/test_write_simple_script/prompt_003.log index 0c54161524f8..7186f107d9f7 100644 --- a/tests/integration/mock/CodeActSWEAgent/test_write_simple_script/prompt_003.log +++ b/tests/integration/mock/CodeActSWEAgent/test_write_simple_script/prompt_003.log @@ -587,8 +587,6 @@ exit NOW, LET'S START! ----------- - Write a shell script 'hello.sh' that prints 'hello'. Do not ask me for confirmation at any point. ---------- diff --git a/tests/integration/mock/CodeActSWEAgent/test_write_simple_script/prompt_004.log b/tests/integration/mock/CodeActSWEAgent/test_write_simple_script/prompt_004.log index d8a0cfb83a1c..79be0c234017 100644 --- a/tests/integration/mock/CodeActSWEAgent/test_write_simple_script/prompt_004.log +++ b/tests/integration/mock/CodeActSWEAgent/test_write_simple_script/prompt_004.log @@ -587,8 +587,6 @@ exit NOW, LET'S START! ----------- - Write a shell script 'hello.sh' that prints 'hello'. Do not ask me for confirmation at any point. ----------