GetAgentSessionEvents
Subscribes to real-time Server-Sent Events (SSE) for a specified agent session independently and supports resumption with a remote cursor. This API operation is available only when the canary release feature is enabled. Before calling this operation, verify that the canary release feature is enabled for your current account and the target region.
Operation description
This API operation is available only when the canary release feature is enabled. Before calling this operation, verify that the canary release feature is enabled for your current account and the target region.
This API operation provides a read-only SSE subscription and does not submit prompts. Use the GET method and maintain streaming reads. Do not read the response as a single JSON object. When making HTTP requests directly, use V3 signature (ACS3-HMAC-SHA256). For long-running tasks that may exceed a single request timeout, establish an independent event subscription before sending PromptAgentSession. After creating a session, populate SessionCode with the SessionId and read both streams in parallel. The Events stream displays real-time progress, while the SSE built into the Prompt stream is used to read the final state and business errors of the current turn.
Events display messages, tool calls, and execution progress. The establishment of a subscription connection, heartbeats, or an HTTP 200 status code does not indicate task completion. Determine whether the task is complete based on actual terminal state events and the result of the Prompt call.
When resuming after a disconnection, pass the ID of the last consumed remote event as Last-Event-Id. Also, save and pass back the EventEpoch of the same event stream if the server has returned it. Omit these two parameters during the initial subscription when no cursor is available, to receive only real-time events after the subscription is established. Explicitly setting Last-Event-Id=0 attempts to replay from the starting point still in the cache, which does not guarantee retrieval of the complete history. Retrieve the complete history by using LoadAgentSession. Do not generate cursors or epochs yourself, or use local message sequence numbers as replacements.
The event cache is bounded. If you receive a resynchronization prompt such as state_resync_required or the cursor becomes unavailable, restore the history by using LoadAgentSession and then re-establish the subscription. Load is used for refreshing and exception recovery. Do not call it repeatedly as a substitute for real-time event subscriptions. If the Prompt times out or the stream disconnects before the business final state is received, the result of the current turn is unknown. You can continue to monitor the progress through Events. Avoid automatically resending the Prompt. Closing the Events subscription does not trigger CancelAgentSession.
Servers that support epoch information return eventEpoch in the data of the stream_open control frame and provide a mapping between the business sessionId and the nativeSessionId. Save the identifiers returned by the server. Do not assume that the business session ID is the same as the native session ID. The cursor and eventEpoch must come from the same event stream epoch of the same native session. Do not reuse them across native sessions or epochs. Do not advance the cursor when a control frame does not have an ID.
Try it now
Test
RAM authorization
|
Action |
Access level |
Resource type |
Condition key |
Dependent action |
|
dataworks:GetAgentSessionEvents |
none |
*All Resource
|
None | None |
Request syntax
GET HTTP/1.1
Request parameters
|
Parameter |
Type |
Required |
Description |
Example |
| SessionCode |
string |
Yes |
The ID of the target agent session. The value is the SessionId returned by CreateAgentSession. The parameter name for this API operation is SessionCode. |
session_example |
| Last-Event-Id |
string |
No |
The cursor of the last consumed remote SSE event, passed through an HTTP request header. Use the original value as a pure decimal non-negative safe integer (up to 9007199254740991). If omitted, only real-time events are subscribed to. Explicitly setting it to 0 attempts to replay from the starting point of the unevicted cache, which does not represent the complete history. Do not use local message sequence numbers. |
42 |
| EventEpoch |
string |
No |
The event stream epoch identifier, obtained from data.eventEpoch in the stream_open control frame of the server. Pass the original value only when a Last-Event-Id of the same native session and the same epoch is available. Omit it during the initial subscription or when the epoch is not obtained. Do not construct it yourself or reuse it across native sessions. |
epoch_example |
Response elements
|
Element |
Type |
Description |
Example |
|
object |
The OpenAPI mapping structure of a single SSE frame. The response is a continuous event stream. Parse it frame by frame. Do not treat the entire response as a single JSON object. |
||
| Data |
any |
The event data of the current frame. The content varies with the Event type and must be parsed according to the event type. Preserve the original session, turn, and tool call identifiers. |
{} |
| Event |
string |
The SSE event type, such as session_update. Process control frames and business frames separately. |
session_update |
| Id |
string |
The remote SSE event cursor. Save it after consumption for subsequent resumption using Last-Event-Id. Some control frames may not have a cursor. Do not generate a local cursor for them. |
42 |
| RequestId |
string |
The request ID of the current OpenAPI subscription request, used to troubleshoot subscription failures. It is not an event cursor or a human-computer interaction prompt ID. |
01A0B6E0-E005-1465-B5DE-5CD17677426F |
Examples
Success response
JSON format
{
"Data": "{}",
"Event": "session_update",
"Id": "42",
"RequestId": "01A0B6E0-E005-1465-B5DE-5CD17677426F"
}
Error codes
See Error Codes for a complete list.
Release notes
See Release Notes for a complete list.