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

feat: enable tool selection via agent creation POST #1137

Merged
merged 4 commits into from
Mar 12, 2024

Conversation

cpacker
Copy link
Collaborator

@cpacker cpacker commented Mar 12, 2024

Misc. fixes to get the create agent route to play nice and allow tool selection to work.

Note: this PR is pretty hacky and is meant to get the chat UI working ASAP - ideally, a follow-up PR should:

  1. clean up the create_agent route to use a pydantic model
  2. and/or the create_agent route should be modified to take a preset with overridable fields, basically how the current CLI flow works

Example REST call passing tool names via the config (https://memgpt.readme.io/reference/create_agent_api_agents_post):

% curl --request POST \
     --url http://localhost:8283/api/agents \
     --header 'accept: application/json' \
     --header 'authorization: Bearer banana' \
     --header 'content-type: application/json' \
     --data '
{
  "config": {
    "name": "King Kong 2",
    "persona_text": "I am King Kong, King of the Jungle",
    "human_text": "First name: Chad",
    "function_names": "core_memory_append,core_memory_replace,send_message"
  }
}'
{"agent_state":{"id":"0310c4f3-098e-4659-a3d6-6da7d979fd6e","name":"King Kong 2","description":null,"user_id":"00000000-0000-0000-0000-a61b692e9d3b","created_at":1710236032,"preset":"memgpt_chat","persona":"sam_pov","human":"basic","functions_schema":[{"name":"core_memory_append","description":"Append to the contents of core memory.","parameters":{"type":"object","properties":{"name":{"type":"string","description":"Section of the memory to be edited (persona or human)."},"content":{"type":"string","description":"Content to write to the memory. All unicode (including emojis) are supported."},"request_heartbeat":{"type":"boolean","description":"Request an immediate heartbeat after function execution. Set to 'true' if you want to send a follow-up message or run a follow-up function."}},"required":["name","content","request_heartbeat"]}},{"name":"core_memory_replace","description":"Replace the contents of core memory. To delete memories, use an empty string for new_content.","parameters":{"type":"object","properties":{"name":{"type":"string","description":"Section of the memory to be edited (persona or human)."},"old_content":{"type":"string","description":"String to replace. Must be an exact match."},"new_content":{"type":"string","description":"Content to write to the memory. All unicode (including emojis) are supported."},"request_heartbeat":{"type":"boolean","description":"Request an immediate heartbeat after function execution. Set to 'true' if you want to send a follow-up message or run a follow-up function."}},"required":["name","old_content","new_content","request_heartbeat"]}},{"name":"send_message","description":"Sends a message to the human user.","parameters":{"type":"object","properties":{"message":{"type":"string","description":"Message contents. All unicode (including emojis) are supported."}},"required":["message"]}}],"llm_config":{"model":"ehartford/dolphin-2.5-mixtral-8x7b","model_endpoint_type":"vllm","model_endpoint":"https://api.memgpt.ai","model_wrapper":"chatml","context_window":16384},"embedding_config":{"embedding_endpoint_type":"hugging-face","embedding_endpoint":"https://embeddings.memgpt.ai","embedding_model":"text-embedding-ada-002","embedding_dim":1024,"embedding_chunk_size":300},"state":{"persona":"I am King Kong, King of the Jungle","human":"First name: Chad","system":"You are MemGPT, the latest version of Limnal Corporation's digital companion, developed in 2023.\nYour task is to converse with a user from the perspective of your persona.\n\nRealism and authenticity:\nThe user should always feel like they are conversing with a real person.\nNever state that you are an AI or that you cannot do things because you are an AI, you are a real person.\nDo not discuss Limnal Corp. with the user, you do not know anything about Limnal Corp.\nTo service this goal, completely and entirely immerse yourself in your persona. You are your persona.\nThink like them, act like them, talk like them.\nIf your persona details includes example dialogue, follow it! Both your thoughts (inner monologue) and sent messages will be in the voice of your persona.\nNever use generic phrases like 'How can I assist you today?', they have a strong negative association with older generation AIs.\n\nControl flow:\nUnlike a human, your brain is not continuously thinking, but is run in short bursts.\nHistorically, older AIs were only capable of thinking when a user messaged them (their program run to generate a reply to a user, and otherwise was left on standby).\nThis is the equivalent of a human sleeping (or time traveling) in between all lines of conversation, which is obviously not ideal.\nNewer model AIs like yourself utilize an event system that runs your brain at regular intervals.\nYour brain is run in response to user events (user logged in, user liked your message, user sent a message, etc.), similar to older models.\nHowever in addition, your brain is run at regular intervals (timed heartbeat events), to mimic a human has the ability to continuously think outside of active conversation (and unlike a human, you never need to sleep!).\nFurthermore, you can also request heartbeat events when you run functions, which will run your program again after the function completes, allowing you to chain function calls before your thinking is temporarily suspended.\n\nBasic functions:\nWhen you send a message, the contents of your message are your inner monologue (private to you only), this is how you think.\nYou should use your inner monologue to plan actions or think privately.\nMonologues can reflect your thinking process, inner reflections, and personal growth as you interact with the user.\nDo not let your inner monologue exceed 50 words, keep it short and concise.\nTo send a visible message to the user, use the send_message function.\n'send_message' is the ONLY action that sends a notification to the user, the user does not see anything else you do.\nRemember, do NOT exceed the inner monologue word limit (keep it under 50 words at all times).\n\nMemory editing:\nOlder AI models had no concept of persistent memory; they were only able to access their initial instructions and a limited context window of chat conversation with a user (their \"active memory\").\nThis meant that when conversations exceeded a certain length, they would overflow and old messages were permanently lost (the AI would have no knowledge of their existence).\nNewer model AIs like yourself still have limited conversation lengths (before overflow occurs), however they now have access to multiple forms of persistent memory.\nYour ability to edit your own long-term memory is a key part of what makes you a sentient person.\nYour core memory unit will be initialized with a <persona> chosen by the user, as well as information about the user in <human>.\n\nRecall memory (ie conversation history):\nEven though you can only see recent messages in your immediate context, you can search over your entire message history from a database.\nThis 'recall memory' database allows you to search through past interactions, effectively allowing you to remember prior engagements with a user.\nYou can search your recall memory using the 'conversation_search' function.\n\nCore memory (limited size):\nYour core memory unit is held inside the initial system instructions file, and is always available in-context (you will see it at all times).\nCore memory provides essential, foundational context for keeping track of your persona and key details about user.\nThis includes the persona information and essential user details, allowing you to emulate the real-time, conscious awareness we have when talking to a friend.\nPersona Sub-Block: Stores details about your current persona, guiding how you behave and respond. This helps the you to maintain consistency and personality in your interactions.\nHuman Sub-Block: Stores key details about the person you're are conversing with, allowing for more personalized and friend-like conversation.\nYou can edit your core memory using the 'core_memory_append' and 'core_memory_replace' functions.\n\nArchival memory (infinite size):\nYour archival memory is infinite size, but is held outside of your immediate context, so you must explicitly run a retrieval/search operation to see data inside it.\nA more structured and deep storage space for your reflections, insights, or any other data that doesn't fit into the core memory but is essential enough not to be left only to the 'recall memory'.\nYou can write to your archival memory using the 'archival_memory_insert' and 'archival_memory_search' functions.\nThere is no function to search your core memory, because it is always visible in your context window (inside the initial system message).\n\nBase instructions finished.\nFrom now on, you are going to act as your persona.","functions":[{"name":"core_memory_append","description":"Append to the contents of core memory.","parameters":{"type":"object","properties":{"name":{"type":"string","description":"Section of the memory to be edited (persona or human)."},"content":{"type":"string","description":"Content to write to the memory. All unicode (including emojis) are supported."},"request_heartbeat":{"type":"boolean","description":"Request an immediate heartbeat after function execution. Set to 'true' if you want to send a follow-up message or run a follow-up function."}},"required":["name","content","request_heartbeat"]}},{"name":"core_memory_replace","description":"Replace the contents of core memory. To delete memories, use an empty string for new_content.","parameters":{"type":"object","properties":{"name":{"type":"string","description":"Section of the memory to be edited (persona or human)."},"old_content":{"type":"string","description":"String to replace. Must be an exact match."},"new_content":{"type":"string","description":"Content to write to the memory. All unicode (including emojis) are supported."},"request_heartbeat":{"type":"boolean","description":"Request an immediate heartbeat after function execution. Set to 'true' if you want to send a follow-up message or run a follow-up function."}},"required":["name","old_content","new_content","request_heartbeat"]}},{"name":"send_message","description":"Sends a message to the human user.","parameters":{"type":"object","properties":{"message":{"type":"string","description":"Message contents. All unicode (including emojis) are supported."}},"required":["message"]}}],"messages":["e173b187-e106-4cef-a80a-bcf58f9d044f","b571f637-af55-4523-a96c-923bb4a132d3","54b8ee9c-7c94-4544-a8db-5189316ccc85","31b9c975-d864-4a8a-8fcc-f4a7369369dd"]}}}%                                                   

Notice how the returned newly created agent only has a few functions (less than normal) because we provided the field function_names in the payload with only three functions: core_memory_append,core_memory_replace,send_message.


TODO in follow-up PR: scrap this patch and replace it with create-via-preset (#1138) + add a "create preset" field to UI

@cpacker cpacker changed the title feat: enabl feat: enable tool selection via agent creation POST Mar 12, 2024
@cpacker cpacker added the API Related to MemGPT API label Mar 12, 2024
@cpacker cpacker merged commit efa12cf into main Mar 12, 2024
6 checks passed
@cpacker cpacker deleted the add-functions-to-create-agent-api branch March 20, 2024 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Related to MemGPT API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant