Choose the repository and exact version
Use a separate memory repository when the information needs its own access rules, storage lifetime, or delete boundary. You can use one repository per project, user, tenant, or company. Before the agent reads memory, read the current commit SHA of the branch and store it with the agent session. This SHA is the pinned revision. It always identifies the same files, so the agent reads one exact version.createTag() when a person needs a readable name for the version.
Load only the required files
Give the sandbox a temporary API token for only the memory repository. Keep the organization private key in trusted product code. See Authentication & Security for token details. UsegetArchiveStream with file patterns to fetch a group of memory files without a git clone.
Use getFileStream for one file. The sandbox needs no local Git index and no git push.
Save the agent’s changes
SetexpectedHeadSha to the commit SHA that was current before the agent made its change. Code
Storage accepts the save only if the target branch still points to that commit.
precondition_failed; the branch still points at the pinned revision.
Treat it as success with no new commit.
After a timeout, the save can still have succeeded. Do not resend the same request. Read the current
head again, apply the intended change to the current files, and save with the new head as
expectedHeadSha.
Combine changes from separate branches
A product can give each agent session its own branch. Check the merge first, then requiremain to
remain at the commit that you checked.
main moved after the check, run the check
again on the new head.
Inspect and undo a change
UselistCommits to show file history and getCommitDiff to show one change.
restoreCommit to create a new commit from an earlier version. The new commit keeps the undo
action in history.