Skip to content

feat(autogpt_classic): Implement Flask web interface and enhance file operations #9725

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

Closed

Conversation

heeresbach
Copy link

  • Add autogpt/web_interface.py: Implement Flask web interface with routes for creating, listing, and deleting agents, and saving and retrieving information locally.
  • Modify autogpt/commands/file_operations.py: Update write_to_file and read_file functions to handle JSON and CSV formats.
  • Update autogpt/agent/agent_manager.py: Add methods for saving and retrieving agent information locally, and for listing and deleting agents.
  • Change autogpt/cli.py: Add command-line option to start the Flask web interface.

Changes 🏗️

Checklist 📋

For code changes:

  • I have clearly listed my changes in the PR description
  • I have made a test plan
  • I have tested my changes according to the test plan:
    • ...
Example test plan
  • Create from scratch and execute an agent with at least 3 blocks
  • Import an agent from file upload, and confirm it executes correctly
  • Upload agent to marketplace
  • Import an agent from marketplace and confirm it executes correctly
  • Edit an agent from monitor, and confirm it executes correctly

For configuration changes:

  • .env.example is updated or already compatible with my changes
  • docker-compose.yml is updated or already compatible with my changes
  • I have included a list of my configuration changes in the PR description (under Changes)
Examples of configuration changes
  • Changing ports
  • Adding new services that need to communicate with each other
  • Secrets or environment variable changes
  • New or infrastructure changes such as databases

* **Add `autogpt/web_interface.py`**: Implement Flask web interface with routes for creating, listing, and deleting agents, and saving and retrieving information locally.
* **Modify `autogpt/commands/file_operations.py`**: Update `write_to_file` and `read_file` functions to handle JSON and CSV formats.
* **Update `autogpt/agent/agent_manager.py`**: Add methods for saving and retrieving agent information locally, and for listing and deleting agents.
* **Change `autogpt/cli.py`**: Add command-line option to start the Flask web interface.
@heeresbach heeresbach requested a review from a team as a code owner March 31, 2025 02:07
@heeresbach heeresbach requested review from kcze and aarushik93 and removed request for a team March 31, 2025 02:07
@github-project-automation github-project-automation bot moved this to 🆕 Needs initial review in AutoGPT development kanban Mar 31, 2025
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Contributor

