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

feat: support controlling agent task state. #1094

Merged
merged 7 commits into from
Apr 18, 2024

Conversation

iFurySt
Copy link
Collaborator

@iFurySt iFurySt commented Apr 14, 2024

  • feat: add agent task state to agent status bar.

  • feat: add agent task control bar to FE.

#1049

@iFurySt
Copy link
Collaborator Author

iFurySt commented Apr 14, 2024

Screen.Recording.mov

ignore the error BE threw, i just started a 2b LLM to fastly demonstrate.

Copy link
Collaborator

@rbren rbren left a comment

Choose a reason for hiding this comment

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

This is awesome! Thanks for taking it on


if self._task_state == TaskState.FINISHED:
await self._stop_task(is_finished=True) # type: ignore[unreachable]
return
Copy link
Collaborator

Choose a reason for hiding this comment

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

should this be break so we hit the log statement below?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

actually, i don't what you mean 😅

Copy link
Collaborator

Choose a reason for hiding this comment

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

break means "exit the loop". return means "exit the function"

since you're returning here, we never reach the log statement that's below the loop

Comment on lines 185 to 186
self.state = None
self._cur_step = 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we call reset_task here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good idea, reuse code.


def close(self):
# self.stop_task()
Copy link
Collaborator

Choose a reason for hiding this comment

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

rm

Comment on lines 278 to 280
if self.controller is not None:
event_dict['task_state'] = self.controller.get_task_state().value
self.send(event_dict)
Copy link
Collaborator

Choose a reason for hiding this comment

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

instead of sending this constantly, should we send an event when state changes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

you are right. let me adjust it. btw, the asyncio.create_task to start the agent task will very likely block other threads. i think we should consider using multiprocessing to run the agent task in Python to realize the true async.

Copy link
Collaborator

Choose a reason for hiding this comment

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

agree!

* feat: add agent task state to agent status bar.

* feat: add agent task control bar to FE.
@iFurySt iFurySt force-pushed the feat-support-control-agent-task-state branch from 2290615 to 906ad0d Compare April 14, 2024 14:53
@iFurySt
Copy link
Collaborator Author

iFurySt commented Apr 14, 2024

have been updated. sorry for the force push, take care next time😅

@iFurySt
Copy link
Collaborator Author

iFurySt commented Apr 14, 2024

the changes mainly includes:

  • delete asyncio.Event(), i think it's unnecessary for now.
  • add TaskStateChangedAction to carry the changed task state which is sent to the client.

@rbren
Copy link
Collaborator

rbren commented Apr 15, 2024

sorry for the force push, take care next time

I force push to my branches all the time 😄 as long as you don't force push to main it's all good!

I use git push origin +branch-name to only force push a single branch.

@rbren
Copy link
Collaborator

rbren commented Apr 15, 2024

Tried this locally. Seems to work well!

Two things I think we can improve on:

  • "pause" waits for the current step to complete before giving feedback. If the step is taking a long time (e.g. step 0) then it feels kind of broken, because you don't get any feedback that it worked. In the future it'd be cool if we can just cancel the current step
  • "reset" and "stop" feel duplicative. I kind of like that "reset" totally clears everything--I wonder if that should be the "stop" behavior.

I'm good merging this as-is as it's already a big improvement. But the second bullet might be easy to address at least

@@ -133,15 +169,24 @@ async def create_controller(self, start_event: dict):
callbacks=[self.on_agent_event],
)
except Exception as e:
logger.exception(f'Error creating controller: {e}')
logger.exception(f"Error creating controller: {e}")
Copy link
Collaborator

@li-boxuan li-boxuan Apr 15, 2024

Choose a reason for hiding this comment

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

Could you please try running the following command locally?

poetry run pre-commit run --files opendevin/**/* agenthub/**/* --show-diff-on-failure --config ./dev_config/python/.pre-commit-config.yaml

I am surprised to see 1) your pre-commit hook doesn't fix this, and 2) CI doesn't fail.

