veadk-python 0.2.16__py3-none-any.whl → 0.2.17__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.
Files changed (64) hide show
  1. veadk/a2a/remote_ve_agent.py +56 -1
  2. veadk/agent.py +79 -26
  3. veadk/agents/loop_agent.py +22 -9
  4. veadk/agents/parallel_agent.py +21 -9
  5. veadk/agents/sequential_agent.py +18 -9
  6. veadk/auth/veauth/apmplus_veauth.py +32 -39
  7. veadk/auth/veauth/ark_veauth.py +3 -1
  8. veadk/auth/veauth/utils.py +12 -0
  9. veadk/auth/veauth/viking_mem0_veauth.py +91 -0
  10. veadk/cli/cli.py +5 -1
  11. veadk/cli/cli_create.py +62 -1
  12. veadk/cli/cli_deploy.py +36 -1
  13. veadk/cli/cli_eval.py +55 -0
  14. veadk/cli/cli_init.py +44 -3
  15. veadk/cli/cli_kb.py +36 -1
  16. veadk/cli/cli_pipeline.py +66 -1
  17. veadk/cli/cli_prompt.py +16 -1
  18. veadk/cli/cli_uploadevalset.py +15 -1
  19. veadk/cli/cli_web.py +35 -4
  20. veadk/cloud/cloud_agent_engine.py +142 -25
  21. veadk/cloud/cloud_app.py +219 -12
  22. veadk/configs/database_configs.py +4 -0
  23. veadk/configs/model_configs.py +5 -1
  24. veadk/configs/tracing_configs.py +2 -2
  25. veadk/evaluation/adk_evaluator/adk_evaluator.py +77 -17
  26. veadk/evaluation/base_evaluator.py +219 -3
  27. veadk/evaluation/deepeval_evaluator/deepeval_evaluator.py +116 -1
  28. veadk/evaluation/eval_set_file_loader.py +20 -0
  29. veadk/evaluation/eval_set_recorder.py +54 -0
  30. veadk/evaluation/types.py +32 -0
  31. veadk/evaluation/utils/prometheus.py +61 -0
  32. veadk/knowledgebase/backends/base_backend.py +14 -1
  33. veadk/knowledgebase/backends/in_memory_backend.py +10 -1
  34. veadk/knowledgebase/backends/opensearch_backend.py +26 -0
  35. veadk/knowledgebase/backends/redis_backend.py +29 -2
  36. veadk/knowledgebase/backends/vikingdb_knowledge_backend.py +43 -5
  37. veadk/knowledgebase/knowledgebase.py +173 -12
  38. veadk/memory/long_term_memory.py +148 -4
  39. veadk/memory/long_term_memory_backends/mem0_backend.py +11 -0
  40. veadk/memory/short_term_memory.py +119 -5
  41. veadk/runner.py +412 -1
  42. veadk/tools/builtin_tools/llm_shield.py +381 -0
  43. veadk/tools/builtin_tools/mcp_router.py +9 -2
  44. veadk/tools/builtin_tools/run_code.py +25 -5
  45. veadk/tools/builtin_tools/web_search.py +38 -154
  46. veadk/tracing/base_tracer.py +28 -1
  47. veadk/tracing/telemetry/attributes/extractors/common_attributes_extractors.py +105 -1
  48. veadk/tracing/telemetry/attributes/extractors/llm_attributes_extractors.py +260 -0
  49. veadk/tracing/telemetry/attributes/extractors/tool_attributes_extractors.py +69 -0
  50. veadk/tracing/telemetry/attributes/extractors/types.py +78 -0
  51. veadk/tracing/telemetry/exporters/apmplus_exporter.py +157 -0
  52. veadk/tracing/telemetry/exporters/base_exporter.py +8 -0
  53. veadk/tracing/telemetry/exporters/cozeloop_exporter.py +60 -1
  54. veadk/tracing/telemetry/exporters/inmemory_exporter.py +118 -1
  55. veadk/tracing/telemetry/exporters/tls_exporter.py +66 -0
  56. veadk/tracing/telemetry/opentelemetry_tracer.py +111 -1
  57. veadk/tracing/telemetry/telemetry.py +118 -2
  58. veadk/version.py +1 -1
  59. {veadk_python-0.2.16.dist-info → veadk_python-0.2.17.dist-info}/METADATA +1 -1
  60. {veadk_python-0.2.16.dist-info → veadk_python-0.2.17.dist-info}/RECORD +64 -62
  61. {veadk_python-0.2.16.dist-info → veadk_python-0.2.17.dist-info}/WHEEL +0 -0
  62. {veadk_python-0.2.16.dist-info → veadk_python-0.2.17.dist-info}/entry_points.txt +0 -0
  63. {veadk_python-0.2.16.dist-info → veadk_python-0.2.17.dist-info}/licenses/LICENSE +0 -0
  64. {veadk_python-0.2.16.dist-info → veadk_python-0.2.17.dist-info}/top_level.txt +0 -0
veadk/cli/cli_deploy.py CHANGED
@@ -62,7 +62,42 @@ def deploy(
62
62
  use_adk_web: bool,
63
63
  path: str,
64
64
  ) -> None:
65
- """Deploy a user project to Volcengine FaaS application."""
65
+ """Deploy a user project to Volcengine FaaS application.
66
+
67
+ This command deploys a VeADK agent project to Volcengine's Function as a Service (FaaS)
68
+ platform. It creates a deployment package from the local project, configures the necessary
69
+ cloud resources, and manages the deployment process including template generation,
70
+ file copying, and cloud resource provisioning.
71
+
72
+ The deployment process includes:
73
+ 1. Creating a temporary deployment package using cookiecutter templates
74
+ 2. Copying the user's project files to the deployment structure
75
+ 3. Processing configuration files and requirements
76
+ 4. Executing the deployment to Volcengine FaaS
77
+ 5. Cleaning up temporary files
78
+
79
+ Args:
80
+ access_key: Volcengine access key for API authentication. If not provided,
81
+ will use VOLCENGINE_ACCESS_KEY environment variable
82
+ secret_key: Volcengine secret key for API authentication. If not provided,
83
+ will use VOLCENGINE_SECRET_KEY environment variable
84
+ vefaas_app_name: Name of the target Volcengine FaaS application where the
85
+ project will be deployed
86
+ veapig_instance_name: Optional Volcengine API Gateway instance name for
87
+ external API access configuration
88
+ veapig_service_name: Optional Volcengine API Gateway service name
89
+ veapig_upstream_name: Optional Volcengine API Gateway upstream name
90
+ short_term_memory_backend: Backend type for short-term memory storage.
91
+ Choices are 'local' or 'mysql'
92
+ use_adk_web: Flag to enable ADK Web interface for the deployed agent
93
+ path: Local directory path containing the VeADK project to deploy
94
+
95
+ Note:
96
+ - The function automatically processes and copies requirements.txt if present in the project
97
+ - config.yaml files are excluded from deployment for security reasons
98
+ - Temporary files are created in /tmp and cleaned up after deployment
99
+ - The deployment uses cookiecutter templates for standardized project structure
100
+ """
66
101
  import asyncio
67
102
  import shutil
68
103
  from pathlib import Path
veadk/cli/cli_eval.py CHANGED
@@ -64,6 +64,61 @@ def eval(
64
64
  volcengine_access_key: str,
65
65
  volcengine_secret_key: str,
66
66
  ) -> None:
67
+ """Evaluate an agent using specified evaluation datasets and metrics.
68
+
69
+ This command provides comprehensive agent evaluation capabilities using either Google ADK
70
+ or DeepEval frameworks. It supports both local agent evaluation (from source code) and
71
+ remote agent evaluation (via A2A deployment URLs), making it flexible for different
72
+ development and deployment scenarios.
73
+
74
+ The evaluation process includes:
75
+ 1. Loading the target agent from local directory or remote A2A endpoint
76
+ 2. Configuring the evaluation environment and credentials
77
+ 3. Setting up the chosen evaluator with appropriate metrics
78
+ 4. Running evaluation tests against the provided dataset
79
+ 5. Generating detailed performance reports and scores
80
+
81
+ Evaluation Modes:
82
+ - Local Evaluation: Loads agent code from a local directory containing 'agent.py'
83
+ with exported 'root_agent' variable. Suitable for development and testing.
84
+ - Remote Evaluation: Connects to a deployed agent via A2A (Agent-to-Agent) URL.
85
+ Ideal for evaluating production deployments or distributed agents.
86
+
87
+ Evaluator Options:
88
+ - ADK Evaluator: Uses Google's Agent Development Kit evaluation framework.
89
+ Provides standardized metrics and comprehensive evaluation reports.
90
+ - DeepEval: Advanced evaluation framework with customizable metrics including
91
+ GEval for general performance and ToolCorrectnessMetric for tool usage accuracy.
92
+
93
+ Args:
94
+ agent_dir: Local directory path containing the agent implementation.
95
+ Must include an 'agent.py' file with exported 'root_agent' variable.
96
+ Defaults to current directory if not specified
97
+ agent_a2a_url: Complete URL of the deployed agent in A2A mode.
98
+ If provided alongside agent_dir, this URL takes precedence
99
+ evalset_file: Path to the evaluation dataset file in Google ADK format.
100
+ Should contain test cases with inputs, expected outputs, and metadata
101
+ evaluator: Evaluation framework to use. Available options:
102
+ - 'adk': Google ADK evaluator with built-in metrics
103
+ - 'deepeval': Advanced evaluator with customizable metrics and thresholds
104
+ judge_model_name: Name of the language model used for evaluation judgment.
105
+ Defaults to 'doubao-1-5-pro-256k-250115'. Only applicable for DeepEval;
106
+ ignored when using ADK evaluator
107
+ volcengine_access_key: Volcengine platform access key for model authentication.
108
+ If not provided, uses VOLCENGINE_ACCESS_KEY environment variable
109
+ volcengine_secret_key: Volcengine platform secret key for model authentication.
110
+ If not provided, uses VOLCENGINE_SECRET_KEY environment variable
111
+
112
+ Note:
113
+ - At least one of --agent-dir or --agent-a2a-url must be provided
114
+ - If both are provided, --agent-a2a-url takes precedence
115
+ - Judge model name is ignored when using ADK evaluator
116
+ - Evaluation results are logged and may be saved to output files
117
+
118
+ Raises:
119
+ ImportError: If DeepEval dependencies are not installed when using DeepEval evaluator.
120
+ ValueError: If neither agent_dir nor agent_a2a_url is provided.
121
+ """
67
122
  import asyncio
68
123
  import os
69
124
  from pathlib import Path
veadk/cli/cli_init.py CHANGED
@@ -25,6 +25,14 @@ warnings.filterwarnings(
25
25
 
26
26
 
27
27
  def _render_prompts() -> dict[str, Any]:
28
+ """Render interactive prompts to collect user configuration for project initialization.
29
+
30
+ This function prompts the user for various configuration options including
31
+ Volcengine FaaS application name, API Gateway settings, and deployment mode.
32
+
33
+ Returns:
34
+ dict[str, Any]: A dictionary containing all the collected configuration values
35
+ """
28
36
  vefaas_application_name = click.prompt(
29
37
  "Volcengine FaaS application name", default="veadk-cloud-agent"
30
38
  )
@@ -71,9 +79,42 @@ def _render_prompts() -> dict[str, Any]:
71
79
  def init(
72
80
  vefaas_template_type: str,
73
81
  ) -> None:
74
- """Init a veadk project that can be deployed to Volcengine VeFaaS.
75
-
76
- `template` is A2A/MCP/Web server template, `web_template` is for web applications (i.e., a simple blog).
82
+ """Initialize a new VeADK project that can be deployed to Volcengine FaaS.
83
+
84
+ This command creates a new VeADK project from predefined templates using an interactive
85
+ setup process. It generates a complete project structure with all necessary files,
86
+ configurations, and deployment scripts ready for Volcengine cloud deployment.
87
+
88
+ The initialization process includes:
89
+ 1. Interactive prompts for collecting deployment configuration
90
+ 2. Template selection based on the specified template type
91
+ 3. Project directory creation with proper structure
92
+ 4. Configuration file generation with user preferences
93
+ 5. Ready-to-use deployment scripts and source code structure
94
+
95
+ Available template types:
96
+ - 'template' (default): Creates an A2A/MCP/Web server template with a weather-reporter
97
+ example application. Suitable for most agent development scenarios.
98
+ - 'web_template': Creates a web application template with a simple-blog example.
99
+ Designed for web-based agent applications with UI components.
100
+
101
+ The generated project structure includes:
102
+ - src/ directory containing agent source code
103
+ - deploy.py script for cloud deployment
104
+ - Configuration files for various deployment scenarios
105
+ - Example implementations based on the selected template
106
+
107
+ Args:
108
+ vefaas_template_type: The type of template to use for project initialization.
109
+ Defaults to 'template'. Valid options are:
110
+ - 'template': Standard agent template (weather-reporter example)
111
+ - 'web_template': Web application template (simple-blog example)
112
+
113
+ Note:
114
+ - If the target directory already exists, you will be prompted to confirm overwrite
115
+ - The generated project includes example code that can be modified for your use case
116
+ - All deployment configurations can be customized after project creation
117
+ - The deploy.py script provides automated deployment to Volcengine FaaS platform
77
118
  """
78
119
  import shutil
79
120
  from pathlib import Path
veadk/cli/cli_kb.py CHANGED
@@ -48,7 +48,42 @@ def add(
48
48
  index: str,
49
49
  path: str,
50
50
  ):
51
- """Add files to knowledgebase"""
51
+ """Add files to knowledgebase.
52
+
53
+ This command adds files or directories to a specified knowledgebase backend.
54
+ It supports various backend types including local storage, OpenSearch, Viking,
55
+ and Redis for storing and indexing knowledge content.
56
+
57
+ Args:
58
+ backend: The knowledgebase backend type to use for storing and indexing documents.
59
+ Available options:
60
+ - 'local': Local file-based storage using SQLite. Suitable for development
61
+ and small-scale deployments. No external dependencies required.
62
+ - 'opensearch': Elasticsearch-compatible search engine with advanced
63
+ full-text search and vector similarity capabilities. Recommended for
64
+ production environments with large document collections.
65
+ - 'viking': Volcengine's managed vector database service optimized for
66
+ semantic search and RAG applications. Provides high performance and
67
+ automatic scaling on Volcengine cloud platform.
68
+ - 'redis': In-memory data structure store with vector search capabilities.
69
+ Fast retrieval but limited by memory capacity. Good for frequently
70
+ accessed, smaller knowledge bases.
71
+ app_name: Application identifier for organizing and isolating knowledgebase
72
+ data. Used to create logical separation between different applications
73
+ or environments. Must be consistent across operations for the same knowledge base.
74
+ index: Knowledgebase index identifier within the application namespace.
75
+ Acts as a unique name for this specific knowledge collection. Multiple
76
+ indexes can exist under the same app_name for different knowledge domains.
77
+ Index names should be descriptive and follow naming conventions of the chosen backend.
78
+ path: File system path to the knowledge content to be added to the knowledge base.
79
+ Supported formats:
80
+ - Single file: Path to a specific document (PDF, TXT, MD, DOCX, etc.)
81
+ - Directory: Path to a folder containing multiple documents. All supported
82
+ files in the directory will be processed recursively.
83
+
84
+ Raises:
85
+ RuntimeError: If the file type is not supported
86
+ """
52
87
  _path = Path(path)
53
88
  assert _path.exists(), f"Path {path} not exists. Please check your input."
54
89
 
veadk/cli/cli_pipeline.py CHANGED
@@ -37,6 +37,18 @@ warnings.filterwarnings(
37
37
 
38
38
 
39
39
  def _create_cr(volcengine_settings: dict[str, str], cr_settings: dict[str, str]):
40
+ """Create Container Registry (CR) resources including instance, namespace, and repository.
41
+
42
+ This helper function creates the necessary Container Registry infrastructure
43
+ on Volcengine cloud platform for storing Docker images used in the CI/CD pipeline.
44
+
45
+ Args:
46
+ volcengine_settings: Dictionary containing Volcengine credentials and region
47
+ cr_settings: Dictionary containing CR instance, namespace, and repo configuration
48
+
49
+ Raises:
50
+ Exception: If any of the CR resource creation operations fail
51
+ """
40
52
  vecr = VeCR(
41
53
  access_key=volcengine_settings["volcengine_access_key"],
42
54
  secret_key=volcengine_settings["volcengine_secret_key"],
@@ -137,7 +149,60 @@ def pipeline(
137
149
  cr_repo_name: str,
138
150
  vefaas_function_id: str,
139
151
  ) -> None:
140
- """Integrate a veadk project to volcengine pipeline for CI/CD"""
152
+ """Integrate a VeADK project with Volcengine pipeline for automated CI/CD deployment.
153
+
154
+ This command sets up a complete CI/CD pipeline that automatically builds, containerizes,
155
+ and deploys your VeADK agent project whenever changes are pushed to the specified GitHub
156
+ repository. It creates all necessary cloud infrastructure including Container Registry
157
+ resources, FaaS functions, and pipeline configurations.
158
+
159
+ The pipeline integration process includes:
160
+ 1. Creating Container Registry (CR) infrastructure (instance, namespace, repository)
161
+ 2. Setting up or using existing VeFaaS function for deployment target
162
+ 3. Configuring Volcengine Code Pipeline with GitHub integration
163
+ 4. Establishing automated build and deployment workflows
164
+ 5. Linking all components for seamless CI/CD operation
165
+
166
+ Pipeline Workflow:
167
+ - Code changes pushed to GitHub trigger the pipeline
168
+ - Source code is automatically pulled from the specified branch
169
+ - Docker image is built using the specified VeADK base image
170
+ - Built image is pushed to Volcengine Container Registry
171
+ - VeFaaS function is updated with the new container image
172
+ - Deployment completion notifications are provided
173
+
174
+ Args:
175
+ veadk_version: Base VeADK image version for containerization. Can be:
176
+ - 'preview': Latest preview/development version
177
+ - 'latest': Latest stable release
178
+ - Specific version (e.g., '1.0.0'): Pinned version for consistency
179
+ github_url: Complete GitHub repository URL containing your VeADK project.
180
+ Must be accessible with the provided GitHub token
181
+ github_branch: Target branch to monitor for changes and deploy from.
182
+ Typically 'main', 'master', or your preferred deployment branch
183
+ github_token: GitHub personal access token with repository access permissions.
184
+ Required for pipeline to access and monitor your repository
185
+ volcengine_access_key: Volcengine cloud platform access key for authentication.
186
+ If not provided, uses VOLCENGINE_ACCESS_KEY environment variable
187
+ volcengine_secret_key: Volcengine cloud platform secret key for authentication.
188
+ If not provided, uses VOLCENGINE_SECRET_KEY environment variable
189
+ region: Volcengine cloud region for all resources (VeFaaS, CR, Pipeline).
190
+ Defaults to 'cn-beijing'. Choose region closest to your users
191
+ cr_instance_name: Name for the Container Registry instance that will store
192
+ your Docker images. Defaults to 'veadk-user-instance'
193
+ cr_namespace_name: Namespace within the Container Registry for organizing
194
+ repositories. Defaults to 'veadk-user-namespace'
195
+ cr_repo_name: Repository name within the Container Registry namespace
196
+ for storing your project images. Defaults to 'veadk-user-repo'
197
+ vefaas_function_id: Existing VeFaaS function ID to update with new deployments.
198
+ If not provided, a new function will be created automatically
199
+
200
+ Note:
201
+ - GitHub token must have appropriate permissions for repository access
202
+ - All Volcengine resources will be created in the specified region
203
+ - The pipeline will be triggered immediately upon creation for initial deployment
204
+ - Subsequent deployments occur automatically when code is pushed to the monitored branch
205
+ """
141
206
 
142
207
  click.echo(
143
208
  "Welcome use VeADK to integrate your project to volcengine pipeline for CI/CD."
veadk/cli/cli_prompt.py CHANGED
@@ -30,7 +30,22 @@ import click
30
30
  def prompt(
31
31
  path: str, feedback: str, api_key: str, workspace_id: str, model_name: str
32
32
  ) -> None:
33
- """Optimize agent system prompt from a local file."""
33
+ """Optimize agent system prompt from a local file.
34
+
35
+ This command uses Volcengine PromptPilot service to optimize agent system prompts
36
+ based on feedback and best practices. It loads agents from a specified file and
37
+ applies intelligent prompt optimization using the specified model.
38
+
39
+ Args:
40
+ path: Path to the agent file containing global variable `agent=...`
41
+ feedback: User feedback and suggestions for prompt optimization
42
+ api_key: API key for accessing PromptPilot service
43
+ workspace_id: Workspace ID in PromptPilot for organizing prompts
44
+ model_name: Name of the model to use for prompt optimization
45
+
46
+ Raises:
47
+ ValueError: If workspace_id is not provided when required
48
+ """
34
49
  from pathlib import Path
35
50
 
36
51
  from veadk.agent import Agent
@@ -37,7 +37,21 @@ def uploadevalset(
37
37
  cozeloop_evalset_id: str,
38
38
  cozeloop_api_key: str,
39
39
  ) -> None:
40
- """Upload dataset items to CozeLoop evaluation set."""
40
+ """Upload dataset items to CozeLoop evaluation set.
41
+
42
+ This command uploads evaluation dataset items from a JSON file to the CozeLoop
43
+ platform for agent evaluation and testing. It processes Google ADK formatted
44
+ evaluation cases and converts them to CozeLoop's expected format.
45
+
46
+ Args:
47
+ file: Path to the JSON file containing dataset items in Google ADK format.
48
+ cozeloop_workspace_id: CozeLoop workspace identifier for organizing evaluation sets.
49
+ If not provided, uses OBSERVABILITY_OPENTELEMETRY_COZELOOP_SERVICE_NAME environment variable.
50
+ cozeloop_evalset_id: Specific evaluation set ID where items will be uploaded.
51
+ If not provided, uses OBSERVABILITY_OPENTELEMETRY_COZELOOP_EVALSET_ID environment variable.
52
+ cozeloop_api_key: API key for authenticating with CozeLoop services.
53
+ If not provided, uses OBSERVABILITY_OPENTELEMETRY_COZELOOP_API_KEY environment variable.
54
+ """
41
55
 
42
56
  if not cozeloop_workspace_id:
43
57
  cozeloop_workspace_id = getenv(
veadk/cli/cli_web.py CHANGED
@@ -23,7 +23,14 @@ logger = get_logger(__name__)
23
23
 
24
24
  def patch_adkwebserver_disable_openapi():
25
25
  """
26
- Monkey patch AdkWebServer.get_fast_api to remove openapi.json route.
26
+ Monkey patch AdkWebServer to disable OpenAPI documentation endpoints.
27
+
28
+ This function patches the AdkWebServer.get_fast_api_app method to remove
29
+ OpenAPI-related routes (/openapi.json, /docs, /redoc) from the FastAPI
30
+ application for security and simplicity purposes.
31
+
32
+ The patch is applied by replacing the original method with a wrapped version
33
+ that filters out the unwanted routes after the FastAPI app is created.
27
34
  """
28
35
  import google.adk.cli.adk_web_server
29
36
  from fastapi.routing import APIRoute
@@ -52,7 +59,25 @@ def patch_adkwebserver_disable_openapi():
52
59
  )
53
60
  @click.pass_context
54
61
  def web(ctx, *args, **kwargs) -> None:
55
- """Launch web with long term and short term memory."""
62
+ """
63
+ Launch a web server with VeADK agent support and memory integration.
64
+
65
+ This command starts a web server that can serve VeADK agents with both
66
+ short-term and long-term memory capabilities. It automatically detects
67
+ the type of agent being loaded and configures the appropriate memory
68
+ services accordingly.
69
+
70
+ The function patches the ADK web server to integrate VeADK-specific
71
+ functionality, including memory service configuration and workflow
72
+ agent detection.
73
+
74
+ Args:
75
+ ctx: Click context object containing command line arguments
76
+
77
+ Note:
78
+ For workflow agents (Sequential, Loop, Parallel), individual sub-agent
79
+ memory configurations are not utilized as warned in the logs.
80
+ """
56
81
  from google.adk.cli import adk_web_server
57
82
  from google.adk.runners import Runner as ADKRunner
58
83
 
@@ -107,6 +132,12 @@ def web(ctx, *args, **kwargs) -> None:
107
132
 
108
133
  from google.adk.cli.cli_tools_click import cli_web
109
134
 
110
- extra_args = ctx.args
111
- logger.debug(f"User args: {ctx.args}")
135
+ extra_args: list = ctx.args
136
+ logger.debug(f"User args: {extra_args}")
137
+
138
+ # set a default log level to avoid unnecessary outputs
139
+ # from Google ADK and Litellm
140
+ if "--log_level" not in extra_args:
141
+ extra_args.extend(["--log_level", "ERROR"])
142
+
112
143
  cli_web.main(args=extra_args, standalone_mode=False)
@@ -22,7 +22,7 @@ from typing import Any
22
22
  from pydantic import BaseModel
23
23
 
24
24
  from veadk.cloud.cloud_app import CloudApp
25
- from veadk.config import getenv
25
+ from veadk.config import getenv, veadk_environments
26
26
  from veadk.integrations.ve_faas.ve_faas import VeFaaS
27
27
  from veadk.utils.logger import get_logger
28
28
  from veadk.utils.misc import formatted_timestamp
@@ -31,11 +31,51 @@ logger = get_logger(__name__)
31
31
 
32
32
 
33
33
  class CloudAgentEngine(BaseModel):
34
+ """Manages cloud agent deployment and operations on Volcengine FaaS platform.
35
+
36
+ This class handles authentication with Volcengine, deploys local projects to FaaS,
37
+ updates function code, removes applications, and supports local testing.
38
+
39
+ Attributes:
40
+ volcengine_access_key (str): Access key for Volcengine authentication.
41
+ Defaults to VOLCENGINE_ACCESS_KEY environment variable.
42
+ volcengine_secret_key (str): Secret key for Volcengine authentication.
43
+ Defaults to VOLCENGINE_SECRET_KEY environment variable.
44
+ region (str): Region for Volcengine services. Defaults to "cn-beijing".
45
+ _vefaas_service (VeFaaS): Internal VeFaaS client instance, initialized post-creation.
46
+
47
+ Note:
48
+ Credentials must be set via environment variables for default behavior.
49
+ This class performs interactive confirmations for destructive operations like removal.
50
+
51
+ Examples:
52
+ ```python
53
+ from veadk.cloud.cloud_agent_engine import CloudAgentEngine
54
+ engine = CloudAgentEngine()
55
+ app = engine.deploy("test-app", "/path/to/local/project")
56
+ print(app.vefaas_endpoint)
57
+ ```
58
+ """
59
+
34
60
  volcengine_access_key: str = getenv("VOLCENGINE_ACCESS_KEY")
35
61
  volcengine_secret_key: str = getenv("VOLCENGINE_SECRET_KEY")
36
62
  region: str = "cn-beijing"
37
63
 
38
64
  def model_post_init(self, context: Any, /) -> None:
65
+ """Initializes the internal VeFaaS service after Pydantic model validation.
66
+
67
+ Creates a VeFaaS instance using the configured access key, secret key, and region.
68
+
69
+ Args:
70
+ self: The CloudAgentEngine instance.
71
+ context: Pydantic post-init context parameter (not used).
72
+
73
+ Returns:
74
+ None
75
+
76
+ Note:
77
+ This is a Pydantic lifecycle method, ensuring service readiness after init.
78
+ """
39
79
  self._vefaas_service = VeFaaS(
40
80
  access_key=self.volcengine_access_key,
41
81
  secret_key=self.volcengine_secret_key,
@@ -43,6 +83,25 @@ class CloudAgentEngine(BaseModel):
43
83
  )
44
84
 
45
85
  def _prepare(self, path: str, name: str):
86
+ """Prepares the local project for deployment by validating path and name.
87
+
88
+ Checks if the path exists and is a directory, validates application name format.
89
+
90
+ Args:
91
+ path (str): Full or relative path to the local agent project directory.
92
+ name (str): Intended VeFaaS application name.
93
+
94
+ Returns:
95
+ None
96
+
97
+ Raises:
98
+ AssertionError: If path does not exist or is not a directory.
99
+ ValueError: If name contains invalid characters like underscores.
100
+
101
+ Note:
102
+ Includes commented code for handling requirements.txt; not executed currently.
103
+ Called internally by deploy and update methods.
104
+ """
46
105
  # basic check
47
106
  assert os.path.exists(path), f"Local agent project path `{path}` not exists."
48
107
  assert os.path.isdir(path), (
@@ -73,10 +132,23 @@ class CloudAgentEngine(BaseModel):
73
132
  # )
74
133
 
75
134
  def _try_launch_fastapi_server(self, path: str):
76
- """Try to launch a fastapi server for tests according to user's configuration.
135
+ """Tries to start a FastAPI server locally for testing deployment readiness.
136
+
137
+ Runs the project's run.sh script and checks connectivity on port 8000.
77
138
 
78
139
  Args:
79
- path (str): Local agent project path.
140
+ path (str): Path to the local project containing run.sh.
141
+
142
+ Returns:
143
+ None
144
+
145
+ Raises:
146
+ RuntimeError: If server startup times out after 30 seconds.
147
+
148
+ Note:
149
+ Sets _FAAS_FUNC_TIMEOUT environment to 900 seconds.
150
+ Streams output to console and terminates process after successful check.
151
+ Assumes run.sh launches server on 0.0.0.0:8000.
80
152
  """
81
153
  RUN_SH = f"{path}/run.sh"
82
154
 
@@ -128,33 +200,42 @@ class CloudAgentEngine(BaseModel):
128
200
  use_adk_web: bool = False,
129
201
  local_test: bool = False,
130
202
  ) -> CloudApp:
