veadk-python 0.2.27__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- veadk/__init__.py +37 -0
- veadk/a2a/__init__.py +13 -0
- veadk/a2a/agent_card.py +45 -0
- veadk/a2a/remote_ve_agent.py +390 -0
- veadk/a2a/utils/__init__.py +13 -0
- veadk/a2a/utils/agent_to_a2a.py +170 -0
- veadk/a2a/ve_a2a_server.py +93 -0
- veadk/a2a/ve_agent_executor.py +78 -0
- veadk/a2a/ve_middlewares.py +313 -0
- veadk/a2a/ve_task_store.py +37 -0
- veadk/agent.py +402 -0
- veadk/agent_builder.py +93 -0
- veadk/agents/loop_agent.py +68 -0
- veadk/agents/parallel_agent.py +72 -0
- veadk/agents/sequential_agent.py +64 -0
- veadk/auth/__init__.py +13 -0
- veadk/auth/base_auth.py +22 -0
- veadk/auth/ve_credential_service.py +203 -0
- veadk/auth/veauth/__init__.py +13 -0
- veadk/auth/veauth/apmplus_veauth.py +58 -0
- veadk/auth/veauth/ark_veauth.py +75 -0
- veadk/auth/veauth/base_veauth.py +50 -0
- veadk/auth/veauth/cozeloop_veauth.py +13 -0
- veadk/auth/veauth/opensearch_veauth.py +75 -0
- veadk/auth/veauth/postgresql_veauth.py +75 -0
- veadk/auth/veauth/prompt_pilot_veauth.py +60 -0
- veadk/auth/veauth/speech_veauth.py +54 -0
- veadk/auth/veauth/utils.py +69 -0
- veadk/auth/veauth/vesearch_veauth.py +62 -0
- veadk/auth/veauth/viking_mem0_veauth.py +91 -0
- veadk/cli/__init__.py +13 -0
- veadk/cli/cli.py +58 -0
- veadk/cli/cli_clean.py +87 -0
- veadk/cli/cli_create.py +163 -0
- veadk/cli/cli_deploy.py +233 -0
- veadk/cli/cli_eval.py +215 -0
- veadk/cli/cli_init.py +214 -0
- veadk/cli/cli_kb.py +110 -0
- veadk/cli/cli_pipeline.py +285 -0
- veadk/cli/cli_prompt.py +86 -0
- veadk/cli/cli_update.py +106 -0
- veadk/cli/cli_uploadevalset.py +139 -0
- veadk/cli/cli_web.py +143 -0
- veadk/cloud/__init__.py +13 -0
- veadk/cloud/cloud_agent_engine.py +485 -0
- veadk/cloud/cloud_app.py +475 -0
- veadk/config.py +115 -0
- veadk/configs/__init__.py +13 -0
- veadk/configs/auth_configs.py +133 -0
- veadk/configs/database_configs.py +132 -0
- veadk/configs/model_configs.py +78 -0
- veadk/configs/tool_configs.py +54 -0
- veadk/configs/tracing_configs.py +110 -0
- veadk/consts.py +74 -0
- veadk/evaluation/__init__.py +17 -0
- veadk/evaluation/adk_evaluator/__init__.py +17 -0
- veadk/evaluation/adk_evaluator/adk_evaluator.py +302 -0
- veadk/evaluation/base_evaluator.py +642 -0
- veadk/evaluation/deepeval_evaluator/__init__.py +17 -0
- veadk/evaluation/deepeval_evaluator/deepeval_evaluator.py +339 -0
- veadk/evaluation/eval_set_file_loader.py +48 -0
- veadk/evaluation/eval_set_recorder.py +146 -0
- veadk/evaluation/types.py +65 -0
- veadk/evaluation/utils/prometheus.py +196 -0
- veadk/integrations/__init__.py +13 -0
- veadk/integrations/ve_apig/__init__.py +13 -0
- veadk/integrations/ve_apig/ve_apig.py +349 -0
- veadk/integrations/ve_apig/ve_apig_utils.py +332 -0
- veadk/integrations/ve_code_pipeline/__init__.py +13 -0
- veadk/integrations/ve_code_pipeline/ve_code_pipeline.py +431 -0
- veadk/integrations/ve_cozeloop/__init__.py +13 -0
- veadk/integrations/ve_cozeloop/ve_cozeloop.py +96 -0
- veadk/integrations/ve_cr/__init__.py +13 -0
- veadk/integrations/ve_cr/ve_cr.py +220 -0
- veadk/integrations/ve_faas/__init__.py +13 -0
- veadk/integrations/ve_faas/template/cookiecutter.json +15 -0
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/__init__.py +13 -0
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/clean.py +23 -0
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/config.yaml.example +6 -0
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/deploy.py +106 -0
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/__init__.py +13 -0
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/agent.py +25 -0
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/app.py +202 -0
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/requirements.txt +3 -0
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/run.sh +49 -0
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/{{ cookiecutter.app_name }}/__init__.py +14 -0
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/{{ cookiecutter.app_name }}/agent.py +27 -0
- veadk/integrations/ve_faas/ve_faas.py +754 -0
- veadk/integrations/ve_faas/ve_faas_utils.py +408 -0
- veadk/integrations/ve_faas/web_template/cookiecutter.json +20 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/__init__.py +13 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/clean.py +23 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/config.yaml.example +2 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/deploy.py +44 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/Dockerfile +23 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/app.py +123 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/init_db.py +46 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/models.py +36 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/requirements.txt +4 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/run.sh +21 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/static/css/style.css +368 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/static/js/admin.js +0 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/templates/admin/dashboard.html +21 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/templates/admin/edit_post.html +24 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/templates/admin/login.html +21 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/templates/admin/posts.html +53 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/templates/base.html +45 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/templates/index.html +29 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/templates/post.html +14 -0
- veadk/integrations/ve_identity/__init__.py +110 -0
- veadk/integrations/ve_identity/auth_config.py +261 -0
- veadk/integrations/ve_identity/auth_mixins.py +650 -0
- veadk/integrations/ve_identity/auth_processor.py +385 -0
- veadk/integrations/ve_identity/function_tool.py +158 -0
- veadk/integrations/ve_identity/identity_client.py +864 -0
- veadk/integrations/ve_identity/mcp_tool.py +181 -0
- veadk/integrations/ve_identity/mcp_toolset.py +431 -0
- veadk/integrations/ve_identity/models.py +228 -0
- veadk/integrations/ve_identity/token_manager.py +188 -0
- veadk/integrations/ve_identity/utils.py +151 -0
- veadk/integrations/ve_prompt_pilot/__init__.py +13 -0
- veadk/integrations/ve_prompt_pilot/ve_prompt_pilot.py +85 -0
- veadk/integrations/ve_tls/__init__.py +13 -0
- veadk/integrations/ve_tls/utils.py +116 -0
- veadk/integrations/ve_tls/ve_tls.py +212 -0
- veadk/integrations/ve_tos/ve_tos.py +710 -0
- veadk/integrations/ve_viking_db_memory/__init__.py +13 -0
- veadk/integrations/ve_viking_db_memory/ve_viking_db_memory.py +308 -0
- veadk/knowledgebase/__init__.py +17 -0
- veadk/knowledgebase/backends/__init__.py +13 -0
- veadk/knowledgebase/backends/base_backend.py +72 -0
- veadk/knowledgebase/backends/in_memory_backend.py +91 -0
- veadk/knowledgebase/backends/opensearch_backend.py +162 -0
- veadk/knowledgebase/backends/redis_backend.py +172 -0
- veadk/knowledgebase/backends/utils.py +92 -0
- veadk/knowledgebase/backends/vikingdb_knowledge_backend.py +608 -0
- veadk/knowledgebase/entry.py +25 -0
- veadk/knowledgebase/knowledgebase.py +307 -0
- veadk/memory/__init__.py +35 -0
- veadk/memory/long_term_memory.py +365 -0
- veadk/memory/long_term_memory_backends/__init__.py +13 -0
- veadk/memory/long_term_memory_backends/base_backend.py +35 -0
- veadk/memory/long_term_memory_backends/in_memory_backend.py +67 -0
- veadk/memory/long_term_memory_backends/mem0_backend.py +155 -0
- veadk/memory/long_term_memory_backends/opensearch_backend.py +124 -0
- veadk/memory/long_term_memory_backends/redis_backend.py +140 -0
- veadk/memory/long_term_memory_backends/vikingdb_memory_backend.py +189 -0
- veadk/memory/short_term_memory.py +252 -0
- veadk/memory/short_term_memory_backends/__init__.py +13 -0
- veadk/memory/short_term_memory_backends/base_backend.py +31 -0
- veadk/memory/short_term_memory_backends/mysql_backend.py +49 -0
- veadk/memory/short_term_memory_backends/postgresql_backend.py +49 -0
- veadk/memory/short_term_memory_backends/sqlite_backend.py +55 -0
- veadk/memory/short_term_memory_processor.py +100 -0
- veadk/processors/__init__.py +26 -0
- veadk/processors/base_run_processor.py +120 -0
- veadk/prompts/__init__.py +13 -0
- veadk/prompts/agent_default_prompt.py +30 -0
- veadk/prompts/prompt_evaluator.py +20 -0
- veadk/prompts/prompt_memory_processor.py +55 -0
- veadk/prompts/prompt_optimization.py +150 -0
- veadk/runner.py +732 -0
- veadk/tools/__init__.py +13 -0
- veadk/tools/builtin_tools/__init__.py +13 -0
- veadk/tools/builtin_tools/agent_authorization.py +94 -0
- veadk/tools/builtin_tools/generate_image.py +23 -0
- veadk/tools/builtin_tools/image_edit.py +300 -0
- veadk/tools/builtin_tools/image_generate.py +446 -0
- veadk/tools/builtin_tools/lark.py +67 -0
- veadk/tools/builtin_tools/las.py +24 -0
- veadk/tools/builtin_tools/link_reader.py +66 -0
- veadk/tools/builtin_tools/llm_shield.py +381 -0
- veadk/tools/builtin_tools/load_knowledgebase.py +97 -0
- veadk/tools/builtin_tools/mcp_router.py +29 -0
- veadk/tools/builtin_tools/run_code.py +113 -0
- veadk/tools/builtin_tools/tts.py +253 -0
- veadk/tools/builtin_tools/vesearch.py +49 -0
- veadk/tools/builtin_tools/video_generate.py +363 -0
- veadk/tools/builtin_tools/web_scraper.py +76 -0
- veadk/tools/builtin_tools/web_search.py +83 -0
- veadk/tools/demo_tools.py +58 -0
- veadk/tools/load_knowledgebase_tool.py +149 -0
- veadk/tools/sandbox/__init__.py +13 -0
- veadk/tools/sandbox/browser_sandbox.py +37 -0
- veadk/tools/sandbox/code_sandbox.py +40 -0
- veadk/tools/sandbox/computer_sandbox.py +34 -0
- veadk/tracing/__init__.py +13 -0
- veadk/tracing/base_tracer.py +58 -0
- veadk/tracing/telemetry/__init__.py +13 -0
- veadk/tracing/telemetry/attributes/attributes.py +29 -0
- veadk/tracing/telemetry/attributes/extractors/common_attributes_extractors.py +180 -0
- veadk/tracing/telemetry/attributes/extractors/llm_attributes_extractors.py +858 -0
- veadk/tracing/telemetry/attributes/extractors/tool_attributes_extractors.py +152 -0
- veadk/tracing/telemetry/attributes/extractors/types.py +164 -0
- veadk/tracing/telemetry/exporters/__init__.py +13 -0
- veadk/tracing/telemetry/exporters/apmplus_exporter.py +558 -0
- veadk/tracing/telemetry/exporters/base_exporter.py +39 -0
- veadk/tracing/telemetry/exporters/cozeloop_exporter.py +129 -0
- veadk/tracing/telemetry/exporters/inmemory_exporter.py +248 -0
- veadk/tracing/telemetry/exporters/tls_exporter.py +139 -0
- veadk/tracing/telemetry/opentelemetry_tracer.py +320 -0
- veadk/tracing/telemetry/telemetry.py +411 -0
- veadk/types.py +47 -0
- veadk/utils/__init__.py +13 -0
- veadk/utils/audio_manager.py +95 -0
- veadk/utils/auth.py +294 -0
- veadk/utils/logger.py +59 -0
- veadk/utils/mcp_utils.py +44 -0
- veadk/utils/misc.py +184 -0
- veadk/utils/patches.py +101 -0
- veadk/utils/volcengine_sign.py +205 -0
- veadk/version.py +15 -0
- veadk_python-0.2.27.dist-info/METADATA +373 -0
- veadk_python-0.2.27.dist-info/RECORD +218 -0
- veadk_python-0.2.27.dist-info/WHEEL +5 -0
- veadk_python-0.2.27.dist-info/entry_points.txt +2 -0
- veadk_python-0.2.27.dist-info/licenses/LICENSE +201 -0
- veadk_python-0.2.27.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import os
|
|
16
|
+
|
|
17
|
+
from typing_extensions import override
|
|
18
|
+
|
|
19
|
+
from veadk.auth.veauth.base_veauth import BaseVeAuth
|
|
20
|
+
from veadk.utils.logger import get_logger
|
|
21
|
+
from veadk.utils.volcengine_sign import ve_request
|
|
22
|
+
|
|
23
|
+
logger = get_logger(__name__)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class PromptPilotVeAuth(BaseVeAuth):
|
|
27
|
+
def __init__(
|
|
28
|
+
self,
|
|
29
|
+
access_key: str = os.getenv("VOLCENGINE_ACCESS_KEY", ""),
|
|
30
|
+
secret_key: str = os.getenv("VOLCENGINE_SECRET_KEY", ""),
|
|
31
|
+
) -> None:
|
|
32
|
+
super().__init__(access_key, secret_key)
|
|
33
|
+
|
|
34
|
+
self._token: str = ""
|
|
35
|
+
|
|
36
|
+
@override
|
|
37
|
+
def _fetch_token(self) -> None:
|
|
38
|
+
logger.info("Fetching Prompt Pilot token...")
|
|
39
|
+
|
|
40
|
+
res = ve_request(
|
|
41
|
+
request_body={},
|
|
42
|
+
action="GetOrCreatePromptPilotAPIKeys",
|
|
43
|
+
ak=self.access_key,
|
|
44
|
+
sk=self.secret_key,
|
|
45
|
+
service="ark",
|
|
46
|
+
version="2024-01-01",
|
|
47
|
+
region="cn-beijing",
|
|
48
|
+
host="open.volcengineapi.com",
|
|
49
|
+
)
|
|
50
|
+
try:
|
|
51
|
+
self._token = res["Result"]["APIKeys"][0]["APIKey"]
|
|
52
|
+
except KeyError:
|
|
53
|
+
raise ValueError(f"Failed to get Prompt Pilot token: {res}")
|
|
54
|
+
|
|
55
|
+
@property
|
|
56
|
+
def token(self) -> str:
|
|
57
|
+
if self._token:
|
|
58
|
+
return self._token
|
|
59
|
+
self._fetch_token()
|
|
60
|
+
return self._token
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import os
|
|
16
|
+
|
|
17
|
+
from veadk.auth.veauth.utils import get_credential_from_vefaas_iam
|
|
18
|
+
from veadk.utils.logger import get_logger
|
|
19
|
+
from veadk.utils.volcengine_sign import ve_request
|
|
20
|
+
|
|
21
|
+
logger = get_logger(__name__)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def get_speech_token(region: str = "cn-beijing") -> str:
|
|
25
|
+
logger.info("Fetching speech token...")
|
|
26
|
+
|
|
27
|
+
access_key = os.getenv("VOLCENGINE_ACCESS_KEY")
|
|
28
|
+
secret_key = os.getenv("VOLCENGINE_SECRET_KEY")
|
|
29
|
+
session_token = ""
|
|
30
|
+
|
|
31
|
+
if not (access_key and secret_key):
|
|
32
|
+
# try to get from vefaas iam
|
|
33
|
+
cred = get_credential_from_vefaas_iam()
|
|
34
|
+
access_key = cred.access_key_id
|
|
35
|
+
secret_key = cred.secret_access_key
|
|
36
|
+
session_token = cred.session_token
|
|
37
|
+
|
|
38
|
+
res = ve_request(
|
|
39
|
+
request_body={"ProjectName": "default", "OnlyAvailable": True},
|
|
40
|
+
header={"X-Security-Token": session_token},
|
|
41
|
+
action="ListAPIKeys",
|
|
42
|
+
ak=access_key,
|
|
43
|
+
sk=secret_key,
|
|
44
|
+
service="speech_saas_prod",
|
|
45
|
+
version="2025-05-20",
|
|
46
|
+
region=region,
|
|
47
|
+
host="open.volcengineapi.com",
|
|
48
|
+
)
|
|
49
|
+
try:
|
|
50
|
+
first_api_key_id = res["Result"]["APIKeys"][0]["APIKey"]
|
|
51
|
+
logger.info("Successfully fetching speech API Key.")
|
|
52
|
+
return first_api_key_id
|
|
53
|
+
except KeyError:
|
|
54
|
+
raise ValueError(f"Failed to get speech api key list: {res}")
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import json
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
from pydantic import BaseModel
|
|
19
|
+
|
|
20
|
+
from veadk.consts import VEFAAS_IAM_CRIDENTIAL_PATH
|
|
21
|
+
from veadk.utils.logger import get_logger
|
|
22
|
+
|
|
23
|
+
logger = get_logger(__name__)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class VeIAMCredential(BaseModel):
|
|
27
|
+
access_key_id: str
|
|
28
|
+
secret_access_key: str
|
|
29
|
+
session_token: str
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def get_credential_from_vefaas_iam() -> VeIAMCredential:
|
|
33
|
+
"""Get credential from VeFaaS IAM file"""
|
|
34
|
+
logger.info(
|
|
35
|
+
f"Get Volcegnine access key or secret key from environment variables failed, try to get from VeFaaS IAM file (path={VEFAAS_IAM_CRIDENTIAL_PATH})."
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
path = Path(VEFAAS_IAM_CRIDENTIAL_PATH)
|
|
39
|
+
|
|
40
|
+
if not path.exists():
|
|
41
|
+
logger.error(
|
|
42
|
+
f"Get Volcegnine access key or secret key from environment variables failed, and VeFaaS IAM file (path={VEFAAS_IAM_CRIDENTIAL_PATH}) not exists. Please check your configuration."
|
|
43
|
+
)
|
|
44
|
+
raise FileNotFoundError(
|
|
45
|
+
f"Get Volcegnine access key or secret key from environment variables failed, and VeFaaS IAM file (path={VEFAAS_IAM_CRIDENTIAL_PATH}) not exists. Please check your configuration."
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
with open(VEFAAS_IAM_CRIDENTIAL_PATH, "r") as f:
|
|
49
|
+
cred_dict = json.load(f)
|
|
50
|
+
access_key = cred_dict["access_key_id"]
|
|
51
|
+
secret_key = cred_dict["secret_access_key"]
|
|
52
|
+
session_token = cred_dict["session_token"]
|
|
53
|
+
|
|
54
|
+
logger.info("Get credential from IAM file successfully.")
|
|
55
|
+
|
|
56
|
+
return VeIAMCredential(
|
|
57
|
+
access_key_id=access_key,
|
|
58
|
+
secret_access_key=secret_key,
|
|
59
|
+
session_token=session_token,
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def refresh_ak_sk(access_key: str, secret_key: str) -> VeIAMCredential:
|
|
64
|
+
if access_key and secret_key:
|
|
65
|
+
return VeIAMCredential(
|
|
66
|
+
access_key_id=access_key, secret_access_key=secret_key, session_token=""
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
return get_credential_from_vefaas_iam()
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import os
|
|
16
|
+
|
|
17
|
+
from typing_extensions import override
|
|
18
|
+
|
|
19
|
+
from veadk.auth.veauth.base_veauth import BaseVeAuth
|
|
20
|
+
from veadk.utils.logger import get_logger
|
|
21
|
+
from veadk.utils.volcengine_sign import ve_request
|
|
22
|
+
|
|
23
|
+
logger = get_logger(__name__)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class VesearchVeAuth(BaseVeAuth):
|
|
27
|
+
def __init__(
|
|
28
|
+
self,
|
|
29
|
+
access_key: str = os.getenv("VOLCENGINE_ACCESS_KEY", ""),
|
|
30
|
+
secret_key: str = os.getenv("VOLCENGINE_SECRET_KEY", ""),
|
|
31
|
+
) -> None:
|
|
32
|
+
super().__init__(access_key, secret_key)
|
|
33
|
+
|
|
34
|
+
self._token: str = ""
|
|
35
|
+
|
|
36
|
+
@override
|
|
37
|
+
def _fetch_token(self):
|
|
38
|
+
logger.info("Fetching VeSearch token ...")
|
|
39
|
+
|
|
40
|
+
res = ve_request(
|
|
41
|
+
request_body={"biz_scene": "search_agent", "page": 1, "rows": 10},
|
|
42
|
+
action="ListAPIKeys",
|
|
43
|
+
ak=self.access_key,
|
|
44
|
+
sk=self.secret_key,
|
|
45
|
+
service="content_customization",
|
|
46
|
+
version="2025-01-01",
|
|
47
|
+
region="cn-beijing",
|
|
48
|
+
host="open.volcengineapi.com",
|
|
49
|
+
)
|
|
50
|
+
try:
|
|
51
|
+
self._token = res["Result"]["api_key_vos"][0]["api_key"]
|
|
52
|
+
|
|
53
|
+
logger.info("Fetching VeSearch token done.")
|
|
54
|
+
except KeyError:
|
|
55
|
+
raise ValueError(f"Failed to get VeSearch token: {res}")
|
|
56
|
+
|
|
57
|
+
@property
|
|
58
|
+
def token(self) -> str:
|
|
59
|
+
if self._token:
|
|
60
|
+
return self._token
|
|
61
|
+
self._fetch_token()
|
|
62
|
+
return self._token
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import os
|
|
16
|
+
|
|
17
|
+
from veadk.auth.veauth.utils import get_credential_from_vefaas_iam
|
|
18
|
+
from veadk.utils.logger import get_logger
|
|
19
|
+
from veadk.utils.volcengine_sign import ve_request
|
|
20
|
+
|
|
21
|
+
logger = get_logger(__name__)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _get_api_key_id_by_project_id(
|
|
25
|
+
project_id: str, access_key: str, secret_key: str, session_token: str, region: str
|
|
26
|
+
):
|
|
27
|
+
res = ve_request(
|
|
28
|
+
request_body={"MemoryProjectId": project_id},
|
|
29
|
+
header={"X-Security-Token": session_token},
|
|
30
|
+
action="DescribeMemoryProjectDetail",
|
|
31
|
+
ak=access_key,
|
|
32
|
+
sk=secret_key,
|
|
33
|
+
service="mem0",
|
|
34
|
+
version="2025-10-10",
|
|
35
|
+
region=region,
|
|
36
|
+
host="open.volcengineapi.com",
|
|
37
|
+
)
|
|
38
|
+
try:
|
|
39
|
+
api_key_id = res["Result"]["APIKeyInfos"]["APIKeyId"]
|
|
40
|
+
except KeyError:
|
|
41
|
+
raise ValueError(f"Failed to get mem0 api key id: {res}")
|
|
42
|
+
|
|
43
|
+
return api_key_id
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _get_api_key_by_api_key_id(
|
|
47
|
+
api_key_id: str, access_key: str, secret_key: str, session_token: str, region: str
|
|
48
|
+
) -> str:
|
|
49
|
+
res = ve_request(
|
|
50
|
+
request_body={"APIKeyId": api_key_id},
|
|
51
|
+
header={"X-Security-Token": session_token},
|
|
52
|
+
action="DescribeAPIKeyDetail",
|
|
53
|
+
ak=access_key,
|
|
54
|
+
sk=secret_key,
|
|
55
|
+
service="mem0",
|
|
56
|
+
version="2025-10-10",
|
|
57
|
+
region=region,
|
|
58
|
+
host="open.volcengineapi.com",
|
|
59
|
+
)
|
|
60
|
+
try:
|
|
61
|
+
api_key = res["Result"]["APIKeyValue"]
|
|
62
|
+
except KeyError:
|
|
63
|
+
raise ValueError(f"Failed to get mem0 api key: {res}")
|
|
64
|
+
|
|
65
|
+
return api_key
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def get_viking_mem0_token(
|
|
69
|
+
api_key_id: str, memory_project_id: str, region: str = "cn-beijing"
|
|
70
|
+
) -> str:
|
|
71
|
+
logger.info("Fetching Viking mem0 token...")
|
|
72
|
+
|
|
73
|
+
access_key = os.getenv("VOLCENGINE_ACCESS_KEY")
|
|
74
|
+
secret_key = os.getenv("VOLCENGINE_SECRET_KEY")
|
|
75
|
+
session_token = ""
|
|
76
|
+
|
|
77
|
+
if not (access_key and secret_key):
|
|
78
|
+
# try to get from vefaas iam
|
|
79
|
+
cred = get_credential_from_vefaas_iam()
|
|
80
|
+
access_key = cred.access_key_id
|
|
81
|
+
secret_key = cred.secret_access_key
|
|
82
|
+
session_token = cred.session_token
|
|
83
|
+
|
|
84
|
+
if not api_key_id:
|
|
85
|
+
api_key_id = _get_api_key_id_by_project_id(
|
|
86
|
+
memory_project_id, access_key, secret_key, session_token, region
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
return _get_api_key_by_api_key_id(
|
|
90
|
+
api_key_id, access_key, secret_key, session_token, region
|
|
91
|
+
)
|
veadk/cli/__init__.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
veadk/cli/cli.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
import click
|
|
17
|
+
|
|
18
|
+
from veadk.cli.cli_deploy import deploy
|
|
19
|
+
from veadk.cli.cli_eval import eval
|
|
20
|
+
from veadk.cli.cli_init import init
|
|
21
|
+
from veadk.cli.cli_create import create
|
|
22
|
+
from veadk.cli.cli_kb import kb
|
|
23
|
+
from veadk.cli.cli_pipeline import pipeline
|
|
24
|
+
from veadk.cli.cli_prompt import prompt
|
|
25
|
+
from veadk.cli.cli_web import web
|
|
26
|
+
from veadk.cli.cli_uploadevalset import uploadevalset
|
|
27
|
+
from veadk.cli.cli_update import update
|
|
28
|
+
from veadk.cli.cli_clean import clean
|
|
29
|
+
from veadk.version import VERSION
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@click.group()
|
|
33
|
+
@click.version_option(
|
|
34
|
+
version=VERSION, prog_name="Volcengine Agent Development Kit (VeADK)"
|
|
35
|
+
)
|
|
36
|
+
def veadk():
|
|
37
|
+
"""Volcengine Agent Development Kit (VeADK) command line interface.
|
|
38
|
+
|
|
39
|
+
This is the main entry point for all VeADK CLI commands. VeADK provides
|
|
40
|
+
tools for developing, deploying, and managing AI agents on the Volcengine platform.
|
|
41
|
+
"""
|
|
42
|
+
pass
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
veadk.add_command(deploy)
|
|
46
|
+
veadk.add_command(init)
|
|
47
|
+
veadk.add_command(create)
|
|
48
|
+
veadk.add_command(prompt)
|
|
49
|
+
veadk.add_command(web)
|
|
50
|
+
veadk.add_command(pipeline)
|
|
51
|
+
veadk.add_command(eval)
|
|
52
|
+
veadk.add_command(kb)
|
|
53
|
+
veadk.add_command(uploadevalset)
|
|
54
|
+
veadk.add_command(update)
|
|
55
|
+
veadk.add_command(clean)
|
|
56
|
+
|
|
57
|
+
if __name__ == "__main__":
|
|
58
|
+
veadk()
|
veadk/cli/cli_clean.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import time
|
|
16
|
+
import click
|
|
17
|
+
|
|
18
|
+
from veadk.config import getenv
|
|
19
|
+
from veadk.integrations.ve_faas.ve_faas import VeFaaS
|
|
20
|
+
from veadk.utils.logger import get_logger
|
|
21
|
+
|
|
22
|
+
logger = get_logger(__name__)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@click.command()
|
|
26
|
+
@click.option(
|
|
27
|
+
"--vefaas-app-name",
|
|
28
|
+
required=True,
|
|
29
|
+
help="VeFaaS application name to clean",
|
|
30
|
+
)
|
|
31
|
+
@click.option(
|
|
32
|
+
"--volcengine-access-key",
|
|
33
|
+
default=None,
|
|
34
|
+
help="Volcengine access key, if not set, will use the value of environment variable VOLCENGINE_ACCESS_KEY",
|
|
35
|
+
)
|
|
36
|
+
@click.option(
|
|
37
|
+
"--volcengine-secret-key",
|
|
38
|
+
default=None,
|
|
39
|
+
help="Volcengine secret key, if not set, will use the value of environment variable VOLCENGINE_SECRET_KEY",
|
|
40
|
+
)
|
|
41
|
+
def clean(
|
|
42
|
+
vefaas_app_name: str, volcengine_access_key: str, volcengine_secret_key: str
|
|
43
|
+
) -> None:
|
|
44
|
+
"""
|
|
45
|
+
Clean and delete a VeFaaS application from the cloud.
|
|
46
|
+
|
|
47
|
+
This command deletes a specified VeFaaS application after user confirmation.
|
|
48
|
+
It will prompt the user for confirmation before proceeding with the deletion
|
|
49
|
+
and monitor the deletion process until completion.
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
vefaas_app_name (str): The name of the VeFaaS application to delete
|
|
53
|
+
volcengine_access_key (str): Volcengine access key for authentication.
|
|
54
|
+
If None, will use VOLCENGINE_ACCESS_KEY environment variable
|
|
55
|
+
volcengine_secret_key (str): Volcengine secret key for authentication.
|
|
56
|
+
If None, will use VOLCENGINE_SECRET_KEY environment variable
|
|
57
|
+
|
|
58
|
+
Returns:
|
|
59
|
+
None
|
|
60
|
+
"""
|
|
61
|
+
if not volcengine_access_key:
|
|
62
|
+
volcengine_access_key = getenv("VOLCENGINE_ACCESS_KEY")
|
|
63
|
+
if not volcengine_secret_key:
|
|
64
|
+
volcengine_secret_key = getenv("VOLCENGINE_SECRET_KEY")
|
|
65
|
+
|
|
66
|
+
confirm = input(f"Confirm delete cloud app {vefaas_app_name}? (y/N): ")
|
|
67
|
+
if confirm.lower() != "y":
|
|
68
|
+
click.echo("Delete cancelled.")
|
|
69
|
+
return
|
|
70
|
+
else:
|
|
71
|
+
vefaas_client = VeFaaS(
|
|
72
|
+
access_key=volcengine_access_key, secret_key=volcengine_secret_key
|
|
73
|
+
)
|
|
74
|
+
vefaas_application_id = vefaas_client.find_app_id_by_name(vefaas_app_name)
|
|
75
|
+
vefaas_client.delete(vefaas_application_id)
|
|
76
|
+
click.echo(
|
|
77
|
+
f"Cloud app {vefaas_app_name} delete request has been sent to VeFaaS"
|
|
78
|
+
)
|
|
79
|
+
while True:
|
|
80
|
+
try:
|
|
81
|
+
id = vefaas_client.find_app_id_by_name(vefaas_app_name)
|
|
82
|
+
if not id:
|
|
83
|
+
break
|
|
84
|
+
time.sleep(3)
|
|
85
|
+
except Exception as _:
|
|
86
|
+
break
|
|
87
|
+
click.echo("Delete application done.")
|
veadk/cli/cli_create.py
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import click
|
|
16
|
+
import shutil
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
|
|
19
|
+
_ENV_TEMPLATE = """\
|
|
20
|
+
MODEL_AGENT_API_KEY={ark_api_key}
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
_INIT_PY_TEMPLATE = """\
|
|
24
|
+
from . import agent
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
_AGENT_PY_TEMPLATE = """\
|
|
28
|
+
from veadk import Agent
|
|
29
|
+
|
|
30
|
+
root_agent = Agent(
|
|
31
|
+
name="root_agent",
|
|
32
|
+
description="A helpful assistant for user questions.",
|
|
33
|
+
instruction="Answer user questions to the best of your knowledge",
|
|
34
|
+
model_name="doubao-seed-1-6-251015", # <---- you can change your model here
|
|
35
|
+
)
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
_SUCCESS_MSG = """\
|
|
39
|
+
Agent created in {agent_folder}:
|
|
40
|
+
- .env
|
|
41
|
+
- __init__.py
|
|
42
|
+
- agent.py
|
|
43
|
+
|
|
44
|
+
You can run the agent by executing: veadk web
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _prompt_for_ark_api_key() -> str:
|
|
49
|
+
"""Prompt user to enter ARK API key with guidance and options.
|
|
50
|
+
|
|
51
|
+
Displays instructions for obtaining an ARK API key and provides the user
|
|
52
|
+
with two options: enter the key immediately or configure it later in the
|
|
53
|
+
generated .env file. Includes helpful documentation links and clear choices.
|
|
54
|
+
|
|
55
|
+
Returns:
|
|
56
|
+
str: The ARK API key entered by the user, or empty string if they
|
|
57
|
+
choose to configure it later
|
|
58
|
+
"""
|
|
59
|
+
click.secho(
|
|
60
|
+
"An API key is required to run the agent. See https://www.volcengine.com/docs/82379/1541594 for details.",
|
|
61
|
+
fg="green",
|
|
62
|
+
)
|
|
63
|
+
click.echo("You have two options:")
|
|
64
|
+
click.echo(" 1. Enter the API key now.")
|
|
65
|
+
click.echo(" 2. Configure it later in the generated .env file.")
|
|
66
|
+
choice = click.prompt("Please select an option", type=click.Choice(["1", "2"]))
|
|
67
|
+
if choice == "1":
|
|
68
|
+
return click.prompt("Please enter your ARK API key")
|
|
69
|
+
else:
|
|
70
|
+
click.secho("You can set the `api_key` in the .env file later.", fg="yellow")
|
|
71
|
+
return ""
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _generate_files(ark_api_key: str, target_dir_path: Path) -> None:
|
|
75
|
+
"""Generate agent project files from templates in the target directory.
|
|
76
|
+
|
|
77
|
+
Creates the essential files for a new VeADK agent project including
|
|
78
|
+
environment configuration, Python package initialization, and the main
|
|
79
|
+
agent definition file. Uses predefined templates to ensure consistent
|
|
80
|
+
project structure and proper configuration.
|
|
81
|
+
|
|
82
|
+
Args:
|
|
83
|
+
ark_api_key: ARK API key to be written to the .env file for
|
|
84
|
+
model authentication. Can be empty string if not provided
|
|
85
|
+
target_dir_path: Path object pointing to the target directory
|
|
86
|
+
where files should be created
|
|
87
|
+
|
|
88
|
+
Files Created:
|
|
89
|
+
- .env: Environment file with ARK API key configuration
|
|
90
|
+
- __init__.py: Python package initialization file
|
|
91
|
+
- agent.py: Main agent definition with default configuration
|
|
92
|
+
|
|
93
|
+
Note:
|
|
94
|
+
- Creates target directory if it doesn't exist
|
|
95
|
+
- Overwrites existing files without warning
|
|
96
|
+
- Uses template formatting to inject API key into .env file
|
|
97
|
+
- Displays success message with project location after completion
|
|
98
|
+
"""
|
|
99
|
+
target_dir_path.mkdir(exist_ok=True)
|
|
100
|
+
env_path = target_dir_path / ".env"
|
|
101
|
+
init_file_path = target_dir_path / "__init__.py"
|
|
102
|
+
agent_file_path = target_dir_path / "agent.py"
|
|
103
|
+
|
|
104
|
+
env_content = _ENV_TEMPLATE.format(ark_api_key=ark_api_key)
|
|
105
|
+
env_path.write_text(env_content)
|
|
106
|
+
init_file_path.write_text(_INIT_PY_TEMPLATE)
|
|
107
|
+
agent_file_path.write_text(_AGENT_PY_TEMPLATE)
|
|
108
|
+
|
|
109
|
+
click.secho(
|
|
110
|
+
_SUCCESS_MSG.format(agent_folder=target_dir_path),
|
|
111
|
+
fg="green",
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
@click.command()
|
|
116
|
+
@click.argument("agent_name", required=False)
|
|
117
|
+
@click.option("--ark-api-key", help="The ARK API key.")
|
|
118
|
+
def create(agent_name: str, ark_api_key: str) -> None:
|
|
119
|
+
"""Create a new VeADK agent project with prepopulated template files.
|
|
120
|
+
|
|
121
|
+
This command creates a new agent project directory with all necessary
|
|
122
|
+
files to get started with VeADK agent development. It sets up a complete
|
|
123
|
+
project structure including environment configuration, agent definition,
|
|
124
|
+
and package initialization.
|
|
125
|
+
|
|
126
|
+
The command handles interactive prompts for missing parameters and provides
|
|
127
|
+
safety checks for existing directories to prevent accidental overwrites.
|
|
128
|
+
|
|
129
|
+
Project Structure Created:
|
|
130
|
+
agent_name/
|
|
131
|
+
├── .env # Environment configuration with API key
|
|
132
|
+
├── __init__.py # Python package initialization
|
|
133
|
+
└── agent.py # Main agent definition with default settings
|
|
134
|
+
|
|
135
|
+
Args:
|
|
136
|
+
agent_name: Name of the agent and directory to create. If not provided
|
|
137
|
+
as an argument, the user will be prompted to enter it interactively
|
|
138
|
+
ark_api_key: ARK API key for model authentication. If not provided,
|
|
139
|
+
the user will be prompted with options to enter it or configure later
|
|
140
|
+
|
|
141
|
+
Note:
|
|
142
|
+
- Agent name becomes both the directory name and project identifier
|
|
143
|
+
- API key can be configured later by editing the .env file
|
|
144
|
+
- Generated agent is immediately runnable with 'veadk web' command
|
|
145
|
+
- Template includes comments guiding users to customize model settings
|
|
146
|
+
"""
|
|
147
|
+
if not agent_name:
|
|
148
|
+
agent_name = click.prompt("Enter the agent name")
|
|
149
|
+
if not ark_api_key:
|
|
150
|
+
ark_api_key = _prompt_for_ark_api_key()
|
|
151
|
+
|
|
152
|
+
cwd = Path.cwd()
|
|
153
|
+
target_dir_path = cwd / agent_name
|
|
154
|
+
|
|
155
|
+
if target_dir_path.exists() and any(target_dir_path.iterdir()):
|
|
156
|
+
if not click.confirm(
|
|
157
|
+
f"Directory '{target_dir_path}' already exists and is not empty. Do you want to overwrite it?"
|
|
158
|
+
):
|
|
159
|
+
click.secho("Operation cancelled.", fg="red")
|
|
160
|
+
return
|
|
161
|
+
shutil.rmtree(target_dir_path)
|
|
162
|
+
|
|
163
|
+
_generate_files(ark_api_key, target_dir_path)
|