FWIW I ran the above command on my end, and it would change this double quote to single quote.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

image

nothing happened.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Poetry (version 1.8.2)
pre-commit 3.7.0

Copy link
Collaborator

Choose a reason for hiding this comment

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

:(

Something's wrong with Fix double quoted strings hook

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

IMO, it doesn't always detect the f"" pattern, even in the GitHub workflow CI env it seems to only detect some cases but not all about this pattern 🤔

Copy link
Collaborator

@li-boxuan li-boxuan Apr 15, 2024

Choose a reason for hiding this comment

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

I am able to reproduce it using 3.12.2. With 3.11.x, this line will be fixed by the plugin. (That's sad, isn't it? We don't want to force everyone to use the same python version just because of a linting tool). That being said, I don't know why CI (which uses 3.11) would ignore this line.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

pre-commit/pre-commit-hooks#973

seems already to be fixed? i can take a look in my env later.

Copy link
Collaborator

Choose a reason for hiding this comment

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

seems already to be fixed?

Nope I tried, it didn't work (even after upgrading pre-commit-hooks to latest version that includes this fix)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i've read the source code of pre-commit-hooks, they just easy skip the fstring if python version is greater than 3.12~

image

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's the most confusing part because that code supposably only exists in their latest version, while we are using an old version.

@iFurySt
Copy link
Collaborator Author

iFurySt commented Apr 15, 2024

Tried this locally. Seems to work well!

Two things I think we can improve on:

  • "pause" waits for the current step to complete before giving feedback. If the step is taking a long time (e.g. step 0) then it feels kind of broken, because you don't get any feedback that it worked. In the future it'd be cool if we can just cancel the current step
  • "reset" and "stop" feel duplicative. I kind of like that "reset" totally clears everything--I wonder if that should be the "stop" behavior.

I'm good merging this as-is as it's already a big improvement. But the second bullet might be easy to address at least

do you mean removing the stop and just keeping the reset for now?

yep, pause may get the feedback for a long time. i originally added an icon loading overlapping with the pause button, but then i removed it. i'll try to handle it to get better ux.

@li-boxuan
Copy link
Collaborator

li-boxuan commented Apr 15, 2024

Tried locally and it worked well, this is awesome!

I think it would be great if we could disable some buttons in certain states, e.g. the pause button could be disabled when already in pause state. Could be a follow-up, though.

image

@iFurySt
Copy link
Collaborator Author

iFurySt commented Apr 15, 2024

image

i've deleted the stop action for now.

@iFurySt
Copy link
Collaborator Author

iFurySt commented Apr 15, 2024

Tried locally and it worked well, this is awesome!

I think it would be great if we could disable some buttons in certain states, e.g. the pause button could be disabled when already in pause state.

image

yep, i think we can add disabled and loading status to improve UX.

@rbren
Copy link
Collaborator

rbren commented Apr 17, 2024

@iFurySt we should probably combine play and pause into the same button (showing "play" if it's paused, and showing "pause" if it's running)

@iFurySt
Copy link
Collaborator Author

iFurySt commented Apr 18, 2024

@iFurySt we should probably combine play and pause into the same button (showing "play" if it's paused, and showing "pause" if it's running)

Okay, let me adjust it.

@iFurySt
Copy link
Collaborator Author

iFurySt commented Apr 18, 2024

Screen.Recording.mov

@rbren have a look. i've just combined pause and resume into one button. and made some improvements to the loading and disabled status for buttons.

frontend/src/services/socket.ts Outdated Show resolved Hide resolved
frontend/src/services/socket.ts Outdated Show resolved Hide resolved
frontend/src/services/socket.ts Outdated Show resolved Hide resolved
frontend/src/services/socket.ts Outdated Show resolved Hide resolved
@rbren rbren enabled auto-merge (squash) April 18, 2024 10:58
@rbren rbren merged commit 1356da8 into OpenDevin:main Apr 18, 2024
4 checks passed
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.

Add pause/resume functionality (and button) Add "stop/cancel" button
3 participants