Skip to content

Commit 37c3702

Browse files
authored
fix: veadk create supports the agent_name parameter (#260)
1 parent 99a461f commit 37c3702

File tree

3 files changed

+48
-72
lines changed

3 files changed

+48
-72
lines changed

docs/content/90.cli/2.commands.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,20 @@ navigation:
1010
使用 `veadk create` 命令在当前目录中创建一个新的智能体项目脚手架。
1111

1212
```bash
13-
veadk create [OPTIONS]
13+
veadk create [AGENT_NAME] [OPTIONS]
1414
```
1515

16-
选项包括:
16+
### 参数
17+
18+
- `AGENT_NAME`: 要创建的智能体的名称。如果未提供,将会提示您输入。
19+
20+
### 选项
1721

18-
- `--agent-name`:智能体的名称。如果未提供,将会提示您输入。
1922
- `--ark-api-key`:ARK API 密钥。如果未提供,将会提示您输入或稍后在 `config.yaml` 文件中配置。
2023

2124
执行 `veadk create` 命令后,它会:
2225

23-
1. 提示您输入智能体名称(如果未通过 `--agent-name` 提供)。
26+
1. 提示您输入智能体名称(如果未作为参数提供)。
2427
2. 提示您输入 ARK API 密钥(如果未通过 `--ark-api-key` 提供),您可以选择立即输入或稍后在生成的 `config.yaml` 文件中手动配置。
2528
3. 在当前目录下创建一个以智能体名称命名的新目录。
2629
4. 在新目录中生成以下文件:

tests/cli/test_cli_create.py

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,74 +20,67 @@
2020
def test_create_agent_with_options():
2121
runner = CliRunner()
2222
with runner.isolated_filesystem() as temp_dir:
23-
result = runner.invoke(
24-
create, ["--agent-name", "test-agent", "--ark-api-key", "test-key"]
25-
)
23+
result = runner.invoke(create, ["test-agent", "--ark-api-key", "test-key"])
2624
assert result.exit_code == 0
2725

2826
agent_folder = Path(temp_dir) / "test-agent"
2927
assert agent_folder.exists()
3028

31-
config_path = agent_folder / "config.yaml"
29+
config_path = agent_folder / ".env"
3230
assert config_path.exists()
3331
config_content = config_path.read_text()
34-
assert "api_key: test-key" in config_content
32+
assert "MODEL_AGENT_API_KEY=test-key" in config_content
3533

36-
agent_init_path = agent_folder / "test-agent" / "__init__.py"
34+
agent_init_path = agent_folder / "__init__.py"
3735
assert agent_init_path.exists()
3836

39-
agent_py_path = agent_folder / "test-agent" / "agent.py"
37+
agent_py_path = agent_folder / "agent.py"
4038
assert agent_py_path.exists()
4139

4240

4341
def test_create_agent_overwrite_existing_directory():
4442
runner = CliRunner()
4543
with runner.isolated_filesystem() as temp_dir:
4644
# First, create the agent
47-
runner.invoke(
48-
create, ["--agent-name", "test-agent", "--ark-api-key", "test-key"]
49-
)
45+
runner.invoke(create, ["test-agent", "--ark-api-key", "test-key"])
5046

5147
# Attempt to create it again, but cancel the overwrite
5248
result = runner.invoke(
5349
create,
54-
["--agent-name", "test-agent", "--ark-api-key", "test-key"],
50+
["test-agent", "--ark-api-key", "test-key"],
5551
input="n\n",
5652
)
5753
assert "Operation cancelled" in result.output
5854

5955
# Attempt to create it again, and confirm the overwrite
6056
result = runner.invoke(
6157
create,
62-
["--agent-name", "test-agent", "--ark-api-key", "new-key"],
58+
["test-agent", "--ark-api-key", "new-key"],
6359
input="y\n",
6460
)
6561
assert result.exit_code == 0
6662
agent_folder = Path(temp_dir) / "test-agent"
67-
config_path = agent_folder / "config.yaml"
63+
config_path = agent_folder / ".env"
6864
config_content = config_path.read_text()
69-
assert "api_key: new-key" in config_content
65+
assert "MODEL_AGENT_API_KEY=new-key" in config_content
7066

7167

7268
def test_generate_files(tmp_path: Path):
7369
agent_name = "test-agent"
7470
api_key = "test-key"
7571
target_dir = tmp_path / agent_name
7672

77-
_generate_files(agent_name, api_key, target_dir)
78-
79-
agent_code_dir = target_dir / agent_name
80-
assert agent_code_dir.is_dir()
73+
_generate_files(api_key, target_dir)
8174

82-
config_file = target_dir / "config.yaml"
75+
config_file = target_dir / ".env"
8376
assert config_file.is_file()
8477
content = config_file.read_text()
85-
assert f"api_key: {api_key}" in content
78+
assert f"MODEL_AGENT_API_KEY={api_key}" in content
8679

87-
init_file = agent_code_dir / "__init__.py"
80+
init_file = target_dir / "__init__.py"
8881
assert init_file.is_file()
8982

90-
agent_file = agent_code_dir / "agent.py"
83+
agent_file = target_dir / "agent.py"
9184
assert agent_file.is_file()
9285

9386

@@ -96,15 +89,15 @@ def test_prompt_for_ark_api_key_enter_now():
9689
with runner.isolated_filesystem():
9790
result = runner.invoke(create, input="test-agent\n1\nmy-secret-key\n")
9891
assert result.exit_code == 0
99-
assert "my-secret-key" in (Path("test-agent") / "config.yaml").read_text()
92+
assert "my-secret-key" in (Path("test-agent") / ".env").read_text()
10093

10194

10295
def test_prompt_for_ark_api_key_configure_later():
10396
runner = CliRunner()
10497
with runner.isolated_filesystem():
10598
result = runner.invoke(create, input="test-agent\n2\n")
10699
assert result.exit_code == 0
107-
assert "api_key: " in (Path("test-agent") / "config.yaml").read_text()
100+
assert "MODEL_AGENT_API_KEY=" in (Path("test-agent") / ".env").read_text()
108101

109102

110103
def test_create_agent_with_prompts():
@@ -116,13 +109,13 @@ def test_create_agent_with_prompts():
116109
agent_folder = Path(temp_dir) / "test-agent"
117110
assert agent_folder.exists()
118111

119-
config_path = agent_folder / "config.yaml"
112+
config_path = agent_folder / ".env"
120113
assert config_path.exists()
121114
config_content = config_path.read_text()
122-
assert "api_key: test-key" in config_content
115+
assert "MODEL_AGENT_API_KEY=test-key" in config_content
123116

124-
agent_init_path = agent_folder / "test-agent" / "__init__.py"
117+
agent_init_path = agent_folder / "__init__.py"
125118
assert agent_init_path.exists()
126119

127-
agent_py_path = agent_folder / "test-agent" / "agent.py"
120+
agent_py_path = agent_folder / "agent.py"
128121
assert agent_py_path.exists()

veadk/cli/cli_create.py

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,8 @@
1616
import shutil
1717
from pathlib import Path
1818

19-
_CONFIG_YAML_TEMPLATE = """\
20-
model:
21-
agent:
22-
name: doubao-seed-1-6-251015
23-
api_key: {ark_api_key}
24-
video:
25-
name: doubao-seedance-1-0-pro-250528
26-
# if you want to use different api_key, just uncomment following line and complete api_key
27-
# api_key:
28-
image:
29-
name: doubao-seedream-4-0-250828
30-
# if you want to use different api_key, just uncomment following line and complete api_key
31-
# api_key:
32-
33-
logging:
34-
# ERROR
35-
# WARNING
36-
# INFO
37-
# DEBUG
38-
level: DEBUG
19+
_ENV_TEMPLATE = """\
20+
MODEL_AGENT_API_KEY={ark_api_key}
3921
"""
4022

4123
_INIT_PY_TEMPLATE = """\
@@ -49,16 +31,17 @@
4931
name="root_agent",
5032
description="A helpful assistant for user questions.",
5133
instruction="Answer user questions to the best of your knowledge",
34+
model_name="doubao-seed-1-6-251015", # <---- you can change your model here
5235
)
5336
"""
5437

5538
_SUCCESS_MSG = """\
56-
Agent '{agent_name}' created successfully at '{agent_folder}':
57-
- config.yaml
58-
- {agent_name}/__init__.py
59-
- {agent_name}/agent.py
39+
Agent created in {agent_folder}:
40+
- .env
41+
- __init__.py
42+
- agent.py
6043
61-
You can run the agent by executing: cd {agent_name} && veadk web
44+
You can run the agent by executing: veadk web
6245
"""
6346

6447

@@ -69,37 +52,34 @@ def _prompt_for_ark_api_key() -> str:
6952
)
7053
click.echo("You have two options:")
7154
click.echo(" 1. Enter the API key now.")
72-
click.echo(" 2. Configure it later in the generated config.yaml file.")
55+
click.echo(" 2. Configure it later in the generated .env file.")
7356
choice = click.prompt("Please select an option", type=click.Choice(["1", "2"]))
7457
if choice == "1":
7558
return click.prompt("Please enter your ARK API key")
7659
else:
77-
click.secho(
78-
"You can set the `api_key` in the config.yaml file later.", fg="yellow"
79-
)
60+
click.secho("You can set the `api_key` in the .env file later.", fg="yellow")
8061
return ""
8162

8263

83-
def _generate_files(agent_name: str, ark_api_key: str, target_dir_path: Path) -> None:
84-
agent_dir_path = target_dir_path / agent_name
85-
agent_dir_path.mkdir(parents=True, exist_ok=True)
86-
config_yaml_path = target_dir_path / "config.yaml"
87-
init_file_path = agent_dir_path / "__init__.py"
88-
agent_file_path = agent_dir_path / "agent.py"
64+
def _generate_files(ark_api_key: str, target_dir_path: Path) -> None:
65+
target_dir_path.mkdir(exist_ok=True)
66+
env_path = target_dir_path / ".env"
67+
init_file_path = target_dir_path / "__init__.py"
68+
agent_file_path = target_dir_path / "agent.py"
8969

90-
config_yaml_content = _CONFIG_YAML_TEMPLATE.format(ark_api_key=ark_api_key)
91-
config_yaml_path.write_text(config_yaml_content)
70+
env_content = _ENV_TEMPLATE.format(ark_api_key=ark_api_key)
71+
env_path.write_text(env_content)
9272
init_file_path.write_text(_INIT_PY_TEMPLATE)
9373
agent_file_path.write_text(_AGENT_PY_TEMPLATE)
9474

9575
click.secho(
96-
_SUCCESS_MSG.format(agent_name=agent_name, agent_folder=target_dir_path),
76+
_SUCCESS_MSG.format(agent_folder=target_dir_path),
9777
fg="green",
9878
)
9979

10080

10181
@click.command()
102-
@click.option("--agent-name", help="The name of the agent.")
82+
@click.argument("agent_name", required=False)
10383
@click.option("--ark-api-key", help="The ARK API key.")
10484
def create(agent_name: str, ark_api_key: str) -> None:
10585
"""Creates a new agent in the current folder with prepopulated agent template."""
@@ -119,4 +99,4 @@ def create(agent_name: str, ark_api_key: str) -> None:
11999
return
120100
shutil.rmtree(target_dir_path)
121101

122-
_generate_files(agent_name, ark_api_key, target_dir_path)
102+
_generate_files(ark_api_key, target_dir_path)

0 commit comments

Comments
 (0)