Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion agentrun/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ def __init__(
Read from env vars if not provided: AGENTRUN_ACCOUNT_ID or FC_ACCOUNT_ID
token: 自定义令牌,用于数据链路调用 / Custom token for data API calls
region_id: 区域 ID,默认 cn-hangzhou / Region ID, defaults to cn-hangzhou
未提供时从环境变量读取: AGENTRUN_REGION、FC_REGION 或 ALIBABA_CLOUD_REGION_ID
Read from env vars if not provided: AGENTRUN_REGION, FC_REGION or ALIBABA_CLOUD_REGION_ID
timeout: 请求超时时间(秒),默认 600 / Request timeout in seconds, defaults to 600
read_timeout: 读取超时时间(秒),默认 100000 / Read timeout in seconds, defaults to 100000
control_endpoint: 自定义控制链路端点,可选 / Custom control endpoint, optional
Expand Down Expand Up @@ -127,7 +129,7 @@ def __init__(
)
if region_id is None:
region_id = get_env_with_default(
"cn-hangzhou", "AGENTRUN_REGION", "FC_REGION"
"cn-hangzhou", "AGENTRUN_REGION", "FC_REGION", "ALIBABA_CLOUD_REGION_ID"
)
if control_endpoint is None:
control_endpoint = get_env_with_default(
Expand Down
23 changes: 23 additions & 0 deletions tests/unittests/utils/test_config_extended.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,29 @@ def test_init_from_env_alibaba_cloud_vars(self):
assert config.get_account_id() == "fc_account"
assert config.get_region_id() == "cn-beijing"

def test_init_from_env_alibaba_cloud_region_id(self):
"""测试从 ALIBABA_CLOUD_REGION_ID 环境变量读取 region_id"""
with patch.dict(
os.environ,
{"ALIBABA_CLOUD_REGION_ID": "cn-shanghai"},
clear=True,
):
config = Config()
assert config.get_region_id() == "cn-shanghai"

def test_region_id_env_priority_agentrun_over_alibaba(self):
"""测试 AGENTRUN_REGION 优先于 ALIBABA_CLOUD_REGION_ID"""
with patch.dict(
os.environ,
{
"AGENTRUN_REGION": "cn-hangzhou",
"ALIBABA_CLOUD_REGION_ID": "cn-shanghai",
},
clear=True,
):
config = Config()
assert config.get_region_id() == "cn-hangzhou"

def test_with_configs_class_method(self):
"""测试 with_configs 类方法"""
config1 = Config(access_key_id="id1", region_id="cn-hangzhou")
Expand Down