131
- """Deploy local agent project to Volcengine FaaS platform.
203
+ """Deploys a local agent project to Volcengine FaaS, creating necessary resources.
204
+
205
+ Prepares project, optionally tests locally, deploys via VeFaaS, and returns app instance.
132
206
 
133
207
  Args:
134
- application_name (str): Expected VeFaaS application name.
135
- path (str): Local agent project path.
136
- gateway_name (str): Gateway name.
137
- gateway_service_name (str): Gateway service name.
138
- gateway_upstream_name (str): Gateway upstream name.
139
- use_adk_web (bool): Whether to use ADK Web.
140
- local_test (bool): Whether to run local test for FastAPI Server.
208
+ application_name (str): Unique name for the VeFaaS application.
209
+ path (str): Local directory path of the agent project.
210
+ gateway_name (str, optional): Custom gateway resource name. Defaults to timestamped.
211
+ gateway_service_name (str, optional): Custom service name. Defaults to timestamped.
212
+ gateway_upstream_name (str, optional): Custom upstream name. Defaults to timestamped.
213
+ use_adk_web (bool): Enable ADK Web configuration. Defaults to False.
214
+ local_test (bool): Perform FastAPI server test before deploy. Defaults to False.
141
215
 
142
216
  Returns:
143
- CloudApp: The deployed cloud application instance.
217
+ CloudApp: Deployed application with endpoint, name, and ID.
218
+
219
+ Raises:
220
+ ValueError: On deployment failure, such as invalid config or VeFaaS errors.
221
+
222
+ Note:
223
+ Converts path to absolute; sets telemetry opt-out and ADK Web env vars.
224
+ Generates default gateway names if not specified.
225
+
226
+ Examples:
227
+ ```python
228
+ app = engine.deploy("my-agent", "./agent-project", local_test=True)
229
+ print(f"Deployed at: {app.vefaas_endpoint}")
230
+ ```
144
231
  """
145
232
  # prevent deepeval writing operations
146
- import veadk.config
147
-
148
- veadk.config.veadk_environments["DEEPEVAL_TELEMETRY_OPT_OUT"] = "YES"
233
+ veadk_environments["DEEPEVAL_TELEMETRY_OPT_OUT"] = "YES"
149
234
 
150
235
  if use_adk_web:
151
- import veadk.config
152
-
153
- veadk.config.veadk_environments["USE_ADK_WEB"] = "True"
236
+ veadk_environments["USE_ADK_WEB"] = "True"
154
237
  else:
155
- import veadk.config
156
-
157
- veadk.config.veadk_environments["USE_ADK_WEB"] = "False"
238
+ veadk_environments["USE_ADK_WEB"] = "False"
158
239
 
159
240
  # convert `path` to absolute path
160
241
  path = str(Path(path).resolve())
@@ -191,6 +272,28 @@ class CloudAgentEngine(BaseModel):
191
272
  )
192
273
 
193
274
  def remove(self, app_name: str):
275
+ """Deletes a deployed cloud application after user confirmation.
276
+
277
+ Locates app by name, confirms, and issues delete via VeFaaS.
278
+
279
+ Args:
280
+ app_name (str): Name of the application to remove.
281
+
282
+ Returns:
283
+ None
284
+
285
+ Raises:
286
+ ValueError: If application not found by name.
287
+
288
+ Note:
289
+ Interactive prompt required; cancels on non-'y' input.
290
+ Deletion is processed asynchronously by VeFaaS.
291
+
292
+ Examples:
293
+ ```python
294
+ engine.remove("my-agent")
295
+ ```
296
+ """
194
297
  confirm = input(f"Confirm delete cloud app {app_name}? (y/N): ")
195
298
  if confirm.lower() != "y":
196
299
  print("Delete cancelled.")
@@ -208,14 +311,28 @@ class CloudAgentEngine(BaseModel):
208
311
  application_name: str,
209
312
  path: str,
210
313
  ) -> CloudApp:
211
- """Update existing agent project code while keeping the same URL.
314
+ """Updates the code in an existing VeFaaS application without changing endpoint.
315
+
316
+ Prepares new code from local path and updates function via VeFaaS.
212
317
 
213
318
  Args:
214
- application_name (str): Existing application name to update.
215
- path (str): Local agent project path.
319
+ application_name (str): Name of the existing application to update.
320
+ path (str): Local path containing updated project files.
216
321
 
217
322
  Returns:
218
- CloudApp: Updated cloud app with same endpoint.
323
+ CloudApp: Updated application instance with same endpoint.
324
+
325
+ Raises:
326
+ ValueError: If update fails due to preparation or VeFaaS issues.
327
+
328
+ Note:
329
+ Preserves gateway and other resources; only function code is updated.
330
+ Path is resolved to absolute before processing.
331
+
332
+ Examples:
333
+ ```python
334
+ updated_app = engine.update_function_code("my-agent", "./updated-project")
335
+ ```
219
336
  """
220
337
  # convert `path` to absolute path
221
338
  path = str(Path(path).resolve())