A-Graph by Agens Research Labs

Memory

A memory keeps the conversation of a node between runs: what the user asked, what the node answered, and a summary of what came before.

A memory keeps the conversation of a node between runs: what the user asked, what the node answered, and a summary of what came before. Memories are declared in external.memory; a node uses one with external.memory on the node, where it says which roles it reads and which it saves. Every key is described in the reference.

external:
  memory:
    - id: session
      provider: json_file
      path: ./sessions/session_a.json
      synt: { length: 10, model: fast }
      chat: { length: 10 }

graph:
  nodes:
    - id: assistant
      external:
        memory:
          - id: session
            read: { user: true, assistant: true }
            write: { user: true, assistant: true }

Only provider: json_file runs today. provider: vectordb (with ref, the id of a vector database) is accepted when the file is checked, but a node that uses it fails when it runs. A json_file memory needs path and chat.

The file

The file is a JSON list of records, one for each node. A node reads and writes only its own record.

[
  {
    "id": "assistant",
    "timestamp": "2026-10-13_21:12:00",
    "synt": "",
    "chat": [
      { "role": "user", "content": "...", "embedding": [0.1, 0.2] },
      { "role": "assistant", "content": "..." }
    ]
  }
]
  • id: the node.
  • timestamp: when the record was last changed, in UTC.
  • synt: the summary, empty until there is one.
  • chat: the messages not summarized yet, in the standard form of chat messages (role and content). A message of the user carries the vector of its text when the memory has chat.embedding.

A file that does not exist yet, an empty file, or a file without a record of the node, is an empty memory. The file, its folder and the record are created at the first write. The file is written in one step (a temporary file of its own, then renamed), so a reader sees the file before or after a write, never half of it. Each change of a record holds an exclusive lock on <path>.lock, a file left next to the memory, from the read of the file to its write: requests of the service and runs of the command line that share the file wait for each other and none of their records is lost. If the process dies between the write of the temporary file and its rename, the temporary file stays next to the memory, and the memory stays as it was. Each temporary file has a random name, so one left behind does not stop the next write. The new file keeps the permissions of the old one (a file set to 0600 stays 0600), its owner becomes the user of the process, and a hard link to the old file keeps the old content. A write to a memory that is a symbolic link fails the node (io) and changes nothing: the yml names the file itself.

A file that is not a list of records fails the node that reads or writes it (io). The message says where, by line and column; what the parser says, which may quote a text of the file, is the detail of the error, written only as the passport allows (see observability).

Reading

Before the call, for every memory of the node:

  • chat becomes the history of the call: the messages that come before the new message. It holds the last chat.length exchanges (a message of the user and the answer after it) or, with chat.embedding, the chat.length exchanges whose message of the user is most similar to the new message, kept in the order they were saved. Only the roles that read takes are kept.
  • synt, for a memory that has synt, goes into the prompt where it writes {{<memory-id>}} (see prompts). A memory without synt has no placeholder.

The read.utility changes each message read and the summary.

Writing

After the node answers, the exchange of this turn is saved in the record of the node: the message the node took (the message of the user if the node takes it, or else the message of the node before; none if it takes neither) and its answer, only the roles that write allows. Any combination is allowed, for example only the messages of the user; what comes back later is what was saved.

The write.utility changes what is saved, after the utilities of message.output; the vector of a saved message is made from the changed text.

The summary

With synt, a memory is summarized when the record of the node reaches synt.length exchanges. Without synt, chat only grows.

The model synt.model gets the previous summary and the exchanges to summarize, writes the new summary in at most synt.max_tokens tokens, and the summarized exchanges leave chat. The call sends no reasoning setting, so the model follows the default of its provider: a model that reasons spends part of max_tokens before it writes, which is why the default is 4000. A summary with no text fails the run.

The model is called outside the lock of the file, so other runs can save their exchanges meanwhile: they stay in chat. When another run wrote a summary meanwhile, this one is dropped and synt and chat are left as they are: the exchanges not summarized yet stay in chat, and are summarized at a next write.

Without synt.prompt the program uses a prompt of its own. A prompt written for the summary must use both of its placeholders (placeholder_unused):

  • {{synt}}: the previous summary, empty the first time;
  • {{chat}}: the exchanges to summarize, one message per line, as user: ... and assistant: ....

On this page