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

Configurable presets #339

Closed
cpacker opened this issue Nov 7, 2023 · 1 comment · Fixed by #420
Closed

Configurable presets #339

cpacker opened this issue Nov 7, 2023 · 1 comment · Fixed by #420
Assignees
Labels
priority Merge ASAP
Milestone

Comments

@cpacker
Copy link
Collaborator

cpacker commented Nov 7, 2023

Related to #282, #287


Example use-case

User wants to give MemGPT the ability to make HTTP requests

Example workflow

  1. User adds the JSON schema for the new function
  2. User adds the python code for the new function
  3. [Optional] User adds a new system message prompt
  4. User creates a new "preset" (combination of system message + available functions)

Schema

Currently only loaded through https://github.com/cpacker/MemGPT/blob/main/memgpt/prompts/gpt_functions.py

    "http_request": {
        "name": "http_request",
        "description": "Generates an HTTP request and returns the response.",
        "parameters": {
            "type": "object",
            "properties": {
                "method": {
                    "type": "string",
                    "description": "The HTTP method (e.g., 'GET', 'POST').",
                },
                "url": {
                    "type": "string",
                    "description": "The URL for the request",
                },
                "payload": {
                    "type": "string",
                    "description": "A JSON string representing the request payload.",
                },
                "request_heartbeat": {
                    "type": "boolean",
                    "description": FUNCTION_PARAM_DESCRIPTION_REQ_HEARTBEAT,
                },
            },
            "required": ["method", "url", "request_heartbeat"],
        },
    },

Implementation

Currently must be attached to agent:

    def http_request(self, method, url, payload_json=None):
        """
        Makes an HTTP request based on the specified method, URL, and JSON payload.

        Args:
        method (str): The HTTP method (e.g., 'GET', 'POST').
        url (str): The URL for the request.
        payload_json (str): A JSON string representing the request payload.

        Returns:
        dict: The response from the HTTP request.
        """
        try:
            headers = {"Content-Type": "application/json"}

            # For GET requests, ignore the payload
            if method.upper() == "GET":
                print(f"[HTTP] launching GET request to {url}")
                response = requests.get(url, headers=headers)
            else:
                # Validate and convert the payload for other types of requests
                if payload_json:
                    payload = json.loads(payload_json)
                else:
                    payload = {}
                print(f"[HTTP] launching {method} request to {url}, payload=\n{json.dumps(payload, indent=2)}")
                response = requests.request(method, url, json=payload, headers=headers)

            return {"status_code": response.status_code, "headers": dict(response.headers), "body": response.text}
        except Exception as e:
            return {"error": str(e)}

Solution

Users write functions, and the schema is extracted automatically via the docstrings

This also avoids issues with typos in schemas where the schema does not match the function signature correctly.

When a user wants to add more functions, they can add python files to a directory containing those functions

For example, they write a few functions related to using JIRA in jira.py. Then, they simply need to place this python file inside of eg ~/.memgpt/functions, and these functions will be available to the preset loader.

Then they can also add a custom preset (JSON) that uses a specific set of functions (providing function names), and put this preset inside of ~/.memgpt/presets.

@cpacker cpacker self-assigned this Nov 7, 2023
@cpacker cpacker added the priority Merge ASAP label Nov 7, 2023
@cpacker
Copy link
Collaborator Author

cpacker commented Nov 7, 2023

@vivi this refactor becomes much more complicated with both async and sync dupe functions attached to all the agents - is there a go-ahead on stripping AsyncAgent?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority Merge ASAP
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants