Skip to content

Commit fa0918a

Browse files
committed
feat: add support for shared internet access in runtime network configuration
1 parent 443470c commit fa0918a

10 files changed

Lines changed: 268 additions & 19 deletions

File tree

agentkit/toolkit/cli/cli_config.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,15 @@ def config_command(
201201
"--runtime-subnet-ids",
202202
help="Runtime subnet ID (repeatable; cloud/hybrid, CreateRuntime only)",
203203
),
204+
runtime_enable_shared_internet_access: Optional[bool] = typer.Option(
205+
None,
206+
"--runtime_enable_shared_internet_access/--no-runtime_enable_shared_internet_access",
207+
"--runtime-enable-shared-internet-access/--no-runtime-enable-shared-internet-access",
208+
help=(
209+
"Enable shared internet egress for Runtime private network "
210+
"(cloud/hybrid, CreateRuntime only; effective for private/both)"
211+
),
212+
),
204213
):
205214
"""Configure AgentKit (supports interactive and non-interactive modes).
206215
@@ -307,6 +316,7 @@ def config_command(
307316
runtime_network_mode=runtime_network_mode,
308317
runtime_vpc_id=runtime_vpc_id,
309318
runtime_subnet_ids=runtime_subnet_ids,
319+
runtime_enable_shared_internet_access=runtime_enable_shared_internet_access,
310320
)
311321

312322
has_cli_params = ConfigParamHandler.has_cli_params(cli_params)

agentkit/toolkit/cli/cli_runtime.py

Lines changed: 71 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,62 @@
3636
)
3737

3838

39+
def _build_network_for_create_runtime(
40+
vpc_id: Optional[str],
41+
subnet_ids: Optional[str],
42+
enable_private_network: bool,
43+
enable_public_network: bool,
44+
enable_shared_internet_access: bool,
45+
) -> Optional[rt.NetworkForCreateRuntime]:
46+
has_vpc_id = bool((vpc_id or "").strip())
47+
has_subnet_ids = bool((subnet_ids or "").strip())
48+
49+
wants_private_network = (
50+
enable_private_network
51+
or has_vpc_id
52+
or has_subnet_ids
53+
or enable_shared_internet_access
54+
)
55+
56+
if enable_shared_internet_access and not wants_private_network:
57+
raise ValueError(
58+
"enable-shared-internet-access is only effective when private network is enabled."
59+
)
60+
61+
if wants_private_network and not has_vpc_id:
62+
raise ValueError(
63+
"vpc-id is required when private network is enabled (private/both)."
64+
)
65+
66+
if not wants_private_network and enable_public_network is False:
67+
raise ValueError(
68+
"At least one network must be enabled. Enable public network or configure private network."
69+
)
70+
71+
should_send_network_configuration = (
72+
wants_private_network or enable_public_network is False
73+
)
74+
if not should_send_network_configuration:
75+
return None
76+
77+
vpc = None
78+
if wants_private_network:
79+
subs = [s.strip() for s in (subnet_ids or "").split(",") if s.strip()] or None
80+
vpc = rt.NetworkVpcForCreateRuntime(
81+
vpc_id=(vpc_id or "").strip(),
82+
subnet_ids=subs,
83+
enable_shared_internet_access=(
84+
True if enable_shared_internet_access else None
85+
),
86+
)
87+
88+
return rt.NetworkForCreateRuntime(
89+
vpc_configuration=vpc,
90+
enable_private_network=wants_private_network,
91+
enable_public_network=enable_public_network,
92+
)
93+
94+
3995
@runtime_app.command("create")
4096
def create_runtime_command(
4197
name: str = typer.Option(..., "--name", help="Runtime name"),
@@ -71,7 +127,14 @@ def create_runtime_command(
71127
False, "--enable-private-network", help="Enable private network"
72128
),
73129
enable_public_network: bool = typer.Option(
74-
True, "--enable-public-network", help="Enable public network"
130+
True,
131+
"--enable-public-network/--no-enable-public-network",
132+
help="Enable public network",
133+
),
134+
enable_shared_internet_access: bool = typer.Option(
135+
False,
136+
"--enable-shared-internet-access",
137+
help="Enable shared internet egress for private network (effective for private/both)",
75138
),
76139
api_key_name: Optional[str] = typer.Option(
77140
None, "--apikey-name", help="API key name"
@@ -133,18 +196,13 @@ def create_runtime_command(
133196
)
134197

135198
network = None
136-
if vpc_id or enable_private_network or enable_public_network:
137-
vpc = None
138-
if vpc_id:
139-
subs = [
140-
s.strip() for s in (subnet_ids or "").split(",") if s.strip()
141-
] or None
142-
vpc = rt.NetworkVpcForCreateRuntime(vpc_id=vpc_id, subnet_ids=subs)
143-
network = rt.NetworkForCreateRuntime(
144-
vpc_configuration=vpc,
145-
enable_private_network=enable_private_network,
146-
enable_public_network=enable_public_network,
147-
)
199+
network = _build_network_for_create_runtime(
200+
vpc_id=vpc_id,
201+
subnet_ids=subnet_ids,
202+
enable_private_network=enable_private_network,
203+
enable_public_network=enable_public_network,
204+
enable_shared_internet_access=enable_shared_internet_access,
205+
)
148206

149207
envs = None
150208
if envs_json:

agentkit/toolkit/config/config_handler.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def collect_cli_params(
110110
runtime_network_mode: Optional[str],
111111
runtime_vpc_id: Optional[str],
112112
runtime_subnet_ids: Optional[List[str]],
113+
runtime_enable_shared_internet_access: Optional[bool],
113114
) -> Dict[str, Any]:
114115
"""Collect all CLI parameters.
115116
@@ -204,6 +205,10 @@ def collect_cli_params(
204205
runtime_network["subnet_ids"] = ConfigParamHandler.parse_id_list(
205206
runtime_subnet_ids
206207
)
208+
if runtime_enable_shared_internet_access is not None:
209+
runtime_network["enable_shared_internet_access"] = (
210+
runtime_enable_shared_internet_access
211+
)
207212
if runtime_network:
208213
strategy_params["runtime_network"] = runtime_network
209214
if runtime_auth_type is not None:

agentkit/toolkit/config/strategy_configs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ class HybridStrategyConfig(AutoSerializableMixin):
323323
metadata={
324324
"hidden": True,
325325
"description": "Runtime network configuration (advanced, CreateRuntime only)",
326-
"examples": "{mode: private, vpc_id: vpc-xxx, subnet_ids: [subnet-aaa, subnet-bbb]}",
326+
"examples": "{mode: private, vpc_id: vpc-xxx, subnet_ids: [subnet-aaa, subnet-bbb], enable_shared_internet_access: true}",
327327
},
328328
)
329329
_config_metadata = {
@@ -588,7 +588,7 @@ class CloudStrategyConfig(AutoSerializableMixin):
588588
metadata={
589589
"hidden": True,
590590
"description": "Runtime network configuration (advanced, CreateRuntime only)",
591-
"examples": "{mode: private, vpc_id: vpc-xxx, subnet_ids: [subnet-aaa, subnet-bbb]}",
591+
"examples": "{mode: private, vpc_id: vpc-xxx, subnet_ids: [subnet-aaa, subnet-bbb], enable_shared_internet_access: true}",
592592
},
593593
)
594594

agentkit/toolkit/runners/ve_agentkit.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,9 @@ def _build_network_config_for_create(
632632
mode = runtime_network.get("mode")
633633
vpc_id = runtime_network.get("vpc_id")
634634
subnet_ids = runtime_network.get("subnet_ids")
635+
enable_shared_internet_access_raw = runtime_network.get(
636+
"enable_shared_internet_access"
637+
)
635638

636639
# Convenience: if vpc_id is provided without an explicit mode, assume private.
637640
if mode is None and vpc_id:
@@ -652,6 +655,30 @@ def _build_network_config_for_create(
652655
enable_public = mode in {"public", "both"}
653656
enable_private = mode in {"private", "both"}
654657

658+
enable_shared_internet_access: Optional[bool] = None
659+
if enable_shared_internet_access_raw is not None:
660+
if isinstance(enable_shared_internet_access_raw, bool):
661+
enable_shared_internet_access = enable_shared_internet_access_raw
662+
elif isinstance(enable_shared_internet_access_raw, (int, float)):
663+
enable_shared_internet_access = bool(enable_shared_internet_access_raw)
664+
else:
665+
raw_str = str(enable_shared_internet_access_raw).strip().lower()
666+
if raw_str in {"true", "1", "yes", "y"}:
667+
enable_shared_internet_access = True
668+
elif raw_str in {"false", "0", "no", "n"}:
669+
enable_shared_internet_access = False
670+
else:
671+
raise ValueError(
672+
"Invalid runtime_network.enable_shared_internet_access. "
673+
"Valid values: true/false."
674+
)
675+
676+
if enable_shared_internet_access and not enable_private:
677+
raise ValueError(
678+
"runtime_network.enable_shared_internet_access is only effective when "
679+
"runtime_network.mode is private/both."
680+
)
681+
655682
vpc_configuration = None
656683
if enable_private:
657684
vpc_id_str = str(vpc_id or "").strip()
@@ -671,6 +698,9 @@ def _build_network_config_for_create(
671698
vpc_configuration = runtime_types.NetworkVpcForCreateRuntime(
672699
vpc_id=vpc_id_str,
673700
subnet_ids=parsed_subnet_ids,
701+
enable_shared_internet_access=(
702+
True if enable_shared_internet_access else None
703+
),
674704
)
675705

676706
return runtime_types.NetworkForCreateRuntime(

agentkit/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
VERSION = "0.4.4"
15+
VERSION = "0.4.5"

docs/content/2.agentkit-cli/2.commands.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,8 @@ launch_types:
537537
agentkit config \
538538
--runtime-network-mode private \
539539
--runtime-vpc-id vpc-xxxxxxxx \
540-
--runtime-subnet-id subnet-aaaaaaaa
540+
--runtime-subnet-id subnet-aaaaaaaa \
541+
--runtime-enable-shared-internet-access
541542
```
542543

543544
**YAML 配置格式**(`agentkit.yaml`):
@@ -548,6 +549,7 @@ launch_types:
548549
runtime_network:
549550
mode: private # public | private | both
550551
vpc_id: vpc-xxxxxxxx # private/both 必填
552+
enable_shared_internet_access: true # 仅对 private/both 生效
551553
subnet_ids:
552554
- subnet-aaaaaaaa
553555
```
@@ -557,6 +559,10 @@ launch_types:
557559
- `private`:仅私网访问(需要 `vpc_id`)
558560
- `both`:同时开启公网与私网(需要 `vpc_id`)
559561

562+
`enable_shared_internet_access` 说明:
563+
- 仅当 `mode` 为 `private` 或 `both` 时生效;开启后 Runtime 将使用平台提供的共享公网出口访问公网
564+
- 若 `mode=public` 且开启该开关,AgentKit 会报错以避免“看似配置但实际不生效”的误用
565+
560566
### 控制选项
561567

562568
| 选项 | 说明 |
@@ -1826,4 +1832,4 @@ agentkit status
18261832

18271833
- 📖 [配置文件说明](./3.configurations.md) - 深入了解每个配置项
18281834
- 🚀 [快速开始](../1.introduction/3.quickstart.md) - 跟随教程实践
1829-
-[问题排查](../1.introduction/4.troubleshooting.md) - 更多疑难问题解答
1835+
-[问题排查](../1.introduction/4.troubleshooting.md) - 更多疑难问题解答

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "agentkit-sdk-python"
3-
version = "0.4.4"
3+
version = "0.4.5"
44
description = "Python SDK for transforming any AI agent into a production-ready application. Framework-agnostic primitives for runtime, memory, authentication, and tools with volcengine-managed infrastructure."
55
readme = "README.md"
66
requires-python = ">=3.10"
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import pytest
2+
3+
4+
def test_build_network_none_when_no_user_intent():
5+
from agentkit.toolkit.cli.cli_runtime import _build_network_for_create_runtime
6+
7+
network = _build_network_for_create_runtime(
8+
vpc_id=None,
9+
subnet_ids=None,
10+
enable_private_network=False,
11+
enable_public_network=True,
12+
enable_shared_internet_access=False,
13+
)
14+
assert network is None
15+
16+
17+
def test_build_network_private_requires_vpc_id():
18+
from agentkit.toolkit.cli.cli_runtime import _build_network_for_create_runtime
19+
20+
with pytest.raises(ValueError):
21+
_build_network_for_create_runtime(
22+
vpc_id=None,
23+
subnet_ids=None,
24+
enable_private_network=True,
25+
enable_public_network=True,
26+
enable_shared_internet_access=False,
27+
)
28+
29+
30+
def test_build_network_disable_public_requires_private():
31+
from agentkit.toolkit.cli.cli_runtime import _build_network_for_create_runtime
32+
33+
with pytest.raises(ValueError):
34+
_build_network_for_create_runtime(
35+
vpc_id=None,
36+
subnet_ids=None,
37+
enable_private_network=False,
38+
enable_public_network=False,
39+
enable_shared_internet_access=False,
40+
)
41+
42+
43+
def test_build_network_vpc_id_implies_private_enabled():
44+
from agentkit.toolkit.cli.cli_runtime import _build_network_for_create_runtime
45+
46+
network = _build_network_for_create_runtime(
47+
vpc_id="vpc-123",
48+
subnet_ids=None,
49+
enable_private_network=False,
50+
enable_public_network=True,
51+
enable_shared_internet_access=False,
52+
)
53+
assert network is not None
54+
assert network.enable_private_network is True
55+
assert network.enable_public_network is True
56+
assert network.vpc_configuration is not None
57+
assert network.vpc_configuration.vpc_id == "vpc-123"
58+
59+
60+
def test_build_network_shared_internet_access_sets_vpc_field():
61+
from agentkit.toolkit.cli.cli_runtime import _build_network_for_create_runtime
62+
63+
network = _build_network_for_create_runtime(
64+
vpc_id="vpc-123",
65+
subnet_ids="subnet-1,subnet-2",
66+
enable_private_network=True,
67+
enable_public_network=False,
68+
enable_shared_internet_access=True,
69+
)
70+
assert network is not None
71+
assert network.enable_private_network is True
72+
assert network.enable_public_network is False
73+
assert network.vpc_configuration is not None
74+
assert network.vpc_configuration.enable_shared_internet_access is True

0 commit comments

Comments
 (0)