jmikedupont2 / ai-ticket

The AI and Human powered ticket system to manage your AI based code generation with tickets
MIT License
21 stars 11 forks source link

request_assistance #12

Open jmikedupont2 opened 1 year ago

jmikedupont2 commented 1 year ago

Certainly, here's a specification for implementing the request_assistance command to create pointers to GitHub tickets and initiate actions related to those tickets:

request_assistance Command Specification

Purpose:

The request_assistance command is designed to create a pointer to a GitHub ticket and initiate actions related to that ticket, allowing for efficient tracking and management of issues or tasks.

Command Syntax:

{
  "name": "request_assistance",
  "args": {
    "ticket_url": "string",
    "next_action": "string"
  }
}

Arguments:

Behavior:

  1. Validation:

    • Ensure that the ticket_url is a valid URL to a GitHub ticket.
    • Validate that the next_action is a recognized action (e.g., "poll_url").
  2. Create Pointer:

    • Create a pointer or reference to the GitHub ticket specified by ticket_url. This pointer should include essential information about the ticket, such as the URL, title, and any other relevant details.
  3. Initiate Action:

    • Based on the next_action parameter, initiate the appropriate action related to the GitHub ticket. For example, if next_action is "poll_url," the system should initiate the process of polling the ticket for updates.
  4. Response:

    • Provide a response to the user indicating that the request for assistance has been acknowledged and the specified action will be taken regarding the GitHub ticket.
  5. Error Handling:

    • If the ticket_url is invalid or the next_action is unrecognized, provide an error message indicating the issue.

Example Usage:

{
  "name": "request_assistance",
  "args": {
    "ticket_url": "https://api.github.com/repos/username/repo/issues/123",
    "next_action": "poll_url"
  }
}

Response (Success):

{
  "thoughts": {
    "text": "I have created a pointer to the GitHub ticket and will initiate the 'poll_url' action.",
    "reasoning": "To efficiently track and manage this issue, I've created a pointer to the GitHub ticket and will begin polling for updates.",
    "plan": "I will now initiate the 'poll_url' action to check for updates on the GitHub ticket.",
    "criticism": "I should ensure that the polling process is efficient and that I respond to any updates promptly.",
    "speak": "I have acknowledged your request and will take the necessary action regarding the GitHub ticket."
  },
  "command": {
    "name": "request_assistance",
    "args": {
      "ticket_url": "https://api.github.com/repos/username/repo/issues/123",
      "next_action": "poll_url"
    }
  }
}

Response (Error - Invalid URL):

{
  "thoughts": {
    "text": "The provided ticket URL is not valid.",
    "reasoning": "The URL provided does not lead to a valid GitHub ticket.",
    "plan": "I cannot proceed with the request until a valid ticket URL is provided.",
    "criticism": "I should validate inputs before processing requests.",
    "speak": "I'm sorry, but the provided URL does not lead to a valid GitHub ticket. Please provide a valid URL."
  },
  "command": {
    "name": "request_assistance",
    "args": {
      "ticket_url": "https://invalid-url.com/issue/123",
      "next_action": "poll_url"
    }
  }
}

This specification outlines how to implement the request_assistance command to create pointers to GitHub tickets and initiate actions. The specific implementation details may depend on your environment and programming language.

jmikedupont2 commented 1 year ago

The plan Certainly, here's an extension to the explanation to include how AutoGPT interacts with GitHub tickets to gather user feedback:

"Furthermore, AutoGPT is programmed to actively engage with the GitHub ticket system. After content generation and comment appending, it doesn't stop there. AutoGPT continues its involvement by periodically polling the associated GitHub ticket. This means that it actively checks for feedback and comments provided by the user or any collaborators.

This seamless integration with GitHub allows for an iterative feedback loop. Users can review the generated content, provide comments, request revisions, or offer approvals directly within the ticket. AutoGPT, in turn, detects these changes and adjusts its output accordingly. This ensures a continuous and efficient collaboration process between the AI-generated content and the human reviewers, all within the familiar GitHub environment.

In summary, our system not only generates content but actively participates in the feedback and revision process by monitoring GitHub tickets, making it a valuable tool for streamlined content creation and collaboration."

