Skip to main content

Quick Start

Create an agent, configure its environment, initiate a session, and make calls—all in four steps via the console.

Prerequisites

  • You have activated Alibaba Cloud Bailian.
  • Your current account has Managed Agents operation permissions in the target workspace.
The first conversation below does not require an uploaded file or an SDK. For file analysis and programmatic calls, use the optional API extensions after completing the console path.

Step 1: Configure the Agent

Navigate to Bailian Console > Managed Agents > Quick Start, and fill in the agent's basic information, model, and tools. The page is pre-filled with template values—you may modify them as needed.
FieldDescription
NameDefault: Agent_v1; customizable
ModelRequired. Select from the dropdown list (e.g., qwen3.7-plus)
System PromptDefines the agent's role and behavior. A generic template is pre-filled; customize it per your use case
ToolsBuilt-in tools are selected by default: bash, write, read, edit, glob, grep, web_search, web_fetch, todo_write, mark_artifacts. Deselect as needed
Skill / MCPOptional. Skip during Quick Start; add later on the agent detail page
After completing the form, click Finish & Next. The system creates and saves the agent, then proceeds to environment configuration.

Step 2: Configure the Runtime Environment

The environment defines the execution sandbox for tool calls and is managed independently from the agent.
FieldDescription
NameDefault: Agent_v1_Env; customizable
Hosting TypeDefault: Cloud-hosted (sandbox container managed by Bailian)
Click Finish & Next. The system creates and saves the environment, then proceeds to session configuration.

Step 3: Confirm Session Configuration

The page displays summaries of the created agent and environment and automatically initiates a session based on both.
  • Verify the Agent card: name and model information.
  • Verify the Environment card: name and hosting type.
  • To use local files inside the sandbox, click Upload Files to mount them; otherwise, skip. No file is needed for the first conversation in Step 4.
Click Finish & Next. The system binds the agent and environment, creates and saves the session, then proceeds to the invocation page.

Step 4: Begin Invocation

Configuration is complete. The page provides two tabs:
  • Callable API: Displays the curl command to create an event—copy and run it directly in your terminal.
  • Preview & Debug: Chat directly with the agent in-browser and view real-time events and tool invocations. Use the dropdown in the top-left corner to filter by event type (User, Agent, Tool, Tool_output, Error, Model, System).
Open Preview & Debug, enter Briefly introduce what you can do., and send it. View the agent's response and execution events. For programmatic calls, establish the SSE subscription before sending; the optional extension below shows the sequence.
The first conversation succeeds when you see the response and the turn ends normally (idle with stop_reason.type=end_turn). requires_action means waiting for tool approval, not success; retries_exhausted means the turn failed. A newly created idle Session with a null stop reason is not a completed turn. A terminated Session cannot continue.
After debugging, click Return to Agent List to enter the management page. The agent, environment, and session created in the first three steps are all saved—you can view and edit them anytime from their respective menus. Reuse the same Session for subsequent turns; idle does not mean deletion.

Optional: API extensions

These examples retain the data-analysis configuration as an alternative to the console path. Choose curl, Python, or Java and execute sections 1–4 in three stages in the same workspace. Do not mix IDs from different variants. To call resources already created in the console, use their actual IDs instead of creating duplicates.

Initialization context

First follow API Quickstart to obtain an API Key and workspace ID and set DASHSCOPE_API_KEY and AGENTSTUDIO_URL. The original endpoint shape is https://{workspace_id}.cn-beijing.maas.aliyuncs.com/api/v1/agentstudio; replace {workspace_id} with your actual workspace ID. Curl requires jq; the examples use Python SDK 1.27.7 or Java SDK 2.23.2 (JDK 9+ for Map.of), with installation instructions in API Quickstart. Assemble the matching language snippets by stage, rather than putting sections 1–4 into one uninterrupted program:
  1. Prepare resources: run the shared initialization and sections 1–2. Save the actual printed AGENT_ID and ENV_ID, and wait for documented Environment warm-up to finish.
  2. Create the Session: rerun the shared imports and client initialization with section 3 only. Bind existing resources using environment variables AGENT_ID and ENV_ID, and save the actual printed SESSION_ID.
  3. Mount and invoke: first upload and mount sales.csv in that SESSION_ID as described in section 4. Rerun the shared initialization with only section 4's subscription/submission snippets, reading the same SESSION_ID from the environment. Do not recreate resources.
