Skip to main content
Sessions

Managing Sessions

After a session is created, its execution flow can be controlled via a state machine, tool call approvals, and interruption mechanisms—and archived or deleted upon task completion.

State Machine

The session status appears at the top of the page. The table below outlines the trigger conditions, next states, and available actions for each status:
StatusTrigger ConditionNext StatusAvailable Actions
idleSession creation completed, or one round of processing finishedOn receiving a message → running; On archiving or deletion → terminatedSend message, attach files, archive, delete
runningMessage received and agent begins processingOn completion → idle; On unrecoverable error → terminatedInterrupt, approve tool calls
terminatedArchived, deleted, or unrecoverable error occurredTerminal state—no further transitions possibleView event history; create a new session to continue
When a session returns to idle, the session_status event includes a stop_reason field indicating why:
  • end_turn: Model voluntarily ended the turn.
  • requires_action: Client-side intervention is required; event_ids are included to identify pending events.
  • retries_exhausted: All retry attempts have been exhausted.
While a session is running, you can mount, list, and unmount file resources dynamically via the API—see Mount Session Resource.

Tool Calls

The agent autonomously decides when and which tool to invoke based on system prompts and the current message. All tools—built-in, MCP, or skills—are executed within the runtime environment bound to the session, and their invocation process is visible in real time via the event panel.

Invocation Flow

  1. Agent Decision: The model outputs a tool call instruction. The event panel displays a Tool Call event containing the tool name and parameters.
  2. Execution: The tool runs inside a sandbox; its output is sent back to the model.
  3. Response or Continue: The model decides whether to reply or initiate another tool call, based on the tool’s output.

Archiving and Deletion

Sessions support two distinct operations: archiving and deletion.
  • Archiving: Changes the session status to terminated (a terminal state), while preserving the full event history for future reference. Recommended for completed sessions.
  • Deletion: Permanently removes all session metadata, event history, and internally copied resources—this action is irreversible. Use archiving instead if you need to retain event history.
To archive a session programmatically, see the Session API.
curl -X POST "https://{workspace_id}.cn-beijing.maas.aliyuncs.com/api/v1/agentstudio/sessions/sesn_xxx/archive" \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY"
To delete a session via API:
curl -X DELETE "https://{workspace_id}.cn-beijing.maas.aliyuncs.com/api/v1/agentstudio/sessions/sesn_xxx" \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY"

Next Steps

Managing Sessions - 阿里云百炼 Agent Studio