You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"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:
defhttp_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 payloadifmethod.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 requestsifpayload_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}
exceptExceptionase:
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.
The text was updated successfully, but these errors were encountered:
@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?
Related to #282, #287
Example use-case
User wants to give MemGPT the ability to make HTTP requests
Example workflow
Schema
Currently only loaded through https://github.com/cpacker/MemGPT/blob/main/memgpt/prompts/gpt_functions.py
Implementation
Currently must be attached to agent:
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
.The text was updated successfully, but these errors were encountered: