Manage Sessions

Updated at:

After a session is created, you can control execution through the state machine, tool call approval, and interrupt mechanisms. Once tasks are complete, you can archive or delete the session.

State Machine

The session state is displayed at the top of the page. The following table shows the trigger condition, next state, and available actions for each state:

State

Trigger Condition

Next State

Available Actions

idle

Session created, or a processing round completed

Message received → running; archived or deleted → terminated

Send message, mount file, archive, delete

running

Message received, agent starts processing

Completed → idle; unrecoverable error → terminated

Interrupt, approve tool calls

terminated

Archived, deleted, or unrecoverable error

Terminal state, not recoverable

View event history; create a new session to continue

When the session returns to idle, the session_status event carries a stop_reason indicating the cause: end_turn means the model ended voluntarily; requires_action means client intervention is needed, with event_ids indicating which events require action; retries_exhausted means all retries have been exhausted.

Tool Calls

The agent autonomously decides when and which tools to call based on the system prompt and current messages. All tools (built-in, MCP, and skills) run in the execution environment bound to the session, and the call process is visible in real time through the event panel.

Call Flow

  1. Agent decision: The model outputs a tool call instruction, and the event panel displays a tool call event containing the tool name and parameters.

  2. Execution: The tool runs in the sandbox, and the output is returned to the model.

  3. Reply or continue: The model decides whether to reply or initiate another tool call based on the output.

Archive and Delete

Sessions support two operations: archive and delete.

  • Archive: The state changes to terminated (terminal state), and the event history is preserved for viewing. Suitable for completed sessions.

  • Delete: Hard delete. Session metadata, event history, and internally copied resources are all removed permanently. Use archive instead if you need to retain event history.

To archive a session via API, see Archive Session.

curl -X POST "https://{workspace_id}.cn-beijing.maas.aliyuncs.com/api/v1/agentstudio/sessions/sesn_xxx/archive" \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY"
client.sessions.archive("sesn_xxx")
client.sessions().archive("sesn_xxx");

To delete a session via API, see Delete Session.

curl -X DELETE "https://{workspace_id}.cn-beijing.maas.aliyuncs.com/api/v1/agentstudio/sessions/sesn_xxx" \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY"
client.sessions.delete("sesn_xxx")
client.sessions().delete("sesn_xxx");