Memory

The RPGGO game engine automatically performs a series of engineering optimizations and algorithmic recalls on the dialogue history between users and AI to enhance the quality of conversations.

Developers have the flexibility to retrieve the raw NPC memory (dialogue history) at any time, allowing them to insert custom dialogues at appropriate intervals to enrich the memory content.

Get Memory by Session

curl -X 'POST' \
  'https://api.rpggo.ai/open/game/memory' \
  -H 'accept: application/json' \
  -H 'Application-ID: $YOUR_APPLICATION_ID' \
  -H 'Authorization: $YOUR_BEARER_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
  "session_id": "$SESSION_ID"
}'

Retrieve the entire conversation history of the current session using the session ID.

POST https://api.rpggo.ai/open/game/memory

Request Body

Name
Type
Description

session_id*

String

session ID, must be an ongoing game session id

{
  "code": 0,
  "msg": "ok",
  "data": {
    "memory_item": [
      {
        "SessionID": "$SESSION_ID",
        "Source": "discord",
        "BotIndex": "1160442433985859738",
        "Message": "How long and often how does this happen with the fridge",
        "Reply": "How long and how often does this happen with the fridge? *(rolls eyes)* Well, it seems like Karen's lunch goes missing quite frequently. Maybe she's just forgetful or someone's got a real appetite for her food. But hey, who knows, maybe it's Lamar with his holy prayers, sneaking a snack when nobody's looking. Or maybe it's Alan, the quiet immigrant driver, trying to make ends meet by taking a bite out of Karen's lunch. *(smirking)* Who knows, right?",
        "Type": 0,
        "CreateTime": "1701139538",
        "UpdateTime": "1701139538"
      },
      {
        "SessionID": "$SESSION_ID",
        "Source": "discord",
        "BotIndex": "1160442433985859738",
        "Message": "Is Lamar Muslim?",
        "Reply": "How would I know if Lamar is Muslim? Do I look like his personal religious advisor? *(rolls eyes)* It's not like he prays in the break room every day or anything. *(sarcastic tone)* But hey, who knows, maybe he's just really committed to his faith and has nothing to do with Karen's missing lunch. Or maybe it's Alan, the starving immigrant driver, who's desperate enough to steal food. *(smirking)* Who knows, right?",
        "Type": 0,
        "CreateTime": "1701139538",
        "UpdateTime": "1701139538"
      }
    ],
    "counters": {
      "1160442433985859738": 2,
      "all": 2
    }
  }
}

Developers can retrieve the complete conversation records of the current session from the memory_item array in response.

  • botIndex corresponds to the NPC ID, allowing you to filter memories for a specific NPC using this field.

  • message and reply fields represent a user-AI dialogue

  • type field distinguishes memory types. 0 for normal interactions via the llm and 1 for dialogues stored through the open/game/recordmemory API.

Record Memory

curl -X 'POST' \
  'https://api.rpggo.ai/open/game/recordmemory' \
  -H 'accept: application/json' \
  -H 'Application-ID: $YOUR_APPLICATION_ID' \
  -H 'Authorization: $YOUR_BEARER_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
  "session_id": "rs_222531704307449856_1178834756272660602_20_3d529def-d6de-4ac7-989b-ff46dc5ac3ff",
  "chats": [
    {
      "npc_id": "1160442433985859738",
      "message": "hi, this is the user message",
      "reply": "hi, this is the assistant reply"
    },
    {
      "npc_id": "1160442433985859738",
      "message": "hi, this is another user message",
      "reply": "hi, this is the assistant reply"
    }
  ]
}'

POST https://api.rpggo.ai/open/game/recordmemory

Request Body

Name
Type
Description

session_id*

String

session ID, must be an ongoing game session id

chats*

List

A dictionary with three fields: npc_id, message, and reply

{
  "code": 0,
  "msg": "successfully saved 2 memories"
}

Before invoking the recordmemory API, it is essential to initiate a game to obtain a session id or use an already ongoing game. Memories are recorded in chronological order based on the invocation of the interface, and developers can retrieve them through the /open/game/memory interface.

In the chats field, developers can submit one or multiple conversation histories. Each dialogue history consists of three elements:

  • npc_id designates the associated NPC

  • message and reply simulate user and AI interactions

Last updated