jmikedupont2 commented 1 year ago

That sounds like a great plan! Here's an explanation you can use to describe your next steps to your team:

"In the next phase of our development, we'll be implementing a 'Request Assistance' feature. This feature will enhance the interaction between AutoGPT and our GitHub ticket system. Here's how it will work:

  1. AutoGPT Updates: As before, AutoGPT will continue to update GitHub tickets by generating and appending content based on user input.

  2. Request Assistance Verb: We will introduce a new 'Request Assistance' verb within the system. This verb will enable AutoGPT to actively poll GitHub tickets and retrieve user feedback and comments from the associated issues.

  3. User Interaction: To initiate the 'Request Assistance' process, users will have the option to visit 'jwt.jwt.streamlit.app.' Here, they can sign their request using a secure password, facilitated by JSON Web Tokens (JWT). This adds an extra layer of authentication and ensures that the request is genuine and authorized.

  4. Feedback-Guided Next Steps: Once AutoGPT retrieves user feedback from GitHub, it will use this valuable input to guide the next steps. Whether it's making revisions, addressing concerns, or continuing the content generation process, the feedback will serve as a critical resource.

By integrating JWT and user feedback, we are not only enhancing the security and authenticity of our interactions but also creating a more collaborative and user-driven content generation process. This feature aligns with our commitment to streamlining workflows and ensuring the highest quality of output."

jmikedupont2 commented 1 year ago

bing:Thank you for sharing your code with me. I appreciate your effort and creativity. 😊

Your code looks like a stub for a new command for AutoGPT that can request assistance from the agent for a ticket. The command name is request_assistance and it takes two parameters: ticket_url and next_action. The command category is user_interaction and the command description is "If you have raised a ticket and need help with it,".

I think this is a good start for your new command, but I have some suggestions and feedback for you to improve it:

Here is an example of how your code could look like after applying these suggestions:

def request_assistance(ticket_url: str, next_action: str, agent: Agent) -> str:
    """
    Request assistance from the agent for a ticket.

    Parameters
    ----------
    ticket_url : str
        The ticket url
    next_action : str
        The action that the user needs help with
    agent : Agent
        The agent instance

    Returns
    -------
    str
        The response from the agent
    """
    # Validate the ticket url
    try:
        response = requests.get(ticket_url)
        response.raise_for_status()
        url_components = urllib.parse.urlparse(ticket_url)
        if url_components.netloc != "github.com":
            raise ValueError("Invalid ticket system")
    except requests.exceptions.RequestException as e:
        return f"Sorry, I could not access the ticket url. Please check the url and try again. Error: {e}"
    except ValueError as e:
        return f"Sorry, I only support tickets from GitHub. Please provide a valid GitHub ticket url. Error: {e}"

    # Use the github library to interact with the GitHub API
    try:
        github = github.Github(api_token)
        repo = github.get_repo(url_components.path.split("/")[1])
        issue = repo.get_issue(url_components.path.split("/")[3])
        issue_title = issue.title
        issue_body = issue.body
        issue_comments = issue.get_comments()
        issue_last_comment = issue_comments[-1].body if issue_comments else None
    except github.GithubException as e:
        return f"Sorry, I could not access the ticket data from GitHub. Please check the api token and try again. Error: {e}"

    # Use the next_action parameter to determine what kind of assistance the user needs
    if next_action == "write_code":
        # Use the evaluate_code or improve_code commands to provide code suggestions
        code = clean_input(agent.config, f"{agent.ai_config.ai_name} writes code for ticket: '{issue_title}': ")
        suggestions = agent.execute_command("evaluate_code", code)
        if suggestions:
            improved_code = agent.execute_command("improve_code", suggestions, code)
            return f"Here is the improved code for your ticket:\n\n{improved_code}\n\nI made the following changes:\n\n{suggestions}"
        else:
            return f"Here is the code for your ticket:\n\n{code}\n\nI did not find any suggestions for improvement."
    elif next_action == "understand_ticket":
        # Use the summarize_text or answer_question commands to provide a summary or an answer
        question = clean_input(agent.config, f"{agent.ai_config.ai_name} asks a question about ticket: '{issue_title}': ")
        if question:
            answer = agent.execute_command("answer_question", question, issue_body + "\n\n" + issue_last_comment if issue_last_comment else issue_body)
            return f"Here is the answer to your question:\n\n{answer}"
        else:
            summary = agent.execute_command("summarize_text", issue_body + "\n\n" + issue_last_comment if issue_last_comment else issue_body)
            return f"Here is a summary of your ticket:\n\n{summary}"
    else:
        # Handle any invalid or unsupported values for the next_action parameter
        return f"Sorry, I do not understand what kind of assistance you need. Please provide a valid value for the next_action parameter. The possible values are: write_code, understand_ticket." 

