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.
Files changed (218) hide show
  1. veadk/__init__.py +37 -0
  2. veadk/a2a/__init__.py +13 -0
  3. veadk/a2a/agent_card.py +45 -0
  4. veadk/a2a/remote_ve_agent.py +390 -0
  5. veadk/a2a/utils/__init__.py +13 -0
  6. veadk/a2a/utils/agent_to_a2a.py +170 -0
  7. veadk/a2a/ve_a2a_server.py +93 -0
  8. veadk/a2a/ve_agent_executor.py +78 -0
  9. veadk/a2a/ve_middlewares.py +313 -0
  10. veadk/a2a/ve_task_store.py +37 -0
  11. veadk/agent.py +402 -0
  12. veadk/agent_builder.py +93 -0
  13. veadk/agents/loop_agent.py +68 -0
  14. veadk/agents/parallel_agent.py +72 -0
  15. veadk/agents/sequential_agent.py +64 -0
  16. veadk/auth/__init__.py +13 -0
  17. veadk/auth/base_auth.py +22 -0
  18. veadk/auth/ve_credential_service.py +203 -0
  19. veadk/auth/veauth/__init__.py +13 -0
  20. veadk/auth/veauth/apmplus_veauth.py +58 -0
  21. veadk/auth/veauth/ark_veauth.py +75 -0
  22. veadk/auth/veauth/base_veauth.py +50 -0
  23. veadk/auth/veauth/cozeloop_veauth.py +13 -0
  24. veadk/auth/veauth/opensearch_veauth.py +75 -0
  25. veadk/auth/veauth/postgresql_veauth.py +75 -0
  26. veadk/auth/veauth/prompt_pilot_veauth.py +60 -0
  27. veadk/auth/veauth/speech_veauth.py +54 -0
  28. veadk/auth/veauth/utils.py +69 -0
  29. veadk/auth/veauth/vesearch_veauth.py +62 -0
  30. veadk/auth/veauth/viking_mem0_veauth.py +91 -0
  31. veadk/cli/__init__.py +13 -0
  32. veadk/cli/cli.py +58 -0
  33. veadk/cli/cli_clean.py +87 -0
  34. veadk/cli/cli_create.py +163 -0
  35. veadk/cli/cli_deploy.py +233 -0
  36. veadk/cli/cli_eval.py +215 -0
  37. veadk/cli/cli_init.py +214 -0
  38. veadk/cli/cli_kb.py +110 -0
  39. veadk/cli/cli_pipeline.py +285 -0
  40. veadk/cli/cli_prompt.py +86 -0
  41. veadk/cli/cli_update.py +106 -0
  42. veadk/cli/cli_uploadevalset.py +139 -0
  43. veadk/cli/cli_web.py +143 -0
  44. veadk/cloud/__init__.py +13 -0
  45. veadk/cloud/cloud_agent_engine.py +485 -0
  46. veadk/cloud/cloud_app.py +475 -0
  47. veadk/config.py +115 -0
  48. veadk/configs/__init__.py +13 -0
  49. veadk/configs/auth_configs.py +133 -0
  50. veadk/configs/database_configs.py +132 -0
  51. veadk/configs/model_configs.py +78 -0
  52. veadk/configs/tool_configs.py +54 -0
  53. veadk/configs/tracing_configs.py +110 -0
  54. veadk/consts.py +74 -0
  55. veadk/evaluation/__init__.py +17 -0
  56. veadk/evaluation/adk_evaluator/__init__.py +17 -0
  57. veadk/evaluation/adk_evaluator/adk_evaluator.py +302 -0
  58. veadk/evaluation/base_evaluator.py +642 -0
  59. veadk/evaluation/deepeval_evaluator/__init__.py +17 -0
  60. veadk/evaluation/deepeval_evaluator/deepeval_evaluator.py +339 -0
  61. veadk/evaluation/eval_set_file_loader.py +48 -0
  62. veadk/evaluation/eval_set_recorder.py +146 -0
  63. veadk/evaluation/types.py +65 -0
  64. veadk/evaluation/utils/prometheus.py +196 -0
  65. veadk/integrations/__init__.py +13 -0
  66. veadk/integrations/ve_apig/__init__.py +13 -0
  67. veadk/integrations/ve_apig/ve_apig.py +349 -0
  68. veadk/integrations/ve_apig/ve_apig_utils.py +332 -0
  69. veadk/integrations/ve_code_pipeline/__init__.py +13 -0
  70. veadk/integrations/ve_code_pipeline/ve_code_pipeline.py +431 -0
  71. veadk/integrations/ve_cozeloop/__init__.py +13 -0
  72. veadk/integrations/ve_cozeloop/ve_cozeloop.py +96 -0
  73. veadk/integrations/ve_cr/__init__.py +13 -0
  74. veadk/integrations/ve_cr/ve_cr.py +220 -0
  75. veadk/integrations/ve_faas/__init__.py +13 -0
  76. veadk/integrations/ve_faas/template/cookiecutter.json +15 -0
  77. veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/__init__.py +13 -0
  78. veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/clean.py +23 -0
  79. veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/config.yaml.example +6 -0
  80. veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/deploy.py +106 -0
  81. veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/__init__.py +13 -0
  82. veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/agent.py +25 -0
  83. veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/app.py +202 -0
  84. veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/requirements.txt +3 -0
  85. veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/run.sh +49 -0
  86. veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/{{ cookiecutter.app_name }}/__init__.py +14 -0
  87. veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/{{ cookiecutter.app_name }}/agent.py +27 -0
  88. veadk/integrations/ve_faas/ve_faas.py +754 -0
  89. veadk/integrations/ve_faas/ve_faas_utils.py +408 -0
  90. veadk/integrations/ve_faas/web_template/cookiecutter.json +20 -0
  91. veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/__init__.py +13 -0
  92. veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/clean.py +23 -0
  93. veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/config.yaml.example +2 -0
  94. veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/deploy.py +44 -0
  95. veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/Dockerfile +23 -0
  96. veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/app.py +123 -0
  97. veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/init_db.py +46 -0
  98. veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/models.py +36 -0
  99. veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/requirements.txt +4 -0
  100. veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/run.sh +21 -0
  101. veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/static/css/style.css +368 -0
  102. veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/static/js/admin.js +0 -0
  103. veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/templates/admin/dashboard.html +21 -0
  104. veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/templates/admin/edit_post.html +24 -0
  105. veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/templates/admin/login.html +21 -0
  106. veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/templates/admin/posts.html +53 -0
  107. veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/templates/base.html +45 -0
  108. veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/templates/index.html +29 -0
  109. veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/templates/post.html +14 -0
  110. veadk/integrations/ve_identity/__init__.py +110 -0
  111. veadk/integrations/ve_identity/auth_config.py +261 -0
  112. veadk/integrations/ve_identity/auth_mixins.py +650 -0
  113. veadk/integrations/ve_identity/auth_processor.py +385 -0
  114. veadk/integrations/ve_identity/function_tool.py +158 -0
  115. veadk/integrations/ve_identity/identity_client.py +864 -0
  116. veadk/integrations/ve_identity/mcp_tool.py +181 -0
  117. veadk/integrations/ve_identity/mcp_toolset.py +431 -0
  118. veadk/integrations/ve_identity/models.py +228 -0
  119. veadk/integrations/ve_identity/token_manager.py +188 -0
  120. veadk/integrations/ve_identity/utils.py +151 -0
  121. veadk/integrations/ve_prompt_pilot/__init__.py +13 -0
  122. veadk/integrations/ve_prompt_pilot/ve_prompt_pilot.py +85 -0
  123. veadk/integrations/ve_tls/__init__.py +13 -0
  124. veadk/integrations/ve_tls/utils.py +116 -0
  125. veadk/integrations/ve_tls/ve_tls.py +212 -0
  126. veadk/integrations/ve_tos/ve_tos.py +710 -0
  127. veadk/integrations/ve_viking_db_memory/__init__.py +13 -0
  128. veadk/integrations/ve_viking_db_memory/ve_viking_db_memory.py +308 -0
  129. veadk/knowledgebase/__init__.py +17 -0
  130. veadk/knowledgebase/backends/__init__.py +13 -0
  131. veadk/knowledgebase/backends/base_backend.py +72 -0
  132. veadk/knowledgebase/backends/in_memory_backend.py +91 -0
  133. veadk/knowledgebase/backends/opensearch_backend.py +162 -0
  134. veadk/knowledgebase/backends/redis_backend.py +172 -0
  135. veadk/knowledgebase/backends/utils.py +92 -0
  136. veadk/knowledgebase/backends/vikingdb_knowledge_backend.py +608 -0
  137. veadk/knowledgebase/entry.py +25 -0
  138. veadk/knowledgebase/knowledgebase.py +307 -0
  139. veadk/memory/__init__.py +35 -0
  140. veadk/memory/long_term_memory.py +365 -0
  141. veadk/memory/long_term_memory_backends/__init__.py +13 -0
  142. veadk/memory/long_term_memory_backends/base_backend.py +35 -0
  143. veadk/memory/long_term_memory_backends/in_memory_backend.py +67 -0
  144. veadk/memory/long_term_memory_backends/mem0_backend.py +155 -0
  145. veadk/memory/long_term_memory_backends/opensearch_backend.py +124 -0
  146. veadk/memory/long_term_memory_backends/redis_backend.py +140 -0
  147. veadk/memory/long_term_memory_backends/vikingdb_memory_backend.py +189 -0
  148. veadk/memory/short_term_memory.py +252 -0
  149. veadk/memory/short_term_memory_backends/__init__.py +13 -0
  150. veadk/memory/short_term_memory_backends/base_backend.py +31 -0
  151. veadk/memory/short_term_memory_backends/mysql_backend.py +49 -0
  152. veadk/memory/short_term_memory_backends/postgresql_backend.py +49 -0
  153. veadk/memory/short_term_memory_backends/sqlite_backend.py +55 -0
  154. veadk/memory/short_term_memory_processor.py +100 -0
  155. veadk/processors/__init__.py +26 -0
  156. veadk/processors/base_run_processor.py +120 -0
  157. veadk/prompts/__init__.py +13 -0
  158. veadk/prompts/agent_default_prompt.py +30 -0
  159. veadk/prompts/prompt_evaluator.py +20 -0
  160. veadk/prompts/prompt_memory_processor.py +55 -0
  161. veadk/prompts/prompt_optimization.py +150 -0
  162. veadk/runner.py +732 -0
  163. veadk/tools/__init__.py +13 -0
  164. veadk/tools/builtin_tools/__init__.py +13 -0
  165. veadk/tools/builtin_tools/agent_authorization.py +94 -0
  166. veadk/tools/builtin_tools/generate_image.py +23 -0
  167. veadk/tools/builtin_tools/image_edit.py +300 -0
  168. veadk/tools/builtin_tools/image_generate.py +446 -0
  169. veadk/tools/builtin_tools/lark.py +67 -0
  170. veadk/tools/builtin_tools/las.py +24 -0
  171. veadk/tools/builtin_tools/link_reader.py +66 -0
  172. veadk/tools/builtin_tools/llm_shield.py +381 -0
  173. veadk/tools/builtin_tools/load_knowledgebase.py +97 -0
  174. veadk/tools/builtin_tools/mcp_router.py +29 -0
  175. veadk/tools/builtin_tools/run_code.py +113 -0
  176. veadk/tools/builtin_tools/tts.py +253 -0
  177. veadk/tools/builtin_tools/vesearch.py +49 -0
  178. veadk/tools/builtin_tools/video_generate.py +363 -0
  179. veadk/tools/builtin_tools/web_scraper.py +76 -0
  180. veadk/tools/builtin_tools/web_search.py +83 -0
  181. veadk/tools/demo_tools.py +58 -0
  182. veadk/tools/load_knowledgebase_tool.py +149 -0
  183. veadk/tools/sandbox/__init__.py +13 -0
  184. veadk/tools/sandbox/browser_sandbox.py +37 -0
  185. veadk/tools/sandbox/code_sandbox.py +40 -0
  186. veadk/tools/sandbox/computer_sandbox.py +34 -0
  187. veadk/tracing/__init__.py +13 -0
  188. veadk/tracing/base_tracer.py +58 -0
  189. veadk/tracing/telemetry/__init__.py +13 -0
  190. veadk/tracing/telemetry/attributes/attributes.py +29 -0
  191. veadk/tracing/telemetry/attributes/extractors/common_attributes_extractors.py +180 -0
  192. veadk/tracing/telemetry/attributes/extractors/llm_attributes_extractors.py +858 -0
  193. veadk/tracing/telemetry/attributes/extractors/tool_attributes_extractors.py +152 -0
  194. veadk/tracing/telemetry/attributes/extractors/types.py +164 -0
  195. veadk/tracing/telemetry/exporters/__init__.py +13 -0
  196. veadk/tracing/telemetry/exporters/apmplus_exporter.py +558 -0
  197. veadk/tracing/telemetry/exporters/base_exporter.py +39 -0
  198. veadk/tracing/telemetry/exporters/cozeloop_exporter.py +129 -0
  199. veadk/tracing/telemetry/exporters/inmemory_exporter.py +248 -0
  200. veadk/tracing/telemetry/exporters/tls_exporter.py +139 -0
  201. veadk/tracing/telemetry/opentelemetry_tracer.py +320 -0
  202. veadk/tracing/telemetry/telemetry.py +411 -0
  203. veadk/types.py +47 -0
  204. veadk/utils/__init__.py +13 -0
  205. veadk/utils/audio_manager.py +95 -0
  206. veadk/utils/auth.py +294 -0
  207. veadk/utils/logger.py +59 -0
  208. veadk/utils/mcp_utils.py +44 -0
  209. veadk/utils/misc.py +184 -0
  210. veadk/utils/patches.py +101 -0
  211. veadk/utils/volcengine_sign.py +205 -0
  212. veadk/version.py +15 -0
  213. veadk_python-0.2.27.dist-info/METADATA +373 -0
  214. veadk_python-0.2.27.dist-info/RECORD +218 -0
  215. veadk_python-0.2.27.dist-info/WHEEL +5 -0
  216. veadk_python-0.2.27.dist-info/entry_points.txt +2 -0
  217. veadk_python-0.2.27.dist-info/licenses/LICENSE +201 -0
  218. veadk_python-0.2.27.dist-info/top_level.txt +1 -0
