[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server working with agent library #97

Merged
merged 17 commits into from
Mar 24, 2024
Merged

Server working with agent library #97

merged 17 commits into from
Mar 24, 2024

Conversation

rbren
Copy link
Collaborator
@rbren rbren commented Mar 22, 2024

This PR modifies the websocket server so that it uses the main Agent API to start an agent.

It removes the docker container mgmt, which is now controlled by the DockerInteractive sandbox.

Sample output. The first line is the only message sent to the server, everything else is a response

❯ websocat ws://127.0.0.1:3000/ws
{"action": "start", {"args": {"task": "write a bash script that prints hello"}}
{"message":"Starting new agent..."}
{"action":"run","message":"Running command: ls","args":{"command":"ls"}}
{"action":"output","message":"Got output.","args":{"output":"LICENSE\nOpenDevinLogo.jpg\nREADME.md\nagenthub\nenv_name\nevaluation\nfrontend\nhello.sh\nopendevin\nrequirements.txt\nserver\nworkspace\n"}}
{"action":"read","message":"Reading file: hello.sh","args":{"path":"hello.sh"}}
{"action":"output","message":"Got output.","args":{"output":"#!/bin/bash\necho \"hello\""}}
{"action":"run","message":"Running command: bash hello.sh","args":{"command":"bash hello.sh"}}
{"action":"output","message":"Got output.","args":{"output":"hello\n"}}
{"action":"think","message":"I've successfully executed the bash script hello.sh which printed 'hello'. My primary task is complete. It's time to finalize my work.","args":{"thought":"I've successfully executed the bash script hello.sh which printed 'hello'. My primary task is complete. It's time to finalize my work."}}
{"action":"finish","message":"Finished!","args":{}}

@kvchitrapu
Copy link
Contributor
kvchitrapu commented Mar 22, 2024

The task hangs in git add hello.sh step. Add error checks around command execution and return exit on errors.

STEP 0
run {'command': 'ls'}
---
output {'output': 'LICENSE\nOpenDevinLogo.jpg\nREADME.md\nagenthub\nevaluation\nfrontend\nopendevin\nrequirements.txt\n'}
==============
STEP 1
think {'thought': "I should create a new bash script file. Let's call it hello.sh."}
---
==============
STEP 2
write {'path': 'hello.sh', 'contents': '#!/bin/bash\necho "hello"'}
---
output {'output': ''}
==============
STEP 3
run {'command': 'bash hello.sh'}
---
output {'output': 'hello\n'}
==============
STEP 4
think {'thought': "I've successfully created and executed the bash script that prints 'hello'. My next step should be to ensure the script is properly saved and can be executed by others. I should consider making the script executable by others and perhaps add a comment to explain what it does."}
---
==============
STEP 5
write {'path': 'hello.sh', 'contents': '#!/bin/bash\n# This script prints \'hello\'\necho "hello"'}
---
output {'output': ''}
==============
STEP 6
run {'command': 'chmod +x hello.sh'}
---
output {'output': ''}
==============
STEP 7
think {'thought': 'Now that the script is executable and has a helpful comment, I should ensure that my work is preserved for future reference or use. A good way to do this would be to commit the changes using git.'}
---
==============
STEP 8
run {'command': 'git add hello.sh'}

@rbren
Copy link
Collaborator Author
rbren commented Mar 22, 2024

@kvchitrapu lmk if you're still able to repro this--I think I've fixed it.

@kvchitrapu
Copy link
Contributor
kvchitrapu commented Mar 23, 2024

@kvchitrapu lmk if you're still able to repro this--I think I've fixed it.

Happy path worked fine.

However, any syntax error in action json drops connection in session.py:56. How about sending back an error to the client indicating bad json? Here is a bad json message with extra '}' at the end to illustrate the problem on the client side.

Client side

$ websocat ws://127.0.0.1:3000/ws
{"message":"Control loop started"}
{"action":"start","args":{"task":"write a bash script that prints hello"}}}
<hangs>

Server side

$ uvicorn opendevin.server.listen:app --reload --port 3000
...
File "/var/OpenDevin-rbren/OpenDevin/opendevin/server/listen.py", line 15, in websocket_endpoint
    await session.start_listening()
  File "/var/OpenDevin-rbren/OpenDevin/opendevin/server/session.py", line 39, in start_listening
    data = await self.websocket.receive_json()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/OpenDevin-rbren/OpenDevin/.venv/lib/python3.11/site-packages/starlette/websockets.py", line 145, in receive_json
    return json.loads(text)
           ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.7_2/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.7_2/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py", line 340, in decode
    raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 1 column 75 (char 74)
INFO:     connection closed

@rbren
Copy link
Collaborator Author
rbren commented Mar 23, 2024

Good catch! Fixed the JSON parsing issue

I just got it to hang again, so I'm digging in a little further.

@rbren
Copy link
Collaborator Author
rbren commented Mar 23, 2024

Figured out some of the hanging. It seems like await sometimes swallows errors--I had raise ValueError triggering, with no logs, which totally broke the control loop.

I've fixed it by adding try/except blocks into the controller, especially where it calls back to the agent or callbacks. But my guess is there's a better way.

@rbren rbren mentioned this pull request Mar 23, 2024
@kvchitrapu
Copy link
Contributor

Figured out some of the hanging. It seems like await sometimes swallows errors--I had raise ValueError triggering, with no logs, which totally broke the control loop.

I've fixed it by adding try/except blocks into the controller, especially where it calls back to the agent or callbacks. But my guess is there's a better way.

Nice work! Bad json input gave an error:

{"action": "start", "args": {"task": "write a bash script that prints hello"}}}
{"error":true,"message":"Invalid JSON"}

@kvchitrapu
Copy link
Contributor

LGTM

@kvchitrapu
Copy link
Contributor

For our next steps, it's important we address the following to enhance our project's stability and cleanliness:

  1. Cleanup methods to ensure a smooth termination of WebSocket connections, sessions, agents, and controllers when errors occur. This should also extend to handling the cleanup of Docker containers started by agents.
  2. A session manager to track sessions, which will aid in preventing resource leaks.
  3. Add linting tools, such as ruff integrated into GitHub Actions, to catch and eliminate unused imports.

@rbren, if that sounds good to you, I'll proceed to create an enhancement issue and follow up with a pull request.

@rbren
Copy link
Collaborator Author
rbren commented Mar 23, 2024

👍 totally agree!

re: cleanup, I think I'm doing some basic cleanup already, but it could probably be improved.

re: sessions, I think we can assume 1 session per server for MVP, but would be great to make sessions more robust

@rbren rbren requested a review from xingyaoww March 24, 2024 02:28
@rbren rbren requested a review from yimothysu March 24, 2024 02:28
Copy link
Collaborator
@yimothysu yimothysu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor
@xingyaoww xingyaoww left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@xingyaoww xingyaoww merged commit 4aa24eb into All-Hands-AI:main Mar 24, 2024
xcodebuild pushed a commit to xcodebuild/OpenDevin that referenced this pull request Mar 31, 2024
* server working with agent library

* update readme

* add messages to events

* factor out steps

* fix websocket messages

* allow user to run arbitrary actions

* allow user to run commands before a task is started

* fix main.py

* check JSON

* handle errors in controller better

* fix memory issue

* better error handling and task cancellation

* fix monologue len

* fix imports

* remove server from lint check

* fix lint issues

* fix lint errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants