Skip to main content

Session History and Messages

Deployment owners can use these endpoints to read their own history on a standalone instance. Follow Connect and Authenticate to obtain the actual instance address and owner token. Every request uses X-Agent-Service-Token; no Socket.IO connection is needed.

Read scope and identifiers​

Session listings, merged history, search, and reads of a specific Run use the user identity resolved by the service. Requests for a specific Run check ownership before returning content. A missing, other-user, or cleared Run returns 404. Knowing its ID does not grant access, and a caller-supplied userId cannot select another user's data.

The two topic endpoints read Agent conversation memory for the connected instance's current local user profile. They are intended for the instance owner and do not provide tenant isolation for a shared service. A missing profile returns 401; ask the instance administrator to check it.

IdentifierWhere to obtain itUse on this page
Agent IDid in the Agent listagentId filters and topic paths
Run IDrunId in the session list, or a known authorized Run record/api/sessions/:runId and its messages path
Runtime session IDQuery start/acceptance events or an available runtime session referenceContinuing a conversation; it cannot replace a Run ID here
Topic IDactiveMatters[].id or recentMatters[].id in the conversation overview/matters/:id/full; it cannot be used to calculate a Run ID

These reads support display and search. Configuration, messages, or tool records in a history snapshot grant no execution permission, and the snapshot is not a protocol archive that can be replayed unchanged to a model provider. Determine whether a current submission completed using the request identity and terminal-event rules in Conversations and Runs.

List session history​

GET /api/sessions​

Query parameterMeaning
agentIdOptional Agent filter; omitting it reads the current user's regular session list
includeArchivedOnly the string true includes archived sessions; excluded by default
limitDefault 20; send a positive decimal integer
offsetDefault 0; send a nonnegative decimal integer

Results are ordered by updatedAt, newest first. Archiving and run status are separate properties; archived entries can include archivedAt. The list retains historical branches that can be opened. A branch may include messages inherited from a predecessor, so concatenating branches does not produce a deduplicated conversation.

This list does not enumerate delegated child Runs, separate conversations created in manual mode, or dedicated timelines such as schedules, Webhooks, and Mentions. There is no includeDelegated or includeManual switch. Background incoming conversations may have background: true; appearing first in the list does not make an entry a suitable target for the next follow-up.

curl --silent --show-error --get \
--header "X-Agent-Service-Token: ${AGENT_SERVICE_TOKEN}" \
--data-urlencode "agentId=${AGENT_ID}" \
--data-urlencode 'limit=20' --data-urlencode 'offset=0' \
"${BASE_URL}/api/sessions"
{
"sessions": [
{
"runId": "run-example",
"agentId": "your-agent-id",
"status": "idle",
"messageCount": 1,
"createdAt": "2026-10-15T08:00:00Z",
"updatedAt": "2026-10-15T08:00:00Z",
"preview": "Please review the release notes"
}
],
"total": 1,
"hasMore": false
}

Entries may also contain forkedFrom, conversationId, title, titleSource, origin, background, and archivedAt. Historical display values for status are idle, completed, failed, or handed_off; they do not replace live execution state or evidence that a particular request succeeded.

When hasMore is true, request the next page with offset + limit. This endpoint and the per-Run messages endpoint do not declare a fixed maximum page size; use small pages. Both accept legacy integer parsing, but always send the integer forms above rather than relying on conversions of invalid values.

Read a session snapshot​

GET /api/sessions/:runId​

Use a runId containing letters, digits, hyphens, or underscores. Success returns the snapshot directly, without a data or session wrapper. The snapshot includes the entire persisted message array; prefer the paginated endpoint in the next section for long sessions.

curl --silent --show-error \
--header "X-Agent-Service-Token: ${AGENT_SERVICE_TOKEN}" \
"${BASE_URL}/api/sessions/${RUN_ID}"
{
"runId": "run-example",
"agentId": "your-agent-id",
"userId": "your-instance-user-id",
"engine": "desirecore-engine",
"messages": [
{
"id": "d8d53a7a-478e-4d96-970e-657dece814f7",
"role": "user",
"content": "Please review the release notes",
"timestamp": 1792051200000
}
],
"options": {},
"status": "idle",
"createdAt": "2026-10-15T08:00:00Z",
"updatedAt": "2026-10-15T08:00:00Z"
}

A snapshot can also contain conversationId, forkedFrom, team or working-directory information, and an available runtimeSession reference. If present, pendingAssistant is an unfinished output checkpoint separate from messages; do not append it as a saved message. The response removes private runtime replay fields and may restore image references to data URLs, which can make it large.

A delegated child Run returns 403 delegated_run_requires_inspect_view from this snapshot endpoint. Adding a view parameter does not turn it into a delegated inspection endpoint. Use the per-Run messages inspection view below.

Read per-Run messages in pages​

GET /api/sessions/:runId/messages​

Query parameterMeaning
offsetDefault 0; a source-record row position, not a byte offset
limitDefault 100; the source-record window to read; use a positive integer
viewOptional for regular sessions; delegated child Runs require inspect-run explicitly
curl --silent --show-error --get \
--header "X-Agent-Service-Token: ${AGENT_SERVICE_TOKEN}" \
--data-urlencode 'offset=0' --data-urlencode 'limit=100' \
"${BASE_URL}/api/sessions/${RUN_ID}/messages"
{
"messages": [
{
"id": "d8d53a7a-478e-4d96-970e-657dece814f7",
"role": "user",
"content": "Please review the release notes",
"timestamp": 1792051200000,
"lineIndex": 0,
"offset": 0
}
],
"total": 1
}

There is no hasMore. Start the next page at the current request's offset + limit and stop when that reaches the response's total. The total counts source-record rows. Blank or malformed records can be skipped, and tool records can be deduplicated for display, so messages.length may be smaller than the window or even zero. Do not advance by the returned length or stop early because a page is empty.

Within a message, lineIndex is the row number in the Run and offset is a byte position. Both support navigation; prefer id for stable message identity. content can be a string or an array of content blocks, not always plain text. Images, media, and externally stored tool results may retain references or previews; this endpoint does not guarantee complete attachment bytes or tool-result text. For file reads, see Attachments and Media.

Delegated inspection view​

For a known delegated Run that you are authorized to read, use the same address with view=inspect-run. This does not relax user ownership checks or add the Run to the regular session list.

While execution is in progress and output has not been persisted, the response may also contain live:

{
"messages": [],
"total": 0,
"live": {
"turnId": "turn-example",
"text": "Working on the delegated task",
"toolCalls": [],
"timestamp": 1792051200000
}
}

live is a replaceable temporary display snapshot. It may roll back or disappear after a terminal event or persistence of the final message. It is excluded from total and is not a persisted message, receipt, or success signal. It contains displayable output text and a limited set of tool states; do not use it to reconstruct tool inputs or execution. text is limited to 16,384 characters and toolCalls to 128 entries.

Read merged history​

GET /api/sessions/messages/all​

Use this endpoint to display the continuous visible timeline of an Agent or one conversation. It filters by trusted user ownership before selecting visible fork branches, merging source messages, applying the public projection, and paging. Its offsets differ from per-Run source-row paging. all does not mean every execution branch or a complete backup.

Query parameterMeaning
agentIdRequired target Agent ID
conversationIdOptional exact conversation lineage within that Agent, such as an existing __manual:… conversation ID; grants no access to other conversations
preferredRunIdOptional visible history branch window; neither an exact-Run filter nor an access credential
orderdesc by default (newest first), or asc; other values fall back to desc
limitDefault 100, range 0–1000; 0 returns empty items, the total, and revision with hasMore: false, rather than all results
offsetDefault 0; a nonnegative safe integer position in the complete merged view
expectedRevisionSend the first page's historyRevision on later pages: h1: followed by 64 lowercase hexadecimal characters

Send canonical decimal integers for limit and offset. The service accepts legacy integer-prefix parsing; do not depend on conversions of mixed strings or fractions. The largest safe integer is 9007199254740991.

Without conversationId, an Agent currently in manual mode excludes separate manual conversations. Once manual mode is disabled, existing manual conversations join the default timeline again. An explicit conversationId selects only that conversation. Cleared and archived records, delegated child Runs, and dedicated schedule and Webhook execution timelines are excluded. Mention execution timelines remain separate, but visible Conversation source messages can appear. No visible history returns an empty page; it neither establishes that an Agent is missing nor reveals other users' records.

curl --silent --show-error --get \
--header "X-Agent-Service-Token: ${AGENT_SERVICE_TOKEN}" \
--data-urlencode "agentId=${AGENT_ID}" \
--data-urlencode 'order=asc' --data-urlencode 'limit=100' \
--data-urlencode 'offset=0' \
"${BASE_URL}/api/sessions/messages/all"
{
"items": [
{
"runId": "run-example",
"messageIndex": 0,
"offset": 0,
"sessionTime": "2026-10-15T08:00:00Z",
"message": {
"id": "d8d53a7a-478e-4d96-970e-657dece814f7",
"role": "user",
"content": "Please review the release notes",
"timestamp": 1792051200000
}
}
],
"total": 1,
"hasMore": false,
"historyRevision": "h1:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
}

Each items entry wraps runId, messageIndex, sessionTime, and a public message. Persisted Run messages may also carry a byte offset. Positions inside entries are not next-page parameters: advance by the request's offset + limit, using hasMore to decide whether to continue. total counts merged public entries, rather than the sum of each Run's source rows.

Mention source entries may carry message.mentionSourceOnly: true and a synthetic outer runId beginning with __mention_source:. They have no actual Run ownership and may have no byte offset. Preserve Mention references for display. Do not send synthetic IDs to Run, follow-up, or recovery APIs, or add source entries to model replay history. Prefer message.id for linking messages; do not deduplicate all Runs solely by text.

Keep one public view revision​

  1. Begin at offset=0 and save the first page's historyRevision.
  2. Keep the same agentId, conversationId, preferredRunId, order, and page size on later pages, sending expectedRevision.
  3. Buffer the current attempt until all pages finish. On 409 history_revision_changed, discard every buffered page and start again at offset=0 for a new revision. Never concatenate pages from different revisions.
  4. Retry reads only. History changes, withheld results, and read failures must not trigger conversation submissions, tool reruns, or recovery execution.
# HISTORY_REVISION is the first response's complete historyRevision; retain all filters.
curl --silent --show-error --get \
--header "X-Agent-Service-Token: ${AGENT_SERVICE_TOKEN}" \
--data-urlencode "agentId=${AGENT_ID}" \
--data-urlencode 'order=asc' --data-urlencode 'limit=100' \
--data-urlencode 'offset=100' \
--data-urlencode "expectedRevision=${HISTORY_REVISION}" \
"${BASE_URL}/api/sessions/messages/all"

Content edits, deletions, branch changes, or public projection changes can invalidate the revision. historyRevision hashes the current complete public view; it is not a persistent cursor, transaction snapshot, or incremental log. Later reads must confirm the revision again. Each page may read and sort all visible history, so bound page counts and avoid unbounded concurrent scans of large histories.

Search an Agent's messages​

GET /api/sessions/messages/search​

Query parameterMeaning
agentIdRequired target Agent ID
qOptional case-insensitive text substring; omit it to filter only by content type
typeall, image, file, or tool; omitted or other values are treated as all
limitDefault 50; a nonnegative safe integer. 0 returns all remaining matches from offset, with hasMore: false; always paginate large histories
offsetDefault 0; a nonnegative safe integer whose sum with limit must also be a safe integer
preferredRunIdOptional selection of a historical branch window for the default conversation; neither an access credential nor a filter restricting results to that Run alone
previewCharsOptional integer from 1 to 8000; matching uses the original text before clipping the display preview. Omit it to retain the full extracted text

The largest safe integer is 9007199254740991. Text matches are returned by message timestamp, newest first. Ordinary text in content blocks participates in matching; this is not a general full-text index of attachment contents or tool results. The image flag follows the message's media/image fields and does not establish that every attachment is an image.

Search includes the user's separate conversations created in manual mode, but excludes archived sessions and delegated child Runs by default. For a default conversation's fork family, it selects a visible branch to avoid duplicate matches. preferredRunId bounds that historical window without excluding separate manual conversations. If no valid matching branch is available, this parameter does not grant access to other Runs.

curl --silent --show-error --get \
--header "X-Agent-Service-Token: ${AGENT_SERVICE_TOKEN}" \
--data-urlencode "agentId=${AGENT_ID}" --data-urlencode 'q=release' \
--data-urlencode 'limit=50' --data-urlencode 'offset=0' \
--data-urlencode 'previewChars=240' \
"${BASE_URL}/api/sessions/messages/search"
{
"items": [
{
"runId": "run-example",
"messageIndex": 0,
"offset": 0,
"messageId": "d8d53a7a-478e-4d96-970e-657dece814f7",
"role": "user",
"text": "Please review the release notes",
"timestamp": 1792051200000,
"hasImages": false,
"hasFiles": false,
"hasToolUse": false
}
],
"total": 1,
"hasMore": false
}

Matches may also contain toolNames and conversationId. Correlate messages with runId and messageId. messageIndex is the source row number, while a hit's offset is a byte position, not the query parameter for the next page. Search pagination instead advances the request's offset + limit and reads hasMore.

Read the conversation topic overview​

GET /api/conversation/:agentId/overview​

There are no query parameters or pagination. The response includes active topics, up to 10 recent topics, and total topic and archived-topic counts. It is a conversation-memory overview, not a replacement for the session list or all original messages.

{
"agentId": "your-agent-id",
"activeMatters": [{ "id": "mat_example", "title": "Release review", "type": "task" }],
"recentMatters": [],
"totalMatters": 1,
"totalArchived": 0
}

Active entries contain id, title, and type; recent entries can also include completedAt and summary. When no conversation memory is available, the response may contain empty arrays and zero counts. This does not mean the Agent has no historical messages or establish that the Agent ID exists.

Read a topic's original messages​

GET /api/conversation/:agentId/matters/:id/full​

Use a topic ID from the overview; there are no pagination parameters. The source can be an active, recent, or archived topic. Success returns { "matterId": "…", "messages": [...] }, with public entries from the topic source. Do not assume every item has the same shape as a per-Run message.

Each request reads at most 120 source messages. A longer source also returns "truncated": true. The public projection may omit internal entries, so the returned length is not the source total. There is no parameter to raise the limit or continue to another page. For complete per-Run history, use the actual authorized Run ID and the messages pagination endpoint.

{
"matterId": "mat_example",
"messages": [{ "role": "user", "content": "Please review the release notes", "timestamp": 1792051200000 }],
"truncated": true
}

Archived topics​

GET /api/manual-topics/archived​

Read archived manual topics across the current user's local Agents, without message bodies or local paths. Use the existing owner token; callers cannot claim a user identity. There is no Agent filter.

Query parameterRule
limitDefault 50, safe integer 1..200
offsetDefault 0, nonnegative safe integer

The service converts with Number and then checks safe integers. Prefer decimal integers. Zero limit, negative offset, fractions and nonnumeric values return 400 {"error":"Invalid pagination"}.

{
"items":[{"agentId":"agent-example","conversationId":"__manual:example","title":null,"archivedAt":"2026-10-29T00:00:00.000Z"}],
"total":1,"hasMore":false
}

Items contain agentId, conversationId, nullable title, archivedAt and optional projectId/projectName. User-assigned titles take priority over recent titled Runs. An unavailable project name does not discard its ID. Ordering is descending archive time, with Agent/topic IDs as tie-breakers.

Each request derives current visible data. Importing, corrupt or unreadable sources may be omitted; total is not a lossless backup count. Continue with the original offset + limit while hasMore is true. There is no revision, and archive/restore activity may change the list. Refresh from the first page for a current display. This read neither restores a topic nor starts a conversation.

node history.mjs archived-topics --limit 50 --all-pages

The example never restores topics and stops paging when the observed total changes. Missing trusted user identity returns 401.

Session recovery reference​

GET /api/sessions/:runId/runtime-state​

Read the persistent session identity/version of an authorized Run. Responses use Cache-Control: private, no-store. This differs from Run runtime state: it does not report live running/idle outcomes, call a model or resend old input.

{"runId":"run-example","teamId":null,"runtimeSession":null}

teamId: null explicitly means personal scope. An omitted field on an older instance means unknown ownership; do not default it to personal. runtimeSession: null means no currently restorable in-place state, including archived, cleared or delegated records. It is not successful completion. A reference can look like:

{
"runId":"run-example","teamId":null,
"runtimeSession":{"sessionId":"saved-session","revision":1,"scopeEpoch":0,"scopeSequence":3}
}

The reference can also contain boundModel. These fields describe identity/version, not an execution grant or guaranteed future admission. Continue using admission reconciliation.

Missing/foreign Runs return 404. Local recovery failures after ownership verification return 500, code: "SESSION_RESTORE_FAILED", a safe error and optional hint. Do not turn that failure into runtimeSession: null. Keep the diagnostic ID and ask the administrator to inspect history storage; do not delete history, switch Runs or replay old input automatically.

node history.mjs runtime-reference run-example

Tool results and read consistency​

These endpoints return message views for display and search. Some tool results contain credentials, interface content, or other sensitive information; history, session snapshots, and topic messages replace that content with a placeholder. Protocol records may also withhold result bodies when the tool-call identity cannot be verified or contains conflicting facts.

For ordinary results allowed in the public view, toolUse items may also include modelOutput/modelOutputRefs: structured result text or references intended for the model. They need not match the UI summary. Read the fields actually returned; do not fetch replacement bodies when they are absent.

  • toolUse[].summary or a tool-result content block may be replaced. Summaries for running or interrupted tools may also be absent. Do not depend on the exact placeholder wording.
  • For withheld results, body references or preview markers such as modelOutput, modelOutputRefs, summaryRef, summaryIncomplete, and externalizedPreview may be removed. An absent reference does not mean the tool never ran, and does not permit constructing a filename to obtain its body.
  • Preserve and read the actual status, isError, and other outcome fields. A placeholder for a failed result still represents failure; the word completed in a summary does not establish completion of the submitted turn or the business task.
  • If sensitive output is needed, have the user obtain it through the original tool or application. A placeholder is not a reason to rerun tools, resubmit a conversation, or approve an action automatically.

The same historical record may produce different display content over time because of privacy rules, display deduplication, or concurrent writes. Message IDs and source-row windows locate records; they do not guarantee byte-identical bodies. These reads are not a full backup or model-protocol replay. The pagination rules and request-terminal rules above continue to apply independently.

Runnable read example​

Download history.mjs. It requires Node.js 22 or later, with no npm dependencies to install.

export DESIRECORE_URL='https://your-instance.example'
export DESIRECORE_TOKEN='your-existing-owner-token'
export DESIRECORE_AGENT_ID='your-agent-id'

node history.mjs list --limit 20 --all-pages
node history.mjs session run-example
node history.mjs messages run-example --limit 100 --all-pages
node history.mjs messages delegated-run-id --inspect-run
node history.mjs all --order asc --limit 100 --all-pages
node history.mjs all --conversation-id '__manual:existing-conversation' --limit 0
node history.mjs search --query 'release' --preview-chars 240 --all-pages
node history.mjs overview
node history.mjs matter mat_example

The example checks the instance handshake before issuing GET requests. It does not submit queries, send follow-ups, or cancel Runs. Each command reads one page by default. --all-pages reads up to 20 pages per attempt, adjustable with --max-pages. Output is newline-delimited JSON containing history content; store it as private data.

list accepts --include-archived. search also supports --type, --preferred-run-id, and --preview-chars. The messages inspection view requires the explicit --inspect-run option. all supports --conversation-id, --order, and --preferred-run-id; for a later single page, pair --offset with --expected-revision.

Exit code 0 means the requested reads succeeded; 1 indicates a configuration or HTTP failure. Code 2 means pagination reached its configured limit, stopped after observing a changed total or repeated revision conflicts, or received a truncated topic response. A stop record's nextOffset provides the next read position, accompanied by historyRevision for all. A revision-conflict stop provides restartOffset: 0; do not resume at an old offset.

all --all-pages buffers the current attempt and discards it on a revision conflict before restarting at the first page. It restarts at most once by default (--max-restarts changes this), with --max-pages applying to each attempt. Success emits pages from one revision. Reaching the page bound emits a revision-tagged partial window and exits 2. all --limit 0 makes only one metadata read.

The other paginated endpoints provide no revision ensuring consistency across pages. Appending, editing, or clearing history during a scan can produce duplicates or omissions. The example stops if total changes, but cannot detect content changes that leave the total unchanged. Do not treat a paginated scan as an audit snapshot from a fixed point in time.

Common errors​

HTTP / errorAction
400 agentId is requiredProvide an actual Agent ID for merged history or search
400 invalid_history_pageFor merged history, use limit from 0 to 1000, a nonnegative safe integer offset, and the complete expectedRevision format
409 history_revision_changedDiscard every page from the attempt and restart at the first page; do not rerun execution
400 Invalid history page parametersUse nonnegative safe integers for search limit and offset, and check the previewChars range
400 Invalid runIdUse a Run ID returned by the session list, not a path or runtime session ID
401Check the instance token; for User not authenticated or User not found, ask the administrator to check the instance's current user profile
403 delegated_run_requires_inspect_viewUse /messages?view=inspect-run for an authorized delegated Run, rather than the full snapshot endpoint
404 Session not found, or the same error with a Run IDThe record is missing, cleared, unreadable, or owned by another user; do not switch identities or guess other IDs to retry
404 Matter messages not found: …The topic or readable source messages are unavailable; select again from the current overview. An empty archived source may also return no messages

For authentication, service readiness, origin restrictions, and HTML responses from a proxy, see Errors and Troubleshooting.