mirror of
https://github.com/OpenHands/OpenHands.git
synced 2026-03-22 13:47:19 +08:00
[Agent, LLM] Make sure codeact agent produce message in u/a/u/a order (#3193)
* make sure codeact agent produce message in u/a/u/a order * integration tests * sync message changes to codeact swe * fix integration tests --------- Co-authored-by: Engel Nyst <enyst@users.noreply.github.com>
This commit is contained in:
@@ -222,7 +222,13 @@ class CodeActAgent(Agent):
|
||||
|
||||
# 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
|
||||
|
||||
@@ -173,7 +173,13 @@ class CodeActSWEAgent(Agent):
|
||||
|
||||
# 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
|
||||
|
||||
@@ -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 <finish></finish>
|
||||
|
||||
@@ -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.
|
||||
|
||||
----------
|
||||
|
||||
@@ -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 <finish></finish>
|
||||
|
||||
@@ -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.
|
||||
|
||||
----------
|
||||
|
||||
@@ -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.
|
||||
|
||||
----------
|
||||
|
||||
@@ -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.
|
||||
|
||||
----------
|
||||
|
||||
@@ -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.
|
||||
|
||||
----------
|
||||
|
||||
@@ -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 <finish></finish>
|
||||
|
||||
@@ -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.
|
||||
|
||||
----------
|
||||
|
||||
@@ -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.
|
||||
|
||||
----------
|
||||
|
||||
@@ -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 <finish></finish>
|
||||
|
||||
@@ -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.
|
||||
|
||||
----------
|
||||
|
||||
@@ -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.
|
||||
|
||||
----------
|
||||
|
||||
@@ -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.
|
||||
|
||||
----------
|
||||
|
||||
@@ -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 <finish></finish>
|
||||
|
||||
@@ -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.
|
||||
|
||||
----------
|
||||
|
||||
@@ -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.
|
||||
|
||||
----------
|
||||
|
||||
@@ -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.
|
||||
|
||||
----------
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -587,8 +587,6 @@ exit
|
||||
|
||||
NOW, LET'S START!
|
||||
|
||||
----------
|
||||
|
||||
Fix typos in bad.txt. Do not ask me for confirmation at any point.
|
||||
|
||||
----------
|
||||
|
||||
@@ -587,8 +587,6 @@ exit
|
||||
|
||||
NOW, LET'S START!
|
||||
|
||||
----------
|
||||
|
||||
Fix typos in bad.txt. Do not ask me for confirmation at any point.
|
||||
|
||||
----------
|
||||
|
||||
@@ -587,8 +587,6 @@ exit
|
||||
|
||||
NOW, LET'S START!
|
||||
|
||||
----------
|
||||
|
||||
Fix typos in bad.txt. Do not ask me for confirmation at any point.
|
||||
|
||||
----------
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
----------
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
----------
|
||||
|
||||
@@ -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.
|
||||
|
||||
----------
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
----------
|
||||
|
||||
@@ -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.
|
||||
|
||||
----------
|
||||
|
||||
@@ -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.
|
||||
|
||||
----------
|
||||
|
||||
Reference in New Issue
Block a user