For Python, replace pass with only the current stage's snippets, indented by four spaces. The official Client context closes the HTTP client on exit; a new process does not retain the previous agent, env, or session objects. For Java, save ManagedAgentQuickstart.java from the API example alongside ManagedAgentConsoleQuickstart.java below. For each stage, insert only its Java snippets at the comment in main and run only the console extension class, not the API class's resource-creation entry point. Stage 3 reuses public runTurn for header-confirmed submission, SSE reception, text output, stop-reason handling, and subscription closure. It retains the 120000 ms business-event wait checks that heartbeats cannot reset, plus a separate socket-inactivity bound. Blocking line reads do not guarantee an exact 120-second wall-clock cutoff; complete heartbeat lines trigger expiry checks and eventually stop. See the API example for the distinction.
set -euo pipefail
# Use the API Quickstart environment variables in this terminal.
# Endpoint templates: replace workspace_id and reuse the returned Session ID.
# POST https://{workspace_id}.cn-beijing.maas.aliyuncs.com/api/v1/agentstudio/agents
# POST https://{workspace_id}.cn-beijing.maas.aliyuncs.com/api/v1/agentstudio/environments
# POST https://{workspace_id}.cn-beijing.maas.aliyuncs.com/api/v1/agentstudio/sessions
# GET  https://{workspace_id}.cn-beijing.maas.aliyuncs.com/api/v1/agentstudio/sessions/sesn_xxx/events/stream
# POST https://{workspace_id}.cn-beijing.maas.aliyuncs.com/api/v1/agentstudio/sessions/sesn_xxx/events

1. Configure the Agent via API

Specify name, model, and tools (see Create Agent). Unlike the console template, this data-analysis example uses data-analyst and qwen3.8-max.
AGENT_ID=$(curl -fsS -X POST "$AGENTSTUDIO_URL/agents" \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "data-analyst",
    "model": {"id": "qwen3.8-max"},
    "system": "You are a data analysis expert who uses pandas to process CSV files.",
    "tools": [
      {
        "type": "builtin_toolkit",
        "default_config": {"enabled": true},
        "configs": [
          {"name": "bash", "enabled": true},
          {"name": "read", "enabled": true},
          {"name": "write", "enabled": true}
        ]
      }
    ]
  }' | jq -er '.id')
printf 'Agent: %s\n' "$AGENT_ID"

2. Configure the Runtime Environment via API

Specify sandbox type and pre-installed packages (see Create an environment). This example installs apt: ffmpeg and pip: pandas, numpy, matplotlib, and sets networking.type=unrestricted.
ENV_ID=$(curl -fsS -X POST "$AGENTSTUDIO_URL/environments" \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "data-sandbox",
    "description": "Data analysis sandbox",
    "config": {
      "type": "cloud",
      "packages": {
        "apt": ["ffmpeg"],
        "pip": ["pandas", "numpy", "matplotlib"]
      },
      "networking": {"type": "unrestricted"}
    }
  }' | jq -er '.id')
printf 'Environment: %s\n' "$ENV_ID"
The API example configures pre-installed packages: warm-up may take several minutes or longer. Session creation in section 3 is rejected until warm-up completes, with invalid_parameter: The environment is still being prepared. Please wait until it is ready and try again. Wait for preparation to complete before continuing; see Environment warm-up.The snippets do not wait automatically. Stage 1 (sections 1–2) saves the printed Agent and Environment IDs. After warm-up, stage 2 (section 3 only) creates the Session and saves its ID. Upload and mount the file before stage 3 (section 4) invokes the task. If Session creation is rejected, retry that operation after preparation completes without creating another Agent or Environment.

