Skip to main content
The memory turn loop is the sequence of EDN calls your application makes around each exchange. It builds a Session Initialization Package (SIP) for your model, saves the conversation as memory and processes the AI response. Follow these seven steps in order:
  1. Save the user’s message to the session.
  2. Build a SIP.
  3. Call your model.
  4. Save the exchange.
  5. Classify the reply.
  6. Save a generated statement, when applicable.
  7. Save the AI response to the session.
Use the same session_id for every exchange in the same conversation. EDN creates the session the first time a new session_id is used. To keep a conversation inside a project, send the same project_id to Build a SIP, Save a conversation turn, Classify an AI response and Save a generated statement.

1. Save the user’s message to the session

Use Add a message to a session to save the user’s message before building context. Send:
  • role: Set to user.
  • content: The user’s message, up to 100,000 characters.
Saved messages form the session’s transcript. They are not memory. Saving the user’s message helps Build a SIP find relevant memory when the user asks a short follow-up question.

2. Build a SIP

Use Build a SIP to retrieve the memory relevant to the user’s current message. Send:
  • query: The user’s message.
  • session_id: The conversation session.
  • project_id: Optional. The project containing the conversation’s memory.
The response includes:
  • sip: The context text to place in the model’s prompt, ahead of the user’s message.
  • grounded: true when project_id was supplied.
  • citations: One entry per numbered item in a project SIP.
Building a SIP counts against the daily SIP quota.

3. Call your model

EDN never calls your model and never answers questions for you. Place the returned sip in your model’s prompt, ahead of the user’s message, and call your model as usual. EDN works with any model.

4. Save the exchange

After receiving the model’s reply, use Save a conversation turn to store the exchange as memory. Send:
  • user_message: The user’s message.
  • assistant_message: The model’s reply.
  • session_id: The conversation session.
  • project_id: The project, when applicable.
EDN saves the exchange as a ROUND memory and returns its record_id. EDN also checks the user’s message for new facts and corrections. When it saves a fact, the response includes a fact object containing:
  • record_id: The ID of the saved fact.
  • replaces: The ID of the older memory it replaced, or null.
When no fact was saved, fact is null.

5. Classify the reply

Use Classify an AI response to check whether the model’s reply answered a factual question from the user. Send:
  • user_message: The user’s message.
  • assistant_message: The model’s reply.
  • session_id: The conversation session.
  • sip: The context returned in step 2.
  • project_id: The project, when applicable.
EDN uses sip to check whether specific facts in the reply are supported by the supplied context. Without it, factual claims cannot be verified. When the reply answers a factual question and is supported by the SIP, EDN saves it as an AI_INFERRED memory. The response contains:
  • saved: true.
  • provenance: AI_INFERRED.
  • record_id: The ID of the saved memory.
An AI_INFERRED memory is not used in SIPs until the user confirms it. Otherwise, saved is false, and reason explains why:
  • not_an_answer: The reply does not answer a factual question from the user.
  • abstention: The reply states that it does not know.
  • unsupported_claim: A fact in the reply is not supported by the supplied SIP.
When the reply is not a factual answer, provenance is AI_GENERATED.

6. Save a generated statement

When Classify an AI response returns AI_GENERATED as the provenance, you can use Save a generated statement to store the reply. Send:
  • assistant_message: The model’s reply.
  • session_id: The conversation session.
  • project_id: The project, when applicable.
EDN saves the reply as an AI_GENERATED memory. This includes assistant output such as suggestions or drafts. An AI_GENERATED memory is never used in a SIP until the user confirms it. Saving a generated statement counts against the daily ingest quota.

7. Save the AI response to the session

Use Add a message to a session again to save the model’s reply to the session transcript. Send:
  • role: Set to assistant.
  • content: The model’s reply.
When EDN checks the next user message for a correction, it uses the latest assistant message saved to that session. Saving both sides of the conversation helps EDN detect corrections in later exchanges.

The complete loop


Next steps: See Build a SIP and Save a conversation turn for the API reference.