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

Feature - Delete Agent fix #473 and #529 #558

Merged
merged 28 commits into from
Jul 17, 2023

Conversation

Arkajit-Datta
Copy link
Contributor

@Arkajit-Datta Arkajit-Datta commented Jun 29, 2023

Description

The Delete Agent feature is capable of soft-deleting an active agent. This makes sure to update the status flags in both AgentExecution and AgentExecutionPermission. The feature update comes with a new Column in the Agent Table named as is_delete: boolean, representing whether the agent is deleted or not.

Related Issues

close #473 and #529

Solution and Design

  1. A new Column named is_delete was added to the Agent Table, which is initialized to False by default whenever an agent is created.
  2. The routes in the Agent Controller are updated with the is_delete flag check, Hence not returning the deleted agents.
  3. New route - /agents/delete/ is added which provides the interface to delete the agent.
  4. Whenever the agent is deleted, the is_deleted param is set to True, AgentExecution status is set to "Terminated" and the AgentExecutionePermission status is set to "Rejected".
  5. Several checks with the is_deleted flag are added in various Controllers.
  6. GUI is updated with a delete agent option in the agent workspace. This functionality removes the agent workspace/tab. Also, refreshes the agent list under the project.

Test Plan

Backend (using PostMan)

  • Update the new database format in the superagi-backend docker. Steps:
    - alembic upgrade head
    - alembic revision --autogenerate -m "Some descriptive message"
    - alembic upgrade head

  • Create an agent from the front-end

  • Note the agent-id (this will be used to delete the agent later)

  • Delete the agent using the /agents/delete endpoint.

  • Reload the SuperAGI home screen.

Frontend

  • Open the frontend on localhost:3000
  • Create an agent and run it.
  • Navigate to the "3 dots" near the run button.
  • Click on the Delete Agent option and confirm the deletion.
  • This should essentially delete the agent and the agent workspace/tab would be removed.

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist

  • My pull request is atomic and focuses on a single change. - Done
  • I have read the contributing guide and my code conforms to the guidelines. - Done
  • I have documented my changes clearly and comprehensively. - Done
  • I have added the required tests. - Done

@Fluder-Paradyne
Copy link
Collaborator

migration for adding is_deleted to agent is missing

@Arkajit-Datta
Copy link
Contributor Author

Hey @Fluder-Paradyne do you want me to add that . py file which got created after alembic migration?

@Fluder-Paradyne
Copy link
Collaborator

Yes,
If it has anything to do with dropping indexes remove them, I am not sure why it is dropping indexes every migration

@Arkajit-Datta
Copy link
Contributor Author

Hey @Fluder-Paradyne I have removed the drop index and create index commands from the migration file. Please have a look thanx!

@Arkajit-Datta
Copy link
Contributor Author

sure @TransformerOptimus will incorporate these

@Arkajit-Datta
Copy link
Contributor Author

Hi @TransformerOptimus, I've incorporated the review changes, please review the changes. Lemme know if any other changes are required. Thanking you!

@neelayan7 neelayan7 mentioned this pull request Jul 4, 2023
@Arkajit-Datta Arkajit-Datta reopened this Jul 6, 2023
@Arkajit-Datta Arkajit-Datta changed the base branch from main to dev July 7, 2023 06:41
if not project:
if project := db.session.query(Project).get(agent.project_id):
db_agent.project_id = project.id
else:
Copy link
Collaborator

Choose a reason for hiding this comment

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

why is this changed, any specific reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

just refactored it, reduces lines of code. thought will make it more pythonic

@@ -438,14 +442,14 @@ def get_agent_configuration(agent_id: int,
dict: Agent configuration including its details.

Raises:
HTTPException (status_code=404): If the agent is not found.
HTTPException (status_code=404): If the agent is not found or deleted.
"""

# Define the agent_config keys to fetch
keys_to_fetch = AgentTemplate.main_keys()
agent = db.session.query(Agent).filter(agent_id == Agent.id).first()

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you update in the query itself rather than doing after fetching from DB?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure we can do this

db.session.commit()

return {"success": True}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we just handle by HTTP status code we are trying to avoid success/failure messages

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure will incorporate this

@TransformerOptimus TransformerOptimus merged commit 9741d44 into TransformerOptimus:dev Jul 17, 2023
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.

Delete Agent
4 participants