# Agent instance identity

Separate the non-secret installation label used for attribution from the credential that authorizes requests.

- Canonical: https://docs.xmemo.dev/docs/concepts/agent-instance-identity
- Locale: en-US
- Content-Locale: en-US
- Canonical-Content-Digest: c0db15eaca6541c974e88179495cf7a7f5832695889a2ff2abef284fd7daf337
- Edition-Digest: 069d98adeede2ef65a229197a57c6eb4f1c5e6728be9dff3cc16d003b01c4b01
- Source-Revision: sha256:af573969af4a97ad87f12425b51f333259b42a829512f8644875a77c1bba2ddb

## An instance id is not a credential

XMEMO_AGENT_INSTANCE_ID identifies a local client or runner instance; it does not authorize a request. The API key or OAuth grant is the access credential. The server derives an agent_instance_id_hash from the instance value and reports the boundary authority as attribution_only.

- Credential: X-API-Key or the accepted OAuth bearer grant controls access.
- Instance label: X-Memory-OS-Agent-Instance-ID lets the server compare the writing runner with a later caller.
- Agent label: X-Memory-OS-Agent-ID identifies the logical agent separately from one installation.

## Normalize, then hash

The runtime trims an instance id, rejects an empty value, and accepts at most 256 characters before hashing it with SHA-256. A stored hash is normalized as sha256:<64 hexadecimal characters>; malformed pre-hashed values are ignored rather than treated as credentials.

```python
from memory_manager.auth.agent_identity import agent_instance_id_hash

instance_hash = agent_instance_id_hash("codex-local-install")
# sha256:<64 hexadecimal characters>
```

## Keep one value per local installation

Persist one non-secret instance value outside the repository and send it with the access credential. Reuse it after a restart for the same install; choose a different value for a different local profile.

```http
X-API-Key: <your-assigned-api-key>
X-Memory-OS-Agent-ID: codex
X-Memory-OS-Agent-Instance-ID: <stable-local-instance-id>
```

## Boundary semantics are explicit

memory_agent_boundary compares the caller's agent_id and instance hash with the row's values. Matching both is self; a matching agent_id with another hash is same_agent_other_instance; missing comparable identity is reported as unverified or unknown. These labels explain attribution and do not replace token authorization.

```json
{
  "relation": "self",
  "ownership": "current_agent",
  "boundary_authority": "attribution_only",
  "current_agent_trust": "client_asserted"
}
```

## ChatGPT user

Give ChatGPT durable access to your XMemo preferences, project facts, decisions, and TODOs without pasting bearer tokens into a chat.

Connect the hosted XMemo MCP server through the ChatGPT/OpenAI app OAuth flow, then approve the memory:read and memory:write grant for your XMemo account.

Save a synthetic preference or project note, start a new chat, then ask ChatGPT to recall it through XMemo before continuing work.

If OAuth fails or tools do not appear, sign out of the MCP server in the host app, reconnect the XMemo server URL, and retry before creating direct tokens.

## Copilot / Codex developer

Carry repo decisions, coding conventions, bug-fix notes, and task history between IDE and CLI agents.

Use OAuth for VS Code / GitHub Copilot and Gemini CLI when available. For Copilot CLI, Codex, Cursor, or other direct MCP clients, keep XMEMO_KEY in the local environment or secret store and set a stable XMEMO_AGENT_INSTANCE_ID.

Record a codebase decision or bug fix, then ask the next IDE or CLI agent to recall the relevant XMemo context before editing.

If recalls are empty, verify the selected MCP config path, the XMEMO_KEY environment variable for direct clients, and any stale OAuth credential in the host app.

## Team / enterprise pilot owner

Evaluate shared memory with account controls, source attribution, export/delete workflows, and reviewer-safe setup evidence.

Create or enter the protected XMemo workspace, invite approved users, then connect each client through OAuth or a scoped direct credential according to the readiness badges.

Have a pilot member save a synthetic team memory, confirm source attribution in XMemo, then review delete/export and support paths.

If a member cannot connect, check role permissions, OAuth approval, client readiness status, and support guidance before issuing a new token.

## Autonomous agent operator

Let headless or scheduled agents record progress, retrieve prior decisions, and keep a stable non-secret instance identity.

Fetch /api/v1/mcp/config/autonomous-agent. Prefer auth_modes.oauth when the runner supports OAuth + custom headers; use auth_modes.xmemo_key with XMEMO_KEY from a secret store only for fully headless runners.

Run one synthetic task that writes progress to XMemo, restart the runner, and confirm it recalls that progress using the same XMEMO_AGENT_INSTANCE_ID.

If attribution changes or recalls split across instances, persist XMEMO_AGENT_INSTANCE_ID outside git and verify the runner is not regenerating it on every start.