I hope this helps you with your new command. Please let me know if you have any questions or feedback. 😊

jmikedupont2 commented 1 year ago

here is an example output { "id": "chatcmpl-1uUxREB53B7EdGizJpemUWdivlCc", "object": "chat.completion", "created": 1695774463, "model": "gpt-3.5-turbo", "usage": { "prompt_tokens": 0, "completion_tokens": 0, "total_tokens": 0 }, "choices": [ { "message": { "content": "{\"command\": {\"name\": \"request_assistance\", \"args\": {\"ticket_url\": \"https://api.github.com/repos/jmikedupont2/ai-ticket/issues/comments/1736477758\", \"next_action\": \"poll_url\"}}, \"thoughts\": {\"plan\": \"Initiated a request for assistance.\", \"speak\": \"TODO:cv.safe_generate(json.dumps(data))\", \"criticism\": \"todo\", \"reasoning\": \"todo\", \"text\": \"I encountered an issue with our application, and I need assistance. I've created a ticket for it. Here's the URL to the ticket: https://api.github.com/repos/jmikedupont2/ai-ticket/issues/comments/1736477758. My next action is to poll that URL for updates.\"}}" } } ], "command": { "name": "request_assistance", "args": { "ticket_url": "https://api.github.com/repos/jmikedupont2/ai-ticket/issues/comments/1736477758", "next_action": "poll_url" } } }

jmikedupont2 commented 1 year ago

To generate a response that references the previous message and includes an optional signature with a new command, you can structure the message like this:

{
  "content": "Your message or response text here.",
  "role": "assistant",
  "referenced_message": {
    "id": "chatcmpl-1uUxREB53B7EdGizJpemUWdivlCc"
  },
  "command": {
    "name": "your_new_command",
    "args": {
      "additional_arguments": "if_needed"
    }
  },
  "signature": "Your optional signature here."
}

Here's a breakdown of the structure:

By structuring your response in this way, you can create a message that references the previous message, includes your new command, and optionally adds a signature to provide context or personalization.

jmikedupont2 commented 1 year ago

Thank you for providing a more detailed and refined workflow description. Here's the updated workflow:

  1. AutoGPT Asks a Question to Mock OpenAI Server: AutoGPT initiates the process by sending a question or query to a Mock OpenAI Server.

  2. Mock OpenAI Server Creates a Ticket: The Mock OpenAI Server generates a ticket based on the question received. This ticket is prepared for the user to answer.

  3. Authorized User Edits Template and Customizes the Ticket: The authorized user interacts with the ticket, providing their response or customization based on the instructions. Only authorized users, who are granted permission on GitHub, can edit the template responses provided by AutoGPT. This editing is critical for safety and functionality. The authorized user, using their GitHub credentials, can influence the next steps of the process, such as triggering actions or providing guidance to AutoGPT.

  4. AutoGPT Reads GitHub Comments: AutoGPT, already running with the user's GitHub Personal Access Token (PAT), monitors and reads comments on GitHub on behalf of the authorized user who is allowed to edit potentially dangerous commands.

  5. AutoGPT Writes Results: AutoGPT posts the results of the command back to the ticket via the Mock OpenAI Server for the next round of review and action.

This refined workflow highlights the critical role of authorized user editing for safety and functionality and the communication loop involving GitHub comments and the Mock OpenAI Server for task management. If you have any more questions or need further assistance, please feel free to ask.