What is AgentScope Runtime?
AgentScope Runtime is a full-stack runtime for AI agents designed to solve two core challenges: efficient deployment & serving and secure sandboxed execution. In short:Key Features
Deployment Infrastructure
Built-in services for agent state management, conversation history, long-term memory, and sandbox lifecycle control.
Framework-Agnostic
Not tied to any specific framework — seamlessly integrates with popular open-source and custom implementations.
Developer-Friendly
AgentApp provides easy deployment with powerful customization options and multiple endpoint types.Full Observability
Comprehensive tracking and monitoring of runtime operations, logs, and traces.
Sandboxed Tool Execution
Isolated sandbox ensures safe tool execution without affecting the host system.
Out-of-the-Box Tools
Rich set of ready-to-use tools with adapters for quick integration into different frameworks.
Quick Start
Prerequisites
- Python 3.10 or higher
- pip or uv package manager
Installation
From PyPI:Agent App Example
This example demonstrates how to create an agent API server using agentscopeReActAgent and AgentApp. To run a minimal AgentScope Agent with AgentScope Runtime, you generally need to implement:
Define lifespan– Usecontextlib.asynccontextmanagerto manage resource initialization (e.g., state services) at startup and cleanup on exit.@agent_app.query(framework="agentscope")– Core logic for handling requests, must usestream_printing_messagestoyield msg, lastfor streaming output
agent_app.py
The above configuration is shared across all deployment methods below. Each method will show only the deployment-specific code.
Deployment
After grasping the concepts and completing the quickstart, deployment is the bridge that turns experimental prototypes into reliable services. Its significance is underpinned by three core pillars:- Connect to real workloads: Moving agents from notebooks or scripts into a continuously running environment is the only way to serve real users, tools, and data.
- Gain operational stability: Runtime offers standardized lifecycles, health checks, and scaling hooks that simplify monitoring and rollback.
- Reuse the ecosystem: A unified deployment approach lets you reuse memory, sandbox, state, and other foundational services instead of rebuilding them per project.
Overview of Deployment Methods
AgentScope Runtime offers multiple distinct deployment approaches, each tailored for specific use cases:Prerequisites
Installation Requirements
Install AgentScope Runtime with all deployment dependencies:Environment Setup
Configure your API keys and environment variables:Prerequisites by Deployment Type
For All Deployments
- Python 3.10+
- AgentScope Runtime installed
For Kubernetes Deployment
- Docker installed and configured
- Kubernetes cluster access
- kubectl configured
- Container registry access (for image pushing)
For ModelStudio Deployment
- Alibaba Cloud account with ModelStudio access
- DashScope API key for LLM services
- OSS (Object Storage Service) access
- ModelStudio workspace configured
Method 1: Local Daemon Deployment
Best for: Development, testing, and single-user scenarios where you need persistent service with manual control.Features
- Persistent service in main process
- Manual lifecycle management
- Interactive control and monitoring
- Direct resource sharing
Implementation
- Service runs in the main process (blocking)
- Manually stopped with Ctrl+C or by ending the script
- Best for development and testing
Testing the Deployed Service
Once deployed, you can test the endpoints using curl or Python: Using curl:Method 2: Detached Process Deployment
Best for: Production services requiring process isolation, automated management, and independent lifecycle.Features
- Independent process execution
- Automated lifecycle management
- Remote shutdown capabilities
- Service persistence after main script exit
Implementation
- Service runs in a separate detached process
- Script exits after deployment, service continues
- Remote shutdown via
/admin/shutdownendpoint
Method 3: Kubernetes Deployment
Best for: Enterprise production environments requiring scalability, high availability, and cloud-native orchestration.Features
- Container-based deployment
- Horizontal scaling support
- Cloud-native orchestration
- Resource management and limits
- Health checks and auto-recovery
Prerequisites for Kubernetes Deployment
Implementation
- Containerized deployment with auto-scaling support
- Resource limits and health checks configured
- Can be scaled with
kubectl scale deployment
Method 4: Serverless Deployment: ModelStudio
Best for: Alibaba Cloud users requiring managed cloud deployment with built-in monitoring, scaling, and integration with Alibaba Cloud ecosystem.Features
- Managed cloud deployment on Alibaba Cloud
- Integrated with DashScope LLM services
- Built-in monitoring and analytics
- Automatic scaling and resource management
- OSS integration for artifact storage
- Web console for deployment management
- Supports STS (Security Token Service) temporary credential authentication.
Prerequisites for ModelStudio Deployment
Implementation
- Fully managed cloud deployment on Alibaba Cloud
- Built-in monitoring and auto-scaling
- Integrated with DashScope LLM services
- Enhanced security with STS Token-based authentication support.
Method 5: Serverless Deployment: AgentRun
Best For: Alibaba Cloud users who need to deploy agents to AgentRun service with automated build, upload, and deployment workflows.Features
- Managed deployment on Alibaba Cloud AgentRun service
- Automatic project building and packaging
- OSS integration for artifact storage
- Complete lifecycle management
- Automatic runtime endpoint creation and management
AgentRun Deployment Prerequisites
Implementation
- Automatically builds and packages the project as a wheel file
- Uploads artifacts to OSS
- Creates and manages runtime in the AgentRun service
- Automatically creates public access endpoints
- Supports updating existing deployments (via
agentrun_idparameter)
Configuration
OSSConfig
OSS configuration for storing build artifacts:AgentRunConfig
AgentRun service configuration:Method 6: PAI Deployment (Platform for AI)
Best for: Enterprise users who need to deploy on Alibaba Cloud PAI platform, leveraging LangStudio for project management and EAS (Elastic Algorithm Service) for service deployment.Features
- Fully managed deployment on Alibaba Cloud PAI platform
- Integrated LangStudio project and snapshot management
- EAS (Elastic Algorithm Service) service deployment
- Three resource types: Public Resource Pool, Dedicated Resource Group, Quota
- VPC network configuration support
- RAM role and permission configuration
- Tracing support
- Automatic/manual approval workflow
- Auto-generated deployment tags
Prerequisites for PAI Deployment
PAI Workspace Requirements
- If using a RAM user account, PAI Developer Role must be assigned
- OSS bucket must be configured for storing build artifacts
- (Optional) VPC with public network access if using DashScope models
Implementation (SDK)
- Automatically packages project and uploads to OSS
- Creates LangStudio project and snapshot
- Deploys as EAS service
- Supports multiple resource type configurations
Implementation (CLI)
PAI deployment recommends using configuration files for clarity and maintainability: Method 1: Using Configuration File (Recommended)Configuration
PAIDeployConfig Structure
PAI deployment uses YAML configuration files with the following structure:code.source_dir is resolved relative to the config file location.Configuration Structure Reference
Resource Types
PAI supports three resource types:1. Public Resource Pool (type: "public")
Deploy on shared ECS instances, suitable for development/testing and small-scale deployments:
2. Dedicated Resource Group (type: "resource")
Deploy on dedicated EAS resource group, suitable for production environments requiring resource isolation:
3. Quota-based (type: "quota")
Deploy using PAI quota, suitable for enterprise-level resource management:
VPC Configuration
Private network deployment configuration for scenarios requiring access to public or internal resources:Method 7: Knative Deployment
Best for: Enterprise production environments requiring scalability, high availability, and cloud-native serverless container orchestration.Features
- Container-based Serverless deployment
- Provides automatic scaling from zero to thousands of instances, intelligent traffic routing
- Cloud-native orchestration
- Resource management and limits
- Health checks and auto-recovery
Prerequisites for Kubernetes Deployment
Implementation
- Containerized Serverless deployment
- Provides automatic scaling from zero to thousands of instances, intelligent traffic routing
- Resource limits and health checks configured
Method 8: Kruise Deployment
Best For: Scenarios requiring instance-level isolation, pause/resume capabilities, and secure multi-tenant runtime environments.Features
- Custom resource deployment based on Kruise Sandbox CRD (
agents.kruise.io/v1alpha1) - Instance-level isolation, ensuring secure runtime environments across different agents
- Supports pausing and resuming, effectively saving resource consumption
- Automatically creates LoadBalancer Service for external access
- Deployment state persistence management
Kruise Deployment Prerequisites
Implementation
- Isolated deployment based on Kruise Sandbox CRD, each agent runs in an independent environment
- Automatically creates LoadBalancer Service, supports automatic switching between local and cloud environments
- Deployment state is automatically persisted, supports lifecycle management via CLI
Method 9: Serverless Deployment: Function Compute (FC)
Best For: Alibaba Cloud users who need to deploy agents to Function Compute (FC) service with automated build, upload, and deployment workflows. FC provides a true serverless experience with pay-per-use pricing and automatic scaling.Features
- Serverless deployment on Alibaba Cloud Function Compute
- Automatic project building and packaging with Docker
- OSS integration for artifact storage
- HTTP trigger for public access
- Session affinity support for stateful applications
- VPC and logging configuration support
- Pay-per-use pricing model
FC Deployment Prerequisites
Implementation
- Automatically builds project with Docker and creates a deployable zip package
- Uploads artifacts to OSS for FC to pull
- Creates FC function with HTTP trigger for public access
- Supports session affinity via
x-agentscope-runtime-session-idheader - Supports updating existing deployments (via
function_nameparameter)