fix up serialization and deserialization of events (#1850)

* fix up serialization and deserialization of events

* fix tests

* remove prints

* fix test

* regenerate tests

* add try blocks
This commit is contained in:
Robert Brennan
2024-05-16 21:09:15 -04:00
committed by GitHub
parent 5b6f622dad
commit 110b878dd9
19 changed files with 232 additions and 251 deletions

View File

@@ -1,7 +1,3 @@
----------
SYSTEM INFO:
You am an autonomous coding agent, here to provide solutions for coding issues.
You have been designed to assist you with a wide range of programming tasks, from code editing and debugging to testing and deployment.
@@ -52,16 +48,12 @@ None
The following commands require an open file to be used: edit, scroll_up, scroll_down, goto
To modify the current file use 'edit'. To move through the current file use 'goto' or 'scroll_up'/'scroll_down'
when using write and edit do not surround the code with any "" just write the code.
----------
These are your past 4 actions:
when using write and edit do not surround the code with any "" just write the code.These are your past 4 actions:
===== Previous Actions =====
Memory 0:
Previous Action:
source: EventSource.USER
source: user
action: message
args:
wait_for_response: False
@@ -72,11 +64,7 @@ content:
extras:
======= End Actions =======
Use these memories to provide additional context to the problem you are solving.
Remember that you have already completed these steps so you do not need to perform them again.
----------
RESPONSE FORMAT:
Remember that you have already completed these steps so you do not need to perform them again.RESPONSE FORMAT:
This is the format of the response you will make in order to solve the current issue.
You will be given multiple iterations to complete this task so break it into steps and solve them one by one.

View File

@@ -1,7 +1,3 @@
----------
SYSTEM INFO:
You am an autonomous coding agent, here to provide solutions for coding issues.
You have been designed to assist you with a wide range of programming tasks, from code editing and debugging to testing and deployment.
@@ -52,16 +48,12 @@ None
The following commands require an open file to be used: edit, scroll_up, scroll_down, goto
To modify the current file use 'edit'. To move through the current file use 'goto' or 'scroll_up'/'scroll_down'
when using write and edit do not surround the code with any "" just write the code.
----------
These are your past 4 actions:
when using write and edit do not surround the code with any "" just write the code.These are your past 4 actions:
===== Previous Actions =====
Memory 0:
Previous Action:
source: EventSource.USER
source: user
action: message
args:
wait_for_response: False
@@ -73,7 +65,7 @@ extras:
Memory 1:
Previous Action:
source: EventSource.AGENT
source: agent
action: write
args:
path: hello.sh
@@ -85,18 +77,14 @@ args:
Action:
Output from Action:
source: EventSource.AGENT
source: agent
observation: write
content:
extras:
path: hello.sh
======= End Actions =======
Use these memories to provide additional context to the problem you are solving.
Remember that you have already completed these steps so you do not need to perform them again.
----------
RESPONSE FORMAT:
Remember that you have already completed these steps so you do not need to perform them again.RESPONSE FORMAT:
This is the format of the response you will make in order to solve the current issue.
You will be given multiple iterations to complete this task so break it into steps and solve them one by one.

View File

@@ -1,7 +1,3 @@
----------
SYSTEM INFO:
You am an autonomous coding agent, here to provide solutions for coding issues.
You have been designed to assist you with a wide range of programming tasks, from code editing and debugging to testing and deployment.
@@ -52,16 +48,12 @@ None
The following commands require an open file to be used: edit, scroll_up, scroll_down, goto
To modify the current file use 'edit'. To move through the current file use 'goto' or 'scroll_up'/'scroll_down'
when using write and edit do not surround the code with any "" just write the code.
----------
These are your past 4 actions:
when using write and edit do not surround the code with any "" just write the code.These are your past 4 actions:
===== Previous Actions =====
Memory 0:
Previous Action:
source: EventSource.USER
source: user
action: message
args:
wait_for_response: False
@@ -73,7 +65,7 @@ extras:
Memory 1:
Previous Action:
source: EventSource.AGENT
source: agent
action: write
args:
path: hello.sh
@@ -85,7 +77,7 @@ args:
Action:
Output from Action:
source: EventSource.AGENT
source: agent
observation: write
content:
extras:
@@ -93,7 +85,7 @@ extras:
Memory 2:
Previous Action:
source: EventSource.AGENT
source: agent
action: write
args:
path: hello.sh
@@ -105,18 +97,14 @@ args:
Action:
Output from Action:
source: EventSource.AGENT
source: agent
observation: write
content:
extras:
path: hello.sh
======= End Actions =======
Use these memories to provide additional context to the problem you are solving.
Remember that you have already completed these steps so you do not need to perform them again.
----------
RESPONSE FORMAT:
Remember that you have already completed these steps so you do not need to perform them again.RESPONSE FORMAT:
This is the format of the response you will make in order to solve the current issue.
You will be given multiple iterations to complete this task so break it into steps and solve them one by one.

View File

@@ -1,7 +1,3 @@
----------
SYSTEM INFO:
You am an autonomous coding agent, here to provide solutions for coding issues.
You have been designed to assist you with a wide range of programming tasks, from code editing and debugging to testing and deployment.
@@ -52,16 +48,12 @@ None
The following commands require an open file to be used: edit, scroll_up, scroll_down, goto
To modify the current file use 'edit'. To move through the current file use 'goto' or 'scroll_up'/'scroll_down'
when using write and edit do not surround the code with any "" just write the code.
----------
These are your past 4 actions:
when using write and edit do not surround the code with any "" just write the code.These are your past 4 actions:
===== Previous Actions =====
Memory 0:
Previous Action:
source: EventSource.USER
source: user
action: message
args:
wait_for_response: False
@@ -73,7 +65,7 @@ extras:
Memory 1:
Previous Action:
source: EventSource.AGENT
source: agent
action: write
args:
path: hello.sh
@@ -85,7 +77,7 @@ args:
Action:
Output from Action:
source: EventSource.AGENT
source: agent
observation: write
content:
extras:
@@ -93,7 +85,7 @@ extras:
Memory 2:
Previous Action:
source: EventSource.AGENT
source: agent
action: write
args:
path: hello.sh
@@ -105,7 +97,7 @@ args:
Action:
Output from Action:
source: EventSource.AGENT
source: agent
observation: write
content:
extras:
@@ -113,7 +105,7 @@ extras:
Memory 3:
Previous Action:
source: EventSource.AGENT
source: agent
action: write
args:
path: hello.sh
@@ -125,18 +117,14 @@ args:
Action:
Output from Action:
source: EventSource.AGENT
source: agent
observation: write
content:
extras:
path: hello.sh
======= End Actions =======
Use these memories to provide additional context to the problem you are solving.
Remember that you have already completed these steps so you do not need to perform them again.
----------
RESPONSE FORMAT:
Remember that you have already completed these steps so you do not need to perform them again.RESPONSE FORMAT:
This is the format of the response you will make in order to solve the current issue.
You will be given multiple iterations to complete this task so break it into steps and solve them one by one.

View File

@@ -1,7 +1,3 @@
----------
SYSTEM INFO:
You am an autonomous coding agent, here to provide solutions for coding issues.
You have been designed to assist you with a wide range of programming tasks, from code editing and debugging to testing and deployment.
@@ -52,16 +48,12 @@ None
The following commands require an open file to be used: edit, scroll_up, scroll_down, goto
To modify the current file use 'edit'. To move through the current file use 'goto' or 'scroll_up'/'scroll_down'
when using write and edit do not surround the code with any "" just write the code.
----------
These are your past 4 actions:
when using write and edit do not surround the code with any "" just write the code.These are your past 4 actions:
===== Previous Actions =====
Memory 0:
Previous Action:
source: EventSource.AGENT
source: agent
action: write
args:
path: hello.sh
@@ -73,7 +65,7 @@ args:
Action:
Output from Action:
source: EventSource.AGENT
source: agent
observation: write
content:
extras:
@@ -81,7 +73,7 @@ extras:
Memory 1:
Previous Action:
source: EventSource.AGENT
source: agent
action: write
args:
path: hello.sh
@@ -93,7 +85,7 @@ args:
Action:
Output from Action:
source: EventSource.AGENT
source: agent
observation: write
content:
extras:
@@ -101,7 +93,7 @@ extras:
Memory 2:
Previous Action:
source: EventSource.AGENT
source: agent
action: write
args:
path: hello.sh
@@ -113,7 +105,7 @@ args:
Action:
Output from Action:
source: EventSource.AGENT
source: agent
observation: write
content:
extras:
@@ -121,7 +113,7 @@ extras:
Memory 3:
Previous Action:
source: EventSource.AGENT
source: agent
action: write
args:
path: hello.sh
@@ -133,18 +125,14 @@ args:
Action:
Output from Action:
source: EventSource.AGENT
source: agent
observation: write
content:
extras:
path: hello.sh
======= End Actions =======
Use these memories to provide additional context to the problem you are solving.
Remember that you have already completed these steps so you do not need to perform them again.
----------
RESPONSE FORMAT:
Remember that you have already completed these steps so you do not need to perform them again.RESPONSE FORMAT:
This is the format of the response you will make in order to solve the current issue.
You will be given multiple iterations to complete this task so break it into steps and solve them one by one.

View File

@@ -1,7 +1,3 @@
----------
SYSTEM INFO:
You am an autonomous coding agent, here to provide solutions for coding issues.
You have been designed to assist you with a wide range of programming tasks, from code editing and debugging to testing and deployment.
@@ -52,16 +48,12 @@ None
The following commands require an open file to be used: edit, scroll_up, scroll_down, goto
To modify the current file use 'edit'. To move through the current file use 'goto' or 'scroll_up'/'scroll_down'
when using write and edit do not surround the code with any "" just write the code.
----------
These are your past 4 actions:
when using write and edit do not surround the code with any "" just write the code.These are your past 4 actions:
===== Previous Actions =====
Memory 0:
Previous Action:
source: EventSource.AGENT
source: agent
action: write
args:
path: hello.sh
@@ -73,7 +65,7 @@ args:
Action:
Output from Action:
source: EventSource.AGENT
source: agent
observation: write
content:
extras:
@@ -81,7 +73,7 @@ extras:
Memory 1:
Previous Action:
source: EventSource.AGENT
source: agent
action: write
args:
path: hello.sh
@@ -93,7 +85,7 @@ args:
Action:
Output from Action:
source: EventSource.AGENT
source: agent
observation: write
content:
extras:
@@ -101,7 +93,7 @@ extras:
Memory 2:
Previous Action:
source: EventSource.AGENT
source: agent
action: write
args:
path: hello.sh
@@ -113,7 +105,7 @@ args:
Action:
Output from Action:
source: EventSource.AGENT
source: agent
observation: write
content:
extras:
@@ -121,7 +113,7 @@ extras:
Memory 3:
Previous Action:
source: EventSource.AGENT
source: agent
action: write
args:
path: hello.sh
@@ -133,18 +125,14 @@ args:
Action:
Output from Action:
source: EventSource.AGENT
source: agent
observation: write
content:
extras:
path: hello.sh
======= End Actions =======
Use these memories to provide additional context to the problem you are solving.
Remember that you have already completed these steps so you do not need to perform them again.
----------
RESPONSE FORMAT:
Remember that you have already completed these steps so you do not need to perform them again.RESPONSE FORMAT:
This is the format of the response you will make in order to solve the current issue.
You will be given multiple iterations to complete this task so break it into steps and solve them one by one.

View File

@@ -1,7 +1,3 @@
----------
SYSTEM INFO:
You am an autonomous coding agent, here to provide solutions for coding issues.
You have been designed to assist you with a wide range of programming tasks, from code editing and debugging to testing and deployment.
@@ -52,16 +48,12 @@ None
The following commands require an open file to be used: edit, scroll_up, scroll_down, goto
To modify the current file use 'edit'. To move through the current file use 'goto' or 'scroll_up'/'scroll_down'
when using write and edit do not surround the code with any "" just write the code.
----------
These are your past 4 actions:
when using write and edit do not surround the code with any "" just write the code.These are your past 4 actions:
===== Previous Actions =====
Memory 0:
Previous Action:
source: EventSource.AGENT
source: agent
action: write
args:
path: hello.sh
@@ -73,7 +65,7 @@ args:
Action:
Output from Action:
source: EventSource.AGENT
source: agent
observation: write
content:
extras:
@@ -81,7 +73,7 @@ extras:
Memory 1:
Previous Action:
source: EventSource.AGENT
source: agent
action: write
args:
path: hello.sh
@@ -93,7 +85,7 @@ args:
Action:
Output from Action:
source: EventSource.AGENT
source: agent
observation: write
content:
extras:
@@ -101,7 +93,7 @@ extras:
Memory 2:
Previous Action:
source: EventSource.AGENT
source: agent
action: write
args:
path: hello.sh
@@ -113,7 +105,7 @@ args:
Action:
Output from Action:
source: EventSource.AGENT
source: agent
observation: write
content:
extras:
@@ -121,7 +113,7 @@ extras:
Memory 3:
Previous Action:
source: EventSource.AGENT
source: agent
action: run
args:
command: chmod +x hello.sh
@@ -129,7 +121,7 @@ args:
thought:
Output from Action:
source: EventSource.AGENT
source: agent
observation: run
content:
extras:
@@ -138,11 +130,7 @@ extras:
exit_code: 0
======= End Actions =======
Use these memories to provide additional context to the problem you are solving.
Remember that you have already completed these steps so you do not need to perform them again.
----------
RESPONSE FORMAT:
Remember that you have already completed these steps so you do not need to perform them again.RESPONSE FORMAT:
This is the format of the response you will make in order to solve the current issue.
You will be given multiple iterations to complete this task so break it into steps and solve them one by one.

View File

@@ -1,7 +1,3 @@
----------
SYSTEM INFO:
You am an autonomous coding agent, here to provide solutions for coding issues.
You have been designed to assist you with a wide range of programming tasks, from code editing and debugging to testing and deployment.
@@ -52,16 +48,12 @@ None
The following commands require an open file to be used: edit, scroll_up, scroll_down, goto
To modify the current file use 'edit'. To move through the current file use 'goto' or 'scroll_up'/'scroll_down'
when using write and edit do not surround the code with any "" just write the code.
----------
These are your past 4 actions:
when using write and edit do not surround the code with any "" just write the code.These are your past 4 actions:
===== Previous Actions =====
Memory 0:
Previous Action:
source: EventSource.AGENT
source: agent
action: write
args:
path: hello.sh
@@ -73,7 +65,7 @@ args:
Action:
Output from Action:
source: EventSource.AGENT
source: agent
observation: write
content:
extras:
@@ -81,7 +73,7 @@ extras:
Memory 1:
Previous Action:
source: EventSource.AGENT
source: agent
action: write
args:
path: hello.sh
@@ -93,7 +85,7 @@ args:
Action:
Output from Action:
source: EventSource.AGENT
source: agent
observation: write
content:
extras:
@@ -101,7 +93,7 @@ extras:
Memory 2:
Previous Action:
source: EventSource.AGENT
source: agent
action: run
args:
command: chmod +x hello.sh
@@ -109,7 +101,7 @@ args:
thought:
Output from Action:
source: EventSource.AGENT
source: agent
observation: run
content:
extras:
@@ -119,7 +111,7 @@ extras:
Memory 3:
Previous Action:
source: EventSource.AGENT
source: agent
action: run
args:
command: bash hello.sh
@@ -127,7 +119,7 @@ args:
thought:
Output from Action:
source: EventSource.AGENT
source: agent
observation: run
content: hello
extras:
@@ -136,11 +128,7 @@ extras:
exit_code: 0
======= End Actions =======
Use these memories to provide additional context to the problem you are solving.
Remember that you have already completed these steps so you do not need to perform them again.
----------
RESPONSE FORMAT:
Remember that you have already completed these steps so you do not need to perform them again.RESPONSE FORMAT:
This is the format of the response you will make in order to solve the current issue.
You will be given multiple iterations to complete this task so break it into steps and solve them one by one.

View File

@@ -1,7 +1,3 @@
----------
SYSTEM INFO:
You am an autonomous coding agent, here to provide solutions for coding issues.
You have been designed to assist you with a wide range of programming tasks, from code editing and debugging to testing and deployment.
@@ -52,16 +48,12 @@ None
The following commands require an open file to be used: edit, scroll_up, scroll_down, goto
To modify the current file use 'edit'. To move through the current file use 'goto' or 'scroll_up'/'scroll_down'
when using write and edit do not surround the code with any "" just write the code.
----------
These are your past 4 actions:
when using write and edit do not surround the code with any "" just write the code.These are your past 4 actions:
===== Previous Actions =====
Memory 0:
Previous Action:
source: EventSource.AGENT
source: agent
action: write
args:
path: hello.sh
@@ -73,7 +65,7 @@ args:
Action:
Output from Action:
source: EventSource.AGENT
source: agent
observation: write
content:
extras:
@@ -81,7 +73,7 @@ extras:
Memory 1:
Previous Action:
source: EventSource.AGENT
source: agent
action: run
args:
command: chmod +x hello.sh
@@ -89,7 +81,7 @@ args:
thought:
Output from Action:
source: EventSource.AGENT
source: agent
observation: run
content:
extras:
@@ -99,7 +91,7 @@ extras:
Memory 2:
Previous Action:
source: EventSource.AGENT
source: agent
action: run
args:
command: bash hello.sh
@@ -107,7 +99,7 @@ args:
thought:
Output from Action:
source: EventSource.AGENT
source: agent
observation: run
content: hello
extras:
@@ -117,7 +109,7 @@ extras:
Memory 3:
Previous Action:
source: EventSource.AGENT
source: agent
action: run
args:
command: bash hello.sh
@@ -125,7 +117,7 @@ args:
thought:
Output from Action:
source: EventSource.AGENT
source: agent
observation: run
content: hello
extras:
@@ -134,11 +126,7 @@ extras:
exit_code: 0
======= End Actions =======
Use these memories to provide additional context to the problem you are solving.
Remember that you have already completed these steps so you do not need to perform them again.
----------
RESPONSE FORMAT:
Remember that you have already completed these steps so you do not need to perform them again.RESPONSE FORMAT:
This is the format of the response you will make in order to solve the current issue.
You will be given multiple iterations to complete this task so break it into steps and solve them one by one.

View File

@@ -14,14 +14,14 @@ from opendevin.events.action import (
ModifyTaskAction,
)
from opendevin.events.serialization import (
action_from_dict,
event_from_dict,
event_to_dict,
event_to_memory,
)
def serialization_deserialization(original_action_dict, cls):
action_instance = action_from_dict(original_action_dict)
action_instance = event_from_dict(original_action_dict)
assert isinstance(
action_instance, Action
), 'The action instance should be an instance of Action.'
@@ -34,11 +34,28 @@ def serialization_deserialization(original_action_dict, cls):
assert (
serialized_action_dict == original_action_dict
), 'The serialized action should match the original action dict.'
original_memory_dict = original_action_dict.copy()
original_memory_dict.pop('id', None)
original_memory_dict.pop('timestamp', None)
assert (
serialized_action_memory == original_action_dict
serialized_action_memory == original_memory_dict
), 'The serialized action in memory should match the original action dict.'
def test_event_props_serialization_deserialization():
original_action_dict = {
'id': 42,
'source': 'agent',
'timestamp': '2021-08-01T12:00:00',
'action': 'message',
'args': {
'content': 'This is a test.',
'wait_for_response': False,
},
}
serialization_deserialization(original_action_dict, MessageAction)
def test_message_action_serialization_deserialization():
original_action_dict = {
'action': 'message',

View File

@@ -7,18 +7,22 @@ from opendevin.events.observation import NullObservation
from opendevin.events.stream import EventSource, EventStream
def collect_events(stream):
return [event for event in stream.get_events()]
@pytest.mark.asyncio
async def test_basic_flow():
stream = EventStream('abc')
await stream.add_event(NullAction(), EventSource.AGENT)
assert len(stream._events) == 1
assert len(collect_events(stream)) == 1
@pytest.mark.asyncio
async def test_stream_storage():
stream = EventStream('def')
await stream.add_event(NullObservation(''), EventSource.AGENT)
assert len(stream._events) == 1
assert len(collect_events(stream)) == 1
content = stream._file_store.read('sessions/def/events/0.json')
assert content is not None
data = json.loads(content)
@@ -39,16 +43,13 @@ async def test_rehydration():
stream1 = EventStream('es1')
await stream1.add_event(NullObservation('obs1'), EventSource.AGENT)
await stream1.add_event(NullObservation('obs2'), EventSource.AGENT)
assert len(stream1._events) == 2
assert len(collect_events(stream1)) == 2
stream2 = EventStream('es2')
assert len(stream2._events) == 0
await stream2._rehydrate()
assert len(stream2._events) == 0
assert len(collect_events(stream2)) == 0
stream1rehydrated = EventStream('es1')
assert len(stream1rehydrated._events) == 0
await stream1rehydrated._rehydrate()
assert len(stream1rehydrated._events) == 2
assert stream1rehydrated._events[0].content == 'obs1'
assert stream1rehydrated._events[1].content == 'obs2'
events = collect_events(stream1rehydrated)
assert len(events) == 2
assert events[0].content == 'obs1'
assert events[1].content == 'obs2'

View File

@@ -9,6 +9,7 @@ from opendevin.controller.agent import Agent
from opendevin.controller.state.state import State
from opendevin.events.action import MessageAction
from opendevin.events.observation import NullObservation
from opendevin.events.serialization import EventSource
def test_all_agents_are_loaded():
@@ -37,7 +38,7 @@ def test_coder_agent_with_summary():
task = 'This is a dummy task'
history = [(MessageAction(content=task), NullObservation(''))]
history[0][0]._source = 'user'
history[0][0]._source = EventSource.USER
summary = 'This is a dummy summary about this repo'
state = State(history=history, inputs={'summary': summary})
coder_agent.step(state)
@@ -64,7 +65,7 @@ def test_coder_agent_without_summary():
task = 'This is a dummy task'
history = [(MessageAction(content=task), NullObservation(''))]
history[0][0]._source = 'user'
history[0][0]._source = EventSource.USER
state = State(history=history)
coder_agent.step(state)

View File

@@ -3,35 +3,52 @@ from opendevin.events.observation import (
Observation,
)
from opendevin.events.serialization import (
event_from_dict,
event_to_dict,
event_to_memory,
observation_from_dict,
)
def test_observation_serialization_deserialization():
original_observation_dict = {
'observation': 'run',
'extras': {'exit_code': 0, 'command': 'ls -l', 'command_id': 3},
'message': 'Command `ls -l` executed with exit code 0.',
'content': 'foo.txt',
}
observation_instance = observation_from_dict(original_observation_dict)
def serialization_deserialization(original_observation_dict, cls):
observation_instance = event_from_dict(original_observation_dict)
assert isinstance(
observation_instance, Observation
), 'The observation instance should be an instance of Action.'
assert isinstance(
observation_instance, CmdOutputObservation
observation_instance, cls
), 'The observation instance should be an instance of CmdOutputObservation.'
serialized_observation_dict = event_to_dict(observation_instance)
serialized_observation_memory = event_to_memory(observation_instance)
assert (
serialized_observation_dict == original_observation_dict
), 'The serialized observation should match the original observation dict.'
original_observation_dict.pop('message')
original_observation_dict.pop('message', None)
original_observation_dict.pop('id', None)
original_observation_dict.pop('timestamp', None)
assert (
serialized_observation_memory == original_observation_dict
), 'The serialized observation in memory should match the original observation dict.'
), 'The serialized observation memory should match the original observation dict.'
# Additional tests for various observation subclasses can be included here
def test_observation_event_props_serialization_deserialization():
original_observation_dict = {
'id': 42,
'source': 'agent',
'timestamp': '2021-08-01T12:00:00',
'observation': 'run',
'message': 'Command `ls -l` executed with exit code 0.',
'extras': {'exit_code': 0, 'command': 'ls -l', 'command_id': 3},
'content': 'foo.txt',
}
serialization_deserialization(original_observation_dict, CmdOutputObservation)
def test_command_output_observation_serialization_deserialization():
original_observation_dict = {
'observation': 'run',
'extras': {'exit_code': 0, 'command': 'ls -l', 'command_id': 3},
'message': 'Command `ls -l` executed with exit code 0.',
'content': 'foo.txt',
}
serialization_deserialization(original_observation_dict, CmdOutputObservation)