Create an agent, configure its environment, initiate a session, and make calls—all in four steps via the console.
Console path
Prerequisites
- You have activated Alibaba Cloud Bailian.
- Your current account has Managed Agents operation permissions in the target workspace.
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.
| Field | Description |
|---|---|
| Name | Default: Agent_v1; customizable |
| Model | Required. Select from the dropdown list (e.g., qwen3.7-plus) |
| System Prompt | Defines the agent's role and behavior. A generic template is pre-filled; customize it per your use case |
| Tools | Built-in tools are selected by default: bash, write, read, edit, glob, grep, web_search, web_fetch, todo_write, mark_artifacts. Deselect as needed |
| Skill / MCP | Optional. Skip during Quick Start; add later on the agent detail page |
Step 2: Configure the Runtime Environment
The environment defines the execution sandbox for tool calls and is managed independently from the agent.
| Field | Description |
|---|---|
| Name | Default: Agent_v1_Env; customizable |
| Hosting Type | Default: Cloud-hosted (sandbox container managed by Bailian) |
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.
Step 4: Begin Invocation
Configuration is complete. The page provides two tabs:
- Callable API: Displays the
curlcommand 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).
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.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:
- Prepare resources: run the shared initialization and sections 1–2. Save the actual printed
AGENT_IDandENV_ID, and wait for documented Environment warm-up to finish. - Create the Session: rerun the shared imports and client initialization with section 3 only. Bind existing resources using environment variables
AGENT_IDandENV_ID, and save the actual printedSESSION_ID. - Mount and invoke: first upload and mount
sales.csvin thatSESSION_IDas described in section 4. Rerun the shared initialization with only section 4's subscription/submission snippets, reading the sameSESSION_IDfrom the environment. Do not recreate resources.
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.
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.
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.
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.
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.
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.
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.
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.