AgentRun 配置示例
1. 代码模式 - 最小配置
edition: 3.0.0
name: minimal-agent
access: default
resources:
my-agent:
component: agentrun
props:
region: cn-hangzhou
agent:
name: my-agent
code:
src: ./code
language: python3.12
command:
- python3
- main.py
2. 代码模式 - 完整配置
edition: 3.0.0
name: complete-agent
access: default
vars:
region: cn-hangzhou
env: production
resources:
my-agent:
component: agentrun
props:
region: ${vars.region}
agent:
# 基本信息
name: ${vars.env}-agent
description: "Production agent runtime"
# 代码配置
code:
src: ./code
language: python3.12
command:
- python3
- main.py
# 资源配置
cpu: 2.0
memory: 4096
port: 8000
instanceConcurrency: 50
sessionIdleTimeoutSeconds: 7200
# 网络配置
vpcConfig:
vpcId: vpc-bp1234567890abcdef
vSwitchIds:
- vsw-bp1111111111111111
- vsw-bp2222222222222222
securityGroupId: sg-bp1234567890abcdef
internetAccess: true
# 环境变量
environmentVariables:
ENVIRONMENT: ${vars.env}
LOG_LEVEL: info
API_KEY: ${env(API_KEY)}
# 执行角色
role: acs:ram::123456789:role/AliyunAgentRunRole
# 凭证名称
credentialName: my-credential
# 日志配置
logConfig:
project: ${vars.env}-logs
logstore: agentrun-runtime
# 协议配置
protocolConfiguration:
type: HTTP
# 健康检查
healthCheckConfiguration:
httpGetUrl: /health
periodSeconds: 30
timeoutSeconds: 3
# 端点配置
endpoints:
- name: production
version: 1
description: "Production endpoint"
- name: staging
version: LATEST
description: "Staging endpoint"
3. 容器模式
edition: 3.0.0
name: container-agent
access: default
resources:
my-agent:
component: agentrun
props:
region: cn-hangzhou
agent:
name: my-container-agent
description: "Container-based agent"
# 容器配置
customContainerConfig:
image: registry.cn-hangzhou.aliyuncs.com/my-ns/my-agent:v1.0
command:
- python3
- app.py
imageRegistryType: ACR
# 资源配置
cpu: 2.0
memory: 4096
port: 9000
# 环境变量
environmentVariables:
MODEL_NAME: qwen-max
API_KEY: ${env(API_KEY)}
# 日志配置
logConfig: auto
4. VPC 内网访问
edition: 3.0.0
name: vpc-agent
access: default
resources:
my-agent:
component: agentrun
props:
region: cn-hangzhou
agent:
name: my-vpc-agent
code:
src: ./code
language: python3.12
command:
- python3
- main.py
# VPC 配置
vpcConfig:
vpcId: vpc-bp1234567890abcdef
vSwitchIds: vsw-bp1111111111111111
securityGroupId: sg-bp1234567890abcdef
# 禁用公网访问
internetAccess: false
logConfig: auto
5. OSS 代码包
edition: 3.0.0
name: oss-agent
access: default
resources:
my-agent:
component: agentrun
props:
region: cn-hangzhou
agent:
name: my-oss-agent
code:
ossBucketName: my-code-bucket
ossObjectName: agent-code.zip
language: python3.12
command:
- python3
- main.py
logConfig: auto
6. 多环境配置示例
s.dev.yaml - 开发环境
edition: 3.0.0
name: dev-agent
access: default
resources:
my-agent:
component: agentrun
props:
region: cn-hangzhou
agent:
name: dev-agent
code:
src: ./code
language: python3.12
command: [python3, main.py]
cpu: 1.0
memory: 2048
logConfig: auto
s.prod.yaml - 生产环境
edition: 3.0.0
name: prod-agent
access: prod-account
resources:
my-agent:
component: agentrun
props:
region: cn-hangzhou
agent:
name: prod-agent
code:
src: ./code
language: python3.12
command: [python3, main.py]
cpu: 2.0
memory: 4096
vpcConfig:
vpcId: vpc-prod
vSwitchIds: [vsw-prod-1, vsw-prod-2]
securityGroupId: sg-prod
internetAccess: false
logConfig:
project: prod-logs
logstore: agentrun
部署时指定配置文件:
# 开发环境
s deploy -t s.dev.yaml
# 生产环境
s deploy -t s.prod.yaml