3. Confirm Session Configuration via API

Bind the Agent and Environment IDs returned above (see Create Session). Placeholder IDs agent_xxx, env_xxx, and sesn_xxx represent the actual returned IDs, not interchangeable fixed values. Before starting stage 2 in Python or Java, export the saved IDs in the launching terminal: replace the placeholders below with the actual values printed in stage 1, then rerun the shared imports and client initialization. A new terminal also needs the same API Key and Endpoint. For curl in the original terminal, keep its existing AGENT_ID and ENV_ID; do not overwrite them with placeholders.
# Replace with the actual IDs printed in stage 1 before running.
export AGENT_ID="agent_xxx"
export ENV_ID="env_xxx"
SESSION_ID=$(curl -fsS -X POST "$AGENTSTUDIO_URL/sessions" \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"agent\": {\"type\": \"agent\", \"id\": \"$AGENT_ID\"}, \"environment_id\": \"$ENV_ID\", \"title\": \"Q3 Sales Data Analysis\"}" | jq -er '.id')
export SESSION_ID
printf 'Session: %s\n' "$SESSION_ID"

4. Begin Invocation via API: optional file analysis

Before starting stage 3 in Python or Java, export the actual Session ID printed in stage 2 (without the following status) in the launching terminal, then rerun the shared imports and client initialization. Keep the same API Key and Endpoint. For curl in the original terminal, keep the variable already exported in section 3.
# Replace the placeholder with the actual Session ID printed in stage 2.
export SESSION_ID="sesn_xxx"
Before sending the analysis task, upload sales.csv, wait for its review status to become available, and mount it in this Session. Specify /sales.csv as the mount path: the service adds the /mnt/session/uploads prefix, so the agent accesses /mnt/session/uploads/sales.csv. Use Upload Files in the console or the procedures in File upload and mounting. Creating the Session above does not upload or mount a local file. Keep this Session ID when adding the file. Subscribe to the SSE event stream first, then send an Event. SSE does not replay history; for disconnects, see Client streaming and recovery. For curl, execute the subscription below in terminal A. In this new terminal, export the same API Key and Endpoint and copy the actual SESSION_ID printed in section 3. Keep it running and confirm a 2xx response with Content-Type: text/event-stream before submitting from terminal B. Do not use a fixed delay as a readiness check.
export SESSION_ID="sesn_xxx"
curl -N -i "$AGENTSTUDIO_URL/sessions/$SESSION_ID/events/stream" \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
  -H "Accept: text/event-stream"
Use the same SESSION_ID in terminal B. Python and Java snippets below combine subscription and submission in the initialization context rerun for stage 3. They read the Session ID from the environment, without relying on stage 2's session object. Python 1.27.7 opens HTTP before stream() returns. Java's runTurn checks HTTP status/content type and opens the input stream before SDK submission; merely calling AgentStudioEventStream.stream() would not guarantee readiness.
curl -fsS -X POST "$AGENTSTUDIO_URL/sessions/$SESSION_ID/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"}
        ]
      }
    ]
  }'
Expect the Q3 sales analysis and a normal end_turn. A successful POST only queues the task. Keep receiving through running and ignore a newly created idle with null reason; distinguish normal completion, pending approval, retry exhaustion, and termination as in Step 4. A disconnect or timeout leaves the task outcome UNKNOWN, not successful: query Session state (Java client.sessions().retrieve(System.getenv("SESSION_ID"))) and history rather than resending automatically. Closing the subscription does not terminate the Session.

Resources and Session management

Keep the returned IDs and reuse the Session across turns after normal completion. For input files, see File upload and mounting; for output artifact retrieval, see Data analysis: retrieve artifacts. For approvals, interrupts, and termination, see Session operations. Session archive terminates the Session and retains history; Session deletion irreversibly removes metadata and history. Environment archive/delete is separate. Runtime charges apply while running, not while idle; see Billing. For production integration, see Overview and API Quickstart.