I already have an AI made to write tools, which is the solution here: to have the AI emit any noteworthy element to a customer database for that assistant that your code provides, and then for the present state of memory to be placed with the additional_instructions
parameters.
So lets have it ramble on to give inspiration:
Here is a new tool function specification for toolspec
that allows the AI to store cross-session memories. This specification includes all necessary details and constraints to guide its use effectively.
Tool Specification for Cross-Session Memory
toolspec.extend([{
"type": "function",
"function": {
"name": "store_cross_session_memory",
"description": "Stores information in a cross-session memory, allowing the AI to recall or reference this information in future interactions with the user. The memory is stored as key-value pairs.",
"parameters": {
"type": "object",
"properties": {
"key": {
"type": "string",
"description": "A unique identifier for the memory item."
},
"value": {
"type": "string",
"description": "The information to be remembered across sessions."
},
"expires_in": {
"type": "number",
"description": "The time in days after which the memory should expire automatically. Set to 0 for no expiration.",
"minimum": 0
}
},
"required": ["key", "value"]
}
}
}])
Examples of Language and Arguments for Storing Memory
Here are some example interactions where the AI might emit language and arguments to store something in cross-session memory:
Example 1: Remembering a User’s Preference
{
"role": "assistant",
"content": "I'll remember that you prefer shipping updates via email.",
"tool_calls": [
{
"type": "function",
"function": {
"name": "store_cross_session_memory",
"arguments": "{\"key\": \"user_shipping_preference\", \"value\": \"email\", \"expires_in\": 365}"
}
}
]
}
Example 2: Storing an Important Date
{
"role": "assistant",
"content": "I'll keep a note of your anniversary date.",
"tool_calls": [
{
"type": "function",
"function": {
"name": "store_cross_session_memory",
"arguments": "{\"key\": \"user_anniversary_date\", \"value\": \"2024-06-07\", \"expires_in\": 0}"
}
}
]
}
Example 3: Remembering a Frequently Asked Question
{
"role": "assistant",
"content": "I'll remember your usual order for quicker service next time.",
"tool_calls": [
{
"type": "function",
"function": {
"name": "store_cross_session_memory",
"arguments": "{\"key\": \"user_usual_order\", \"value\": \"Large coffee with cream\", \"expires_in\": 90}"
}
}
]
}
Each example shows how the AI would inform the user of what it’s remembering and then makes a corresponding tool call to store this information using the store_cross_session_memory
function, specifying a key
, value
, and optionally expires_in
to indicate when or if the memory should expire. This setup ensures the AI can maintain context and provide personalized interactions based on past data stored across sessions.