@@ -0,0 +1,475 @@
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
+ import time
17
+ from typing import Any
18
+ from uuid import uuid4
19
+
20
+ import httpx
21
+ from a2a.client import A2ACardResolver, A2AClient
22
+ from a2a.types import AgentCard, Message, MessageSendParams, SendMessageRequest
23
+
24
+ from veadk.config import getenv
25
+ from veadk.utils.logger import get_logger
26
+ from veadk.integrations.ve_faas.ve_faas import VeFaaS
27
+
28
+ logger = get_logger(__name__)
29
+
30
+
31
+ class CloudApp:
32
+ """Represents a deployed cloud agent application on Volcengine FaaS platform.
33
+
34
+ This class facilitates interaction with the deployed agent via A2A protocol,
35
+ supports self-management like update and delete, and handles endpoint resolution.
36
+
37
+ It uses HTTP client for async communications.
38
+
39
+ Attributes:
40
+ vefaas_application_name (str): Name of the VeFaaS application. Defaults to "".
41
+ vefaas_endpoint (str): URL for accessing the application. Resolved if not provided.
42
+ vefaas_application_id (str): Unique identifier of the application. Defaults to "".
43
+ use_agent_card (bool): Flag to resolve endpoint via agent card. Defaults to False.
44
+ httpx_client (httpx.AsyncClient): Async HTTP client for requests.
45
+
46
+ Note:
47
+ At least one of name, endpoint, or ID must be provided during init.
48
+ Agent card mode fetches card from the endpoint's public path.
49
+
50
+ Examples:
51
+ ```python
52
+ from veadk.cloud.cloud_app import CloudApp
53
+ app = CloudApp(vefaas_endpoint="https://my-agent.volcengine.com")
54
+ response = await app.message_send("Query", "session-1", "user-123")
55
+ print(response.message_id)
56
+ ```
57
+ """
58
+
59
+ def __init__(
60
+ self,
61
+ vefaas_application_name: str = "",
62
+ vefaas_endpoint: str = "",
63
+ vefaas_application_id: str = "",
64
+ use_agent_card: bool = False,
65
+ ):
66
+ """Initializes the CloudApp with VeFaaS application details.
67
+
68
+ Sets attributes, validates inputs, resolves endpoint if missing, and creates HTTP client.
69
+
70
+ Args:
71
+ vefaas_application_name (str, optional): Application name for lookup. Defaults to "".
72
+ vefaas_endpoint (str, optional): Direct endpoint URL. Defaults to "".
73
+ vefaas_application_id (str, optional): Application ID for lookup. Defaults to "".
74
+ use_agent_card (bool): Use agent card to determine invocation URL. Defaults to False.
75
+
76
+ Returns:
77
+ None
78
+
79
+ Raises:
80
+ ValueError: If no app identifiers provided or endpoint lacks http/https prefix.
81
+
82
+ Note:
83
+ Logs info if agent card mode enabled.
84
+ Endpoint is fetched via _get_vefaas_endpoint if not set.
85
+
86
+ Examples:
87
+ ```python
88
+ app = CloudApp(vefaas_application_id="app-123", use_agent_card=True)
89
+ ```
90
+ """
91
+ self.vefaas_endpoint = vefaas_endpoint
92
+ self.vefaas_application_id = vefaas_application_id
93
+ self.vefaas_application_name = vefaas_application_name
94
+ self.use_agent_card = use_agent_card
95
+
96
+ # vefaas must be set one of three
97
+ if (
98
+ not vefaas_endpoint
99
+ and not vefaas_application_id
100
+ and not vefaas_application_name
101
+ ):
102
+ raise ValueError(
103
+ "VeFaaS CloudAPP must be set one of endpoint, application_id, or application_name."
104
+ )
105
+
106
+ if not vefaas_endpoint:
107
+ self.vefaas_endpoint = self._get_vefaas_endpoint()
108
+
109
+ if (
110
+ self.vefaas_endpoint
111
+ and not self.vefaas_endpoint.startswith("http")
112
+ and not self.vefaas_endpoint.startswith("https")
113
+ ):
114
+ raise ValueError(
115
+ f"Invalid endpoint: {vefaas_endpoint}. The endpoint must start with `http` or `https`."
116
+ )
117
+
118
+ if use_agent_card:
119
+ logger.info(
120
+ "Use agent card to invoke agent. The agent endpoint will use the `url` in agent card."
121
+ )
122
+
123
+ self.httpx_client = httpx.AsyncClient()
124
+
125
+ def _get_vefaas_endpoint(
126
+ self,
127
+ volcengine_ak: str = getenv(
128
+ "VOLCENGINE_ACCESS_KEY", "", allow_false_values=True
129
+ ),
130
+ volcengine_sk: str = getenv(
131
+ "VOLCENGINE_SECRET_KEY", "", allow_false_values=True
132
+ ),
133
+ ) -> str:
134
+ """Fetches the application endpoint from VeFaaS details if not directly provided.
135
+
136
+ Uses VeFaaS client to get app info and parse CloudResource JSON for URL.
137
+
138
+ Args:
139
+ volcengine_ak (str, optional): Volcengine access key. Defaults to env var.
140
+ volcengine_sk (str, optional): Volcengine secret key. Defaults to env var.
141
+
142
+ Returns:
143
+ str: The system URL from CloudResource or empty string on failure.
144
+
145
+ Raises:
146
+ ValueError: If application not found by ID or name.
147
+
148
+ Note:
149
+ Logs warning if JSON parsing fails; returns empty on error.
150
+ Called during init if endpoint missing.
151
+
152
+ Examples:
153
+ ```python
154
+ endpoint = app._get_vefaas_endpoint("custom-ak", "custom-sk")
155
+ ```
156
+ """
157
+ from veadk.integrations.ve_faas.ve_faas import VeFaaS
158
+
159
+ vefaas_client = VeFaaS(access_key=volcengine_ak, secret_key=volcengine_sk)
160
+
161
+ app = vefaas_client.get_application_details(
162
+ app_id=self.vefaas_application_id,
163
+ app_name=self.vefaas_application_name,
164
+ )
165
+
166
+ if not app:
167
+ raise ValueError(
168
+ f"VeFaaS CloudAPP with application_id `{self.vefaas_application_id}` or application_name `{self.vefaas_application_name}` not found."
169
+ )
170
+
171
+ try:
172
+ cloud_resource = json.loads(app["CloudResource"])
173
+ vefaas_endpoint = cloud_resource["framework"]["url"]["system_url"]
174
+ except Exception as e:
175
+ logger.warning(f"VeFaaS cloudAPP could not get endpoint. Error: {e}")
176
+ vefaas_endpoint = ""
177
+ return vefaas_endpoint
178
+
179
+ def _get_vefaas_application_id_by_name(self) -> str:
180
+ """Retrieves the application ID using the configured name.
181
+
182
+ Instantiates VeFaaS client and queries by name.
183
+
184
+ Returns:
185
+ str: The found application ID.
186
+
187
+ Raises:
188
+ ValueError: If vefaas_application_name is not set.
189
+
190
+ Note:
191
+ Uses default environment credentials.
192
+ Internal method for ID resolution.
193
+
194
+ Examples:
195
+ ```python
196
+ app.vefaas_application_name = "my-app"
197
+ id = app._get_vefaas_application_id_by_name()
198
+ ```
199
+ """
200
+ if not self.vefaas_application_name:
201
+ raise ValueError(
202
+ "VeFaaS CloudAPP must be set application_name to get application_id."
203
+ )
204
+ from veadk.integrations.ve_faas.ve_faas import VeFaaS
205
+
206
+ vefaas_client = VeFaaS(
207
+ access_key=getenv("VOLCENGINE_ACCESS_KEY"),
208
+ secret_key=getenv("VOLCENGINE_SECRET_KEY"),
209
+ )
210
+ vefaas_application_id = vefaas_client.find_app_id_by_name(
211
+ self.vefaas_application_name
212
+ )
213
+ return vefaas_application_id
214
+
215
+ async def _get_a2a_client(self) -> A2AClient:
216
+ """Constructs an A2A client configured for this cloud app.
217
+
218
+ If use_agent_card, resolves agent card and uses its URL; otherwise uses direct endpoint.
219
+
220
+ Args:
221
+ self: The CloudApp instance.
222
+
223
+ Returns:
224
+ A2AClient: Ready-to-use A2A client.
225
+
226
+ Note:
227
+ Manages httpx_client context.
228
+ For card mode, fetches from base_url/ (public card).
229
+ """
230
+ if self.use_agent_card:
231
+ async with self.httpx_client as httpx_client:
232
+ resolver = A2ACardResolver(
233
+ httpx_client=httpx_client, base_url=self.vefaas_endpoint
234
+ )
235
+
236
+ final_agent_card_to_use: AgentCard | None = None
237
+ _public_card = (
238
+ await resolver.get_agent_card()
239
+ ) # Fetches from default public path
240
+ final_agent_card_to_use = _public_card
241
+
242
+ return A2AClient(
243
+ httpx_client=self.httpx_client, agent_card=final_agent_card_to_use
244
+ )
245
+ else:
246
+ return A2AClient(httpx_client=self.httpx_client, url=self.vefaas_endpoint)
247
+
248
+ def update_self(
249
+ self,
250
+ path: str,
251
+ volcengine_ak: str = getenv(
252
+ "VOLCENGINE_ACCESS_KEY", "", allow_false_values=True
253
+ ),
254
+ volcengine_sk: str = getenv(
255
+ "VOLCENGINE_SECRET_KEY", "", allow_false_values=True
256
+ ),
257
+ ):
258
+ """Updates the configuration of this cloud application.
259
+
260
+ Currently a placeholder; implementation pending.
261
+
262
+ Args:
263
+ volcengine_ak (str, optional): Access key for VeFaaS. Defaults to env var.
264
+ volcengine_sk (str, optional): Secret key for VeFaaS. Defaults to env var.
265
+
266
+ Returns:
267
+ None
268
+
269
+ Raises:
270
+ ValueError: If access key or secret key missing.
271
+
272
+ Examples:
273
+ ```python
274
+ app.update_self("ak", "sk")
275
+ ```
276
+ """
277
+ if not volcengine_ak or not volcengine_sk:
278
+ raise ValueError("Volcengine access key and secret key must be set.")
279
+
280
+ if not self.vefaas_application_id:
281
+ self.vefaas_application_id = self._get_vefaas_application_id_by_name()
282
+
283
+ vefaas_client = VeFaaS(access_key=volcengine_ak, secret_key=volcengine_sk)
284
+
285
+ try:
286
+ vefaas_application_url, app_id, function_id = (
287
+ vefaas_client._update_function_code(
288
+ application_name=self.vefaas_application_name,
289
+ path=path,
290
+ )
291
+ )
292
+ self.vefaas_endpoint = vefaas_application_url
293
+ self.vefaas_application_id = app_id
294
+ logger.info(
295
+ f"Cloud app {self.vefaas_application_name} updated successfully."
296
+ )
297
+ except Exception as e:
298
+ raise ValueError(f"Failed to update cloud app. Error: {e}")
299
+
300
+ def delete_self(
301
+ self,
302
+ volcengine_ak: str = getenv(
303
+ "VOLCENGINE_ACCESS_KEY", "", allow_false_values=True
304
+ ),
305
+ volcengine_sk: str = getenv(
306
+ "VOLCENGINE_SECRET_KEY", "", allow_false_values=True
307
+ ),
308
+ ):
309
+ """Deletes this cloud application after interactive confirmation.
310
+
311
+ Issues delete to VeFaaS and polls for completion.
312
+
313
+ Args:
314
+ volcengine_ak (str, optional): Access key. Defaults to env var.
315
+ volcengine_sk (str, optional): Secret key. Defaults to env var.
316
+
317
+ Returns:
318
+ None
319
+
320
+ Raises:
321
+ ValueError: If credentials not provided.
322
+
323
+ Note:
324
+ Fetches ID if not set using name.
325
+ Polls every 3 seconds until app no longer exists.
326
+ Prints status messages.
327
+
328
+ Examples:
329
+ ```python
330
+ app.delete_self()
331
+ ```
332
+ """
333
+ if not volcengine_ak or not volcengine_sk:
334
+ raise ValueError("Volcengine access key and secret key must be set.")
335
+
336
+ if not self.vefaas_application_id:
337
+ self.vefaas_application_id = self._get_vefaas_application_id_by_name()
338
+
339
+ confirm = input(
340
+ f"Confirm delete cloud app {self.vefaas_application_id}? (y/N): "
341
+ )
342
+ if confirm.lower() != "y":
343
+ print("Delete cancelled.")
344
+ return
345
+ else:
346
+ from veadk.integrations.ve_faas.ve_faas import VeFaaS
347
+
348
+ vefaas_client = VeFaaS(access_key=volcengine_ak, secret_key=volcengine_sk)
349
+ vefaas_client.delete(self.vefaas_application_id)
350
+ print(
351
+ f"Cloud app {self.vefaas_application_id} delete request has been sent to VeFaaS"
352
+ )
353
+ while True:
354
+ try:
355
+ id = self._get_vefaas_application_id_by_name()
356
+ if not id:
357
+ break
358
+ time.sleep(3)
359
+ except Exception as _:
360
+ break
361
+ print("Delete application done.")
362
+
363
+ async def message_send(
364
+ self, message: str, session_id: str, user_id: str, timeout: float = 600.0
365
+ ) -> Message | None:
366
+ """Sends a user message to the cloud agent and retrieves the response.
367
+
368
+ Constructs A2A SendMessageRequest and executes via client.
369
+
370
+ Args:
371
+ message (str): Text content of the user message.
372
+ session_id (str): Identifier for the conversation session.
373
+ user_id (str): Identifier for the user.
374
+ timeout (float): Maximum wait time in seconds. Defaults to 600.0.
375
+
376
+ Returns:
377
+ Message | None: Assistant response message or None if error occurs.
378
+
379
+ Raises:
380
+ Exception: Communication or processing errors; error is printed.
381
+
382
+ Note:
383
+ Uses UUID for message and request IDs.
384
+ Payload includes role 'user' and text part.
385
+ Debug logs the full response.
386
+ Ignores type checks for result as it may not be Task.
387
+
388
+ Examples:
389
+ ```python
390
+ response = await app.message_send("What is AI?", "chat-1", "user-1", timeout=300)
391
+ print(response.content)
392
+ ```
393
+ """
394
+ a2a_client = await self._get_a2a_client()
395
+
396
+ async with self.httpx_client:
397
+ send_message_payload: dict[str, Any] = {
398
+ "message": {
399
+ "role": "user",
400
+ "parts": [{"type": "text", "text": message}],
401
+ "messageId": uuid4().hex,
402
+ },
403
+ "metadata": {
404
+ "user_id": user_id,
405
+ "session_id": session_id,
406
+ },
407
+ }
408
+ try:
409
+ message_send_request = SendMessageRequest(
410
+ id=uuid4().hex,
411
+ params=MessageSendParams(**send_message_payload),
412
+ )
413
+
414
+ res = await a2a_client.send_message(
415
+ message_send_request,
416
+ http_kwargs={"timeout": httpx.Timeout(timeout)},
417
+ )
418
+
419
+ logger.debug(
420
+ f"Message sent to cloud app {self.vefaas_application_name} with response: {res}"
421
+ )
422
+
423
+ # we ignore type checking here, because the response
424
+ # from CloudApp will not be `Task` type
425
+ result = res.root.result # type: ignore
426
+ try:
427
+ from a2a.types import Task
428
+ except ImportError:
429
+ return result
430
+
431
+ if isinstance(result, Task):
432
+ if result.history: # type: ignore
433
+ return next(
434
+ (
435
+ msg
436
+ for msg in reversed(result.history) # type: ignore
437
+ if msg.role == "agent"
438
+ ),
439
+ None,
440
+ )
441
+ else:
442
+ return None
443
+ else:
444
+ return result
445
+ except Exception as e:
446
+ logger.error(f"Failed to send message to cloud app. Error: {e}")
447
+ return None
448
+
449
+
450
+ def get_message_id(message: Message):
451
+ """Extracts the unique ID from an A2A Message object.
452
+
453
+ Checks for both legacy 'messageId' and current 'message_id' attributes.
454
+
455
+ Args:
456
+ message (Message): The A2A message instance.
457
+
458
+ Returns:
459
+ str: The message identifier.
460
+
461
+ Note:
462
+ Ensures compatibility with a2a-python versions before and after 0.3.0.
463
+ Prefers 'message_id' if available, falls back to 'messageId'.
464
+
465
+ Examples:
466
+ ```python
467
+ mid = get_message_id(response_message)
468
+ print(mid)
469
+ ```
470
+ """
471
+ if getattr(message, "messageId", None):
472
+ # Compatible with the messageId of the old a2a-python version (<0.3.0) in cloud app
473
+ return message.messageId # type: ignore
474
+ else:
475
+ return message.message_id
veadk/config.py ADDED
@@ -0,0 +1,115 @@
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
+ from typing import Any
17
+
18
+ from dotenv import find_dotenv, load_dotenv, dotenv_values
19
+ from pydantic import BaseModel, Field
20
+
21
+ from veadk.configs.auth_configs import VeIdentityConfig
22
+ from veadk.configs.database_configs import (
23
+ MysqlConfig,
24
+ OpensearchConfig,
25
+ RedisConfig,
26
+ TOSConfig,
27
+ VikingKnowledgebaseConfig,
28
+ )
29
+ from veadk.configs.model_configs import ModelConfig
30
+ from veadk.configs.tool_configs import BuiltinToolConfigs, PromptPilotConfig
31
+ from veadk.configs.tracing_configs import (
32
+ APMPlusConfig,
33
+ CozeloopConfig,
34
+ PrometheusConfig,
35
+ TLSConfig,
36
+ )
37
+ from veadk.utils.logger import get_logger
38
+ from veadk.utils.misc import set_envs
39
+
40
+ logger = get_logger(__name__)
41
+
42
+ env_file_path = os.path.join(os.getcwd(), ".env")
43
+ if os.path.isfile(env_file_path):
44
+ load_dotenv(env_file_path)
45
+ env_from_dotenv = dotenv_values(env_file_path)
46
+ logger.info(f"Find `.env` file in {env_file_path}, load envs.")
47
+ else:
48
+ env_from_dotenv = {}
49
+ logger.info("No `.env` file found.")
50
+
51
+
52
+ class VeADKConfig(BaseModel):
53
+ model: ModelConfig = Field(default_factory=ModelConfig)
54
+ """Config for agent reasoning model."""
55
+
56
+ tool: BuiltinToolConfigs = Field(default_factory=BuiltinToolConfigs)
57
+ prompt_pilot: PromptPilotConfig = Field(default_factory=PromptPilotConfig)
58
+
59
+ apmplus_config: APMPlusConfig = Field(default_factory=APMPlusConfig)
60
+ cozeloop_config: CozeloopConfig = Field(default_factory=CozeloopConfig)
61
+ tls_config: TLSConfig = Field(default_factory=TLSConfig)
62
+ prometheus_config: PrometheusConfig = Field(default_factory=PrometheusConfig)
63
+
64
+ tos: TOSConfig = Field(default_factory=TOSConfig)
65
+ opensearch: OpensearchConfig = Field(default_factory=OpensearchConfig)
66
+ mysql: MysqlConfig = Field(default_factory=MysqlConfig)
67
+ redis: RedisConfig = Field(default_factory=RedisConfig)
68
+ viking_knowledgebase: VikingKnowledgebaseConfig = Field(
69
+ default_factory=VikingKnowledgebaseConfig
70
+ )
71
+
72
+ veidentity: VeIdentityConfig = Field(default_factory=VeIdentityConfig)
73
+
74
+
75
+ def getenv(
76
+ env_name: str, default_value: Any = "", allow_false_values: bool = False
77
+ ) -> str:
78
+ """
79
+ Get environment variable.
80
+
81
+ Args:
82
+ env_name (str): The name of the environment variable.
83
+ default_value (str): The default value of the environment variable.
84
+ allow_false_values (bool, optional): Whether to allow the environment variable to be None or false values. Defaults to False.
85
+
86
+ Returns:
87
+ str: The value of the environment variable.
88
+ """
89
+ value = os.getenv(env_name, default_value)
90
+
91
+ if allow_false_values:
92
+ return value
93
+
94
+ if value:
95
+ return value
96
+ else:
97
+ raise ValueError(
98
+ f"The environment variable `{env_name}` not exists. Please set this in your environment variable or config.yaml."
99
+ )
100
+
101
+
102
+ config_yaml_path = find_dotenv(filename="config.yaml", usecwd=True)
103
+
104
+ veadk_environments = dict(env_from_dotenv)
105
+
106
+ if config_yaml_path:
107
+ logger.info(f"Find `config.yaml` file in {config_yaml_path}")
108
+ config_dict, _veadk_environments = set_envs(
109
+ config_yaml_path=config_yaml_path, env_from_dotenv=env_from_dotenv
110
+ )
111
+ veadk_environments.update(_veadk_environments)
112
+ else:
113
+ logger.warning("No `config.yaml` file found.")
114
+
115
+ settings = VeADKConfig()
@@ -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.