This PR targets the master branch but does not come from dev or a hotfix/* branch.

Automatically setting the base branch to dev.

@github-actions github-actions bot changed the base branch from master to dev March 31, 2025 02:07
@github-actions github-actions bot added the platform/backend AutoGPT Platform - Back end label Mar 31, 2025
Copy link
Contributor

This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.

@github-actions github-actions bot added the conflicts Automatically applied to PRs with merge conflicts label Mar 31, 2025
Copy link

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 No relevant tests
🔒 Security concerns

Sensitive information exposure:
The web interface (autogpt/web_interface.py) lacks authentication and authorization controls, allowing unauthenticated access to agent creation, listing, deletion, and file operations. This could expose sensitive information stored in agents or allow unauthorized file access on the server. Additionally, the file retrieval endpoint (/retrieve) allows reading any file that the application has access to, which could lead to information disclosure if an attacker can specify arbitrary filenames.

⚡ Recommended focus areas for review

Type Handling

The write_to_file function expects different types for different formats (dict for JSON, list of lists for CSV, string for txt) but this isn't documented in the function signature or docstring, which could lead to runtime errors.

if format == "json":
    with open(filename, "w", encoding="utf-8") as f:
        json.dump(text, f)
elif format == "csv":
    with open(filename, "w", encoding="utf-8", newline='') as f:
        writer = csv.writer(f)
        writer.writerows(text)
else:
    with open(filename, "w", encoding="utf-8") as f:
        f.write(text)
Missing Authentication

The Flask web interface doesn't implement any authentication mechanism, allowing anyone to create, list, or delete agents and access files on the system.

from flask import Flask, request, jsonify
from autogpt.agent.agent_manager import AgentManager
from autogpt.commands.file_operations import write_to_file, read_file

app = Flask(__name__)
agent_manager = AgentManager()

@app.route('/agents', methods=['POST'])
def create_agent():
    data = request.json
    task = data.get('task')
    prompt = data.get('prompt')
    model = data.get('model', 'gpt-3.5-turbo')
    key, response = agent_manager.create_agent(task, prompt, model)
    return jsonify({'key': key, 'response': response})

@app.route('/agents', methods=['GET'])
def list_agents():
    agents = agent_manager.list_agents()
    return jsonify(agents)

@app.route('/agents/<int:key>', methods=['DELETE'])
def delete_agent(key):
    success = agent_manager.delete_agent(key)
    return jsonify({'success': success})

@app.route('/save', methods=['POST'])
def save_information():
    data = request.json
    filename = data.get('filename')
    content = data.get('content')
    response = write_to_file(filename, content)
    return jsonify({'response': response})

@app.route('/retrieve', methods=['GET'])
def retrieve_information():
    filename = request.args.get('filename')
    content = read_file(filename)
    return jsonify({'content': content})

if __name__ == '__main__':
    app.run(debug=True)
Error Handling

The retrieve_agent_information method catches all exceptions generically and returns them as part of the response, which might expose sensitive information or implementation details.

try:
    content = read_file(filename)
    return content
except Exception as e:
    return {"Error": str(e)}

Copy link

deepsource-io bot commented Mar 31, 2025

Here's the code health analysis summary for commits 1f2af18..40fa48e. View details on DeepSource ↗.

Analysis Summary

AnalyzerStatusSummaryLink
DeepSource JavaScript LogoJavaScript✅ Success
❗ 1 occurence introduced
View Check ↗
DeepSource Python LogoPython✅ SuccessView Check ↗

💡 If you’re a repository administrator, you can configure the quality gates from the settings.

Copy link

netlify bot commented Mar 31, 2025

Deploy Preview for auto-gpt-docs failed.

Name Link
🔨 Latest commit 40fa48e
🔍 Latest deploy log https://app.netlify.com/sites/auto-gpt-docs/deploys/67e9f8e8c49386000851e6ac

@ntindle
Copy link
Member

ntindle commented Apr 3, 2025

Thanks for the changes! You've got a couple conflicts and a CLA that needs signed so it can't go in today's release. Ping me when these are resolved and I'll take a look :)

@@ -128,12 +130,13 @@ def ingest_file(


@command("write_to_file", "Write to file", '"filename": "<filename>", "text": "<text>"')
def write_to_file(filename: str, text: str) -> str:
def write_to_file(filename: str, text: str, format: str = "txt") -> str:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def write_to_file(filename: str, text: str, format: str = "txt") -> str:
def write_to_file(filename: str, text: str, format: Literal["txt", "json", "csv"] = "txt") -> str:

Comment on lines +151 to +157
if format == "json":
with open(filename, "w", encoding="utf-8") as f:
json.dump(text, f)
elif format == "csv":
with open(filename, "w", encoding="utf-8", newline='') as f:
writer = csv.writer(f)
writer.writerows(text)
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't make a lot of sense since text is explicitly typed as str. I'd advise breaking this up into separate commands.

@Pwuts Pwuts changed the title Implement Flask web interface and enhance file operations feat(autogpt_classic): Implement Flask web interface and enhance file operations Apr 7, 2025
@ntindle
Copy link
Member

ntindle commented Apr 28, 2025

Closing for CLA poke us if you sign :)

@ntindle ntindle closed this Apr 28, 2025
@github-project-automation github-project-automation bot moved this from 🆕 Needs initial review to ✅ Done in AutoGPT development kanban Apr 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conflicts Automatically applied to PRs with merge conflicts platform/backend AutoGPT Platform - Back end Review effort 3/5 size/l
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants