Skip to content

Commit 5d80bd7

Browse files
committed
Merge remote-tracking branch 'origin/main'
# Conflicts: # src/agentscope_runtime/engine/services/agent_state/redis_state_service.py # src/agentscope_runtime/engine/services/memory/redis_memory_service.py
2 parents e00e815 + d1f8c9d commit 5d80bd7

File tree

9 files changed

+34
-7
lines changed

9 files changed

+34
-7
lines changed

cookbook/en/cli.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,7 @@ agentscope deploy k8s SOURCE [OPTIONS]
579579
| `--deploy-timeout` | integer | `300` | Deployment timeout in seconds |
580580
| `--health-check` | flag | `None` | Enable/disable health check |
581581
| `--platform` | string | `"linux/amd64"` | Target platform (e.g., 'linux/amd64', 'linux/arm64') |
582+
| `--pypi-mirror` | string | `None` | PyPI mirror URL for pip package installation (e.g., 'https://pypi.tuna.tsinghua.edu.cn/simple'). If not specified, uses pip default |
582583

583584
##### Prerequisites
584585

cookbook/en/deployment.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Most deployments follow these stages:
2424
- Access to at least one LLM provider (DashScope, OpenAI, or self-hosted inference).
2525
- Permissions for the target platform (local machine, Docker, Kubernetes, etc.).
2626
- Access grants for tool/sandbox resources such as browser automation, file systems, or bespoke services.
27+
- (Optional) Custom PyPI mirror URL if deploying in regions with restricted or slow access to the default PyPI index. This can significantly speed up Docker image builds, especially in China or corporate networks.
2728

2829
## Section Guide
2930

cookbook/zh/cli.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ agentscope deploy k8s SOURCE [OPTIONS]
578578
| `--deploy-timeout` | integer | `300` | 部署超时时间(秒) |
579579
| `--health-check` | flag | `None` | 启用/禁用健康检查 |
580580
| `--platform` | string | `"linux/amd64"` | 目标平台(例如 'linux/amd64'、'linux/arm64') |
581+
| `--pypi-mirror` | string | `None` | PyPI 镜像源 URL,用于 pip 包安装(例如 'https://pypi.tuna.tsinghua.edu.cn/simple')。如果未指定,使用 pip 默认源 |
581582

582583
##### 前置要求
583584

cookbook/zh/deployment.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
- 至少一个可用的大模型接入(例如 DashScope、OpenAI 或自建推理服务)。
2525
- 目标部署平台(本地、Docker、Kubernetes 等)的访问与权限。
2626
- 对应的工具/沙箱权限,如浏览器自动化、文件系统或自定义工具服务。
27+
- (可选)如果在访问默认 PyPI 受限或速度较慢的区域(如中国或企业网络)部署,可配置自定义 PyPI 镜像源 URL,这可以显著加速 Docker 镜像构建。
2728

2829
## 子章节导读
2930

src/agentscope_runtime/cli/commands/deploy.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,13 @@ def agentrun(
828828
help="Target platform (e.g., 'linux/amd64', 'linux/arm64')",
829829
default="linux/amd64",
830830
)
831+
@click.option(
832+
"--pypi-mirror",
833+
help="PyPI mirror URL for pip package installation (e.g., "
834+
"https://pypi.tuna.tsinghua.edu.cn/simple). If not specified, "
835+
"uses pip default.",
836+
default=None,
837+
)
831838
def k8s(
832839
source: str,
833840
name: str,
@@ -854,6 +861,7 @@ def k8s(
854861
deploy_timeout: int,
855862
health_check: bool,
856863
platform: str,
864+
pypi_mirror: str,
857865
):
858866
"""
859867
Deploy to Kubernetes/ACK.
@@ -898,6 +906,7 @@ def k8s(
898906
"deploy_timeout": deploy_timeout,
899907
"health_check": health_check,
900908
"platform": platform,
909+
"pypi_mirror": pypi_mirror,
901910
}
902911
merged_config = _merge_config(config_dict, cli_params)
903912

@@ -918,6 +927,7 @@ def k8s(
918927
deploy_timeout = merged_config.get("deploy_timeout", 300)
919928
health_check = merged_config.get("health_check", True)
920929
platform = merged_config.get("platform")
930+
pypi_mirror = merged_config.get("pypi_mirror")
921931

922932
# Handle requirements (can be comma-separated string, list, or file
923933
# path)
@@ -1033,6 +1043,8 @@ def k8s(
10331043
deploy_params["health_check"] = health_check
10341044
if platform:
10351045
deploy_params["platform"] = platform
1046+
if pypi_mirror:
1047+
deploy_params["pypi_mirror"] = pypi_mirror
10361048

10371049
# Add agent_source for state saving
10381050
deploy_params["agent_source"] = abs_source

src/agentscope_runtime/engine/deployers/kubernetes_deployer.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ async def deploy(
144144
image_tag: str = "latest",
145145
push_to_registry: bool = False,
146146
use_cache: bool = True,
147+
pypi_mirror: Optional[str] = None,
147148
**kwargs,
148149
) -> Dict[str, Any]:
149150
"""
@@ -170,6 +171,7 @@ async def deploy(
170171
mount_dir: Mount directory
171172
runtime_config: K8s runtime configuration
172173
use_cache: Enable build cache (default: True)
174+
pypi_mirror: PyPI mirror URL for pip package installation
173175
# Backward compatibility
174176
image_name: Image name
175177
image_tag: Image tag
@@ -209,6 +211,7 @@ async def deploy(
209211
protocol_adapters=protocol_adapters,
210212
custom_endpoints=custom_endpoints,
211213
use_cache=use_cache,
214+
pypi_mirror=pypi_mirror,
212215
**kwargs,
213216
)
214217
if not built_image_name:

src/agentscope_runtime/engine/deployers/utils/docker_image_utils/dockerfile_generator.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class DockerfileConfig(BaseModel):
2222
health_check_endpoint: str = "/health"
2323
custom_template: Optional[str] = None
2424
platform: Optional[str] = None
25+
pypi_mirror: Optional[str] = None
2526

2627

2728
class DockerfileGenerator:
@@ -73,8 +74,7 @@ class DockerfileGenerator:
7374
# Install Python dependencies
7475
RUN pip install --no-cache-dir --upgrade pip
7576
RUN if [ -f requirements.txt ]; then \\
76-
pip install --no-cache-dir -r requirements.txt \\
77-
-i https://pypi.tuna.tsinghua.edu.cn/simple; fi
77+
pip install --no-cache-dir -r requirements.txt{pypi_mirror_flag}; fi
7878
7979
# Create non-root user for security
8080
RUN adduser --disabled-password --gecos '' {user} && \\
@@ -136,6 +136,11 @@ def generate_dockerfile_content(self, config: DockerfileConfig) -> str:
136136
f'"--port", "{config.port}"]'
137137
)
138138

139+
# Prepare PyPI mirror flag
140+
pypi_mirror_flag = ""
141+
if config.pypi_mirror:
142+
pypi_mirror_flag = f" -i {config.pypi_mirror}"
143+
139144
# Format template with configuration values
140145
content = template.format(
141146
base_image=config.base_image,
@@ -147,6 +152,7 @@ def generate_dockerfile_content(self, config: DockerfileConfig) -> str:
147152
env_vars_section=env_vars_section,
148153
startup_command_section=startup_command_section,
149154
platform=config.platform,
155+
pypi_mirror_flag=pypi_mirror_flag,
150156
)
151157

152158
return content

src/agentscope_runtime/engine/deployers/utils/docker_image_utils/image_factory.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class ImageConfig(BaseModel):
4040
port: int = 8000
4141
env_vars: Dict[str, str] = Field(default_factory=lambda: {})
4242
startup_command: Optional[str] = None
43+
pypi_mirror: Optional[str] = None
4344

4445
# Runtime configuration
4546
host: str = "0.0.0.0" # Container-friendly default
@@ -218,6 +219,7 @@ def _build_image(
218219
env_vars=config.env_vars,
219220
startup_command=startup_command,
220221
platform=config.platform,
222+
pypi_mirror=config.pypi_mirror,
221223
)
222224

223225
dockerfile_path = self.dockerfile_generator.create_dockerfile(
@@ -314,6 +316,7 @@ def build_image(
314316
embed_task_processor: bool = True,
315317
extra_startup_args: Optional[Dict[str, Union[str, int, bool]]] = None,
316318
use_cache: bool = True,
319+
pypi_mirror: Optional[str] = None,
317320
**kwargs,
318321
) -> str:
319322
"""
@@ -339,6 +342,7 @@ def build_image(
339342
embed_task_processor: Whether to embed task processor
340343
extra_startup_args: Additional startup arguments
341344
use_cache: Enable build cache (default: True)
345+
pypi_mirror: PyPI mirror URL for pip package installation
342346
**kwargs: Additional configuration options
343347
344348
Returns:
@@ -373,6 +377,7 @@ def build_image(
373377
host=host,
374378
embed_task_processor=embed_task_processor,
375379
extra_startup_args=extra_startup_args or {},
380+
pypi_mirror=pypi_mirror,
376381
**kwargs,
377382
)
378383

src/agentscope_runtime/engine/services/agent_state/state_service_factory.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,10 @@ class StateServiceFactory(ServiceFactory[StateService]):
4343

4444
StateServiceFactory.register_backend(
4545
"in_memory",
46-
lambda **kwargs: InMemoryStateService(),
46+
InMemoryStateService,
4747
)
4848

4949
StateServiceFactory.register_backend(
5050
"redis",
51-
lambda **kwargs: RedisStateService(
52-
redis_url=kwargs.get("redis_url", "redis://localhost:6379/0"),
53-
redis_client=kwargs.get("redis_client"),
54-
),
51+
RedisStateService,
5552
)

0 commit comments

Comments
 (0)