Session Event Stream (SSE)
All interactions within a session are recorded as events. When subscribing via API, events are pushed as an SSE (Server-Sent Events) stream.
Server-Pushed Events
While the agent processes a message, the server pushes events of the following types:
type | Description |
| Assistant output message, can be streamed in chunks (accumulated by |
| Built-in tool call request and execution result |
| MCP tool call request and execution result |
| Session state change, carries |
Client-Sent Events
Write events to a session via POST /sessions/{session_id}/events.
type | Description |
| Send a message, triggering the agent to enter |
Send a message event to trigger agent processing. For complete parameters, see Send Event.
curl -X POST "https://{workspace_id}.cn-beijing.maas.aliyuncs.com/api/v1/agentstudio/sessions/sesn_xxx/events" \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"input": [
{
"role": "user",
"type": "message",
"content": [
{"type": "text", "text": "Analyze Q3 sales trends in /mnt/session/uploads/sales.csv"}
]
}
]
}'client.sessions.events.send(
"sesn_xxx",
events=[user_message("Analyze Q3 sales trends in /mnt/session/uploads/sales.csv")],
)client.sessions().events().send("sesn_xxx",
Collections.singletonList(
ClientEvents.userMessage("Analyze Q3 sales trends in /mnt/session/uploads/sales.csv")));SSE Subscription
When sending a message event, set the request header Accept: text/event-stream to receive the response as an SSE stream that pushes all events in real time. Without this header, the response returns the complete event list (requiring polling for incremental updates). See Subscribe to Event SSE Stream for details.
curl -N "https://{workspace_id}.cn-beijing.maas.aliyuncs.com/api/v1/agentstudio/sessions/sesn_xxx/events/stream" \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Accept: text/event-stream"with client.sessions.events.stream("sesn_xxx", timeout=120.0) as stream:
for event in stream:
if event.type == "message":
for block in (event.content or []):
if getattr(block, "type", None) == "text":
print(block.text, end="", flush=True)
elif event.type == "session_status":
if event.session_status in ("idle", "terminated"):
breaktry (AgentStudioEventStream stream = client.sessions().events().stream("sesn_xxx", 120_000L)) {
for (Message event : stream) {
if ("message".equals(event.getType()) && event.getContent() != null) {
for (ContentBlock block : event.getContent()) {
if (block instanceof ContentBlock.Text)
System.out.print(((ContentBlock.Text) block).getText());
}
} else if ("session_status".equals(event.getType())) {
break;
}
}
}Event Filtering
The dropdown in the upper-left corner of the console event panel allows filtering events by type. Supported filters: All events, User, Agent, Tool, Tool_output, Error, Model, System.