This guide shows you how to develop, upload, and deploy an API service for a full-code application from scratch by using AgentScope-AI.
Prerequisites
- You need a Python development environment with
python >= 3.10. - To upload and deploy your Python package to Alibaba Cloud Model Studio, install the AgentScope-AI dependencies:
Development specifications
- The Python backend application must provide a
GET /healthendpoint. If this endpoint is not reachable, Model Studio will consider the application startup failed.
- The entry file for the Python backend application must be
main.py. - The default path for the chat interface is
/process. For protocol details, see the Agent API Protocol Specification. - Reference code package: mcp_server_with_chat.zip.
Application observability
Use the @trace decorator provided by the AgentScope-runtime package to automatically report logs and collect timing metrics.
The following example shows a decorator for a function that calls a large language model:
- When uploading a pre-built
.whlpackage by usingAgentScope-AI, add the--telemetry enableflag to enable Application Observability.
Application upload
-
Obtain and configure the following environment variables. The example shows the Linux syntax:
- Obtain an Alibaba Cloud AccessKey (AK and SK) to authenticate package uploads.
- (Optional) Obtain an Alibaba Cloud Model Studio workspace ID. This ID, which starts with
llm-, specifies the workspace where the full-code application will be stored. If not set, the default workspace is used. - Set the following environment variables to the values you obtained:
-
Use
AgentScope-AIto upload the built.whlpackage. The package is then automatically deployed to Alibaba Cloud Model Studio.The
--telemetry enableflag enables observability and requires developing your application with the AgentScope Tracing module.
- Go to Alibaba Cloud Model Studio > Application Management and wait for the application to be published. After the application is published, you will incur minimal charges based on the deployment duration (less than 0.1 CNY/hour).
Application testing
We recommend that you go to Alibaba Cloud Model Studio > Application Management. On the application details page, you can test the application and view build, deployment, and invocation logs.
Application update
When you need to update a full-code application, use the AgentScope-AI update command to upload the new .whl package. After the package is successfully uploaded, the full-code application is automatically updated and redeployed.
- Go to Alibaba Cloud Model Studio > Application Management and copy the application ID.
-
Run the following command locally to upload the updated local
.whlpackage.After the update, the application is rebuilt and redeployed.
FAQ
Least privilege for RAM accounts
To grant a RAM account least privilege to use a full-code application, create a custom policy based on the following rules.
Troubleshooting upload failures
- Check that the Alibaba Cloud AK/SK and the Alibaba Cloud Model Studio workspace ID belong to the same Alibaba Cloud account.
- Ensure that you have deployed a full-code application at least once from the Model Studio console. This initial deployment guides you through enabling the necessary Alibaba Cloud permissions and resources.
-
Try using a clean
python >= 3.10environment. For example, create a clean virtual environment using thePythonvenvcommand:- Create the environment:
- Activate the environment:
-
If you encounter the error "RAM user is not assigned to any workspace in Bailian" during upload, ask the Alibaba Cloud account owner to do the following:
- You can use an Alibaba Cloud account to grant the AliyunBailianDataFullAccess permission to a sub-account (RAM user) in the RAM console.
- On the Model Studio Account Management page, grant the Agent-Operation permission to the RAM user for a specific workspace.
Deployment stuck or failed
- The
GET /healthendpoint of the Python backend application is unreachable. This causes Model Studio to determine that the startup has failed. - The entry file for the Python backend application must be
main.py. - Go to the application details page for your full-code application to view detailed runtime logs.
Preventing build failures from dependency updates
We recommend pinning dependency versions in your requirements.txt file by using == and avoiding range operators like >=. Using >= can cause each build to pull different dependency versions, which can lead to inconsistent application behavior or build failures.
Example:
pip freeze command to export the exact versions from your current environment: