veadk-python 0.2.6__py3-none-any.whl → 0.2.8__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.

Potentially problematic release.


This version of veadk-python might be problematic. Click here for more details.

Files changed (102) hide show
  1. veadk/agent.py +11 -18
  2. veadk/agent_builder.py +94 -0
  3. veadk/{database/__init__.py → auth/base_auth.py} +7 -2
  4. veadk/auth/veauth/apmplus_veauth.py +65 -0
  5. veadk/auth/veauth/ark_veauth.py +77 -0
  6. veadk/auth/veauth/base_veauth.py +50 -0
  7. veadk/auth/veauth/opensearch_veauth.py +75 -0
  8. veadk/auth/veauth/postgresql_veauth.py +75 -0
  9. veadk/auth/veauth/prompt_pilot_veauth.py +60 -0
  10. veadk/auth/veauth/vesearch_veauth.py +62 -0
  11. veadk/cli/cli.py +4 -0
  12. veadk/cli/cli_deploy.py +3 -2
  13. veadk/cli/cli_eval.py +160 -0
  14. veadk/cli/cli_init.py +1 -1
  15. veadk/cli/cli_pipeline.py +220 -0
  16. veadk/cli/cli_prompt.py +4 -4
  17. veadk/cli/cli_web.py +3 -1
  18. veadk/config.py +45 -81
  19. veadk/configs/database_configs.py +117 -0
  20. veadk/configs/model_configs.py +74 -0
  21. veadk/configs/tool_configs.py +42 -0
  22. veadk/configs/tracing_configs.py +110 -0
  23. veadk/consts.py +13 -1
  24. veadk/evaluation/base_evaluator.py +60 -44
  25. veadk/evaluation/deepeval_evaluator/deepeval_evaluator.py +18 -12
  26. veadk/evaluation/eval_set_recorder.py +2 -2
  27. veadk/integrations/ve_code_pipeline/__init__.py +13 -0
  28. veadk/integrations/ve_code_pipeline/ve_code_pipeline.py +431 -0
  29. veadk/integrations/ve_cozeloop/__init__.py +13 -0
  30. veadk/integrations/ve_cozeloop/ve_cozeloop.py +96 -0
  31. veadk/integrations/ve_cr/ve_cr.py +20 -5
  32. veadk/integrations/ve_faas/template/cookiecutter.json +1 -1
  33. veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/deploy.py +2 -2
  34. veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/agent.py +1 -1
  35. veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/run.sh +1 -5
  36. veadk/integrations/ve_faas/ve_faas.py +351 -36
  37. veadk/integrations/ve_prompt_pilot/ve_prompt_pilot.py +6 -3
  38. veadk/integrations/ve_tls/__init__.py +13 -0
  39. veadk/integrations/ve_tls/utils.py +117 -0
  40. veadk/integrations/ve_tls/ve_tls.py +208 -0
  41. veadk/integrations/ve_tos/ve_tos.py +71 -75
  42. veadk/knowledgebase/backends/__init__.py +13 -0
  43. veadk/knowledgebase/backends/base_backend.py +59 -0
  44. veadk/knowledgebase/backends/in_memory_backend.py +82 -0
  45. veadk/knowledgebase/backends/opensearch_backend.py +136 -0
  46. veadk/knowledgebase/backends/redis_backend.py +144 -0
  47. veadk/knowledgebase/backends/utils.py +91 -0
  48. veadk/knowledgebase/backends/vikingdb_knowledge_backend.py +412 -0
  49. veadk/knowledgebase/knowledgebase.py +109 -55
  50. veadk/memory/__init__.py +22 -0
  51. veadk/memory/long_term_memory.py +120 -51
  52. veadk/memory/long_term_memory_backends/__init__.py +13 -0
  53. veadk/{database/base_database.py → memory/long_term_memory_backends/base_backend.py} +10 -22
  54. veadk/memory/long_term_memory_backends/in_memory_backend.py +65 -0
  55. veadk/memory/long_term_memory_backends/opensearch_backend.py +120 -0
  56. veadk/memory/long_term_memory_backends/redis_backend.py +127 -0
  57. veadk/memory/long_term_memory_backends/vikingdb_memory_backend.py +148 -0
  58. veadk/memory/short_term_memory.py +80 -72
  59. veadk/memory/short_term_memory_backends/__init__.py +13 -0
  60. veadk/memory/short_term_memory_backends/base_backend.py +31 -0
  61. veadk/memory/short_term_memory_backends/mysql_backend.py +41 -0
  62. veadk/memory/short_term_memory_backends/postgresql_backend.py +41 -0
  63. veadk/memory/short_term_memory_backends/sqlite_backend.py +48 -0
  64. veadk/memory/short_term_memory_processor.py +9 -4
  65. veadk/runner.py +204 -247
  66. veadk/tools/builtin_tools/vesearch.py +2 -2
  67. veadk/tools/builtin_tools/video_generate.py +27 -20
  68. veadk/tools/builtin_tools/web_scraper.py +1 -1
  69. veadk/tools/builtin_tools/web_search.py +7 -7
  70. veadk/tools/load_knowledgebase_tool.py +1 -1
  71. veadk/tracing/telemetry/attributes/extractors/llm_attributes_extractors.py +20 -2
  72. veadk/tracing/telemetry/exporters/apmplus_exporter.py +178 -14
  73. veadk/tracing/telemetry/exporters/cozeloop_exporter.py +6 -9
  74. veadk/tracing/telemetry/exporters/inmemory_exporter.py +22 -8
  75. veadk/tracing/telemetry/exporters/tls_exporter.py +6 -10
  76. veadk/tracing/telemetry/opentelemetry_tracer.py +5 -8
  77. veadk/tracing/telemetry/telemetry.py +66 -60
  78. veadk/utils/logger.py +1 -1
  79. veadk/utils/misc.py +63 -0
  80. veadk/utils/volcengine_sign.py +6 -2
  81. veadk/version.py +1 -1
  82. {veadk_python-0.2.6.dist-info → veadk_python-0.2.8.dist-info}/METADATA +16 -3
  83. {veadk_python-0.2.6.dist-info → veadk_python-0.2.8.dist-info}/RECORD +93 -64
  84. veadk/database/database_adapter.py +0 -368
  85. veadk/database/database_factory.py +0 -80
  86. veadk/database/kv/redis_database.py +0 -159
  87. veadk/database/local_database.py +0 -61
  88. veadk/database/relational/mysql_database.py +0 -173
  89. veadk/database/vector/opensearch_vector_database.py +0 -263
  90. veadk/database/vector/type.py +0 -50
  91. veadk/database/viking/viking_database.py +0 -471
  92. veadk/database/viking/viking_memory_db.py +0 -525
  93. /veadk/{database/kv → auth}/__init__.py +0 -0
  94. /veadk/{database/relational → auth/veauth}/__init__.py +0 -0
  95. /veadk/{database/vector/__init__.py → auth/veauth/cozeloop_veauth.py} +0 -0
  96. /veadk/{database/viking → configs}/__init__.py +0 -0
  97. /veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/{{{ cookiecutter.app_name|replace('-', '_') }} → {{ cookiecutter.app_name }}}/__init__.py +0 -0
  98. /veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/{{{ cookiecutter.app_name|replace('-', '_') }} → {{ cookiecutter.app_name }}}/agent.py +0 -0
  99. {veadk_python-0.2.6.dist-info → veadk_python-0.2.8.dist-info}/WHEEL +0 -0
  100. {veadk_python-0.2.6.dist-info → veadk_python-0.2.8.dist-info}/entry_points.txt +0 -0
  101. {veadk_python-0.2.6.dist-info → veadk_python-0.2.8.dist-info}/licenses/LICENSE +0 -0
  102. {veadk_python-0.2.6.dist-info → veadk_python-0.2.8.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,431 @@
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 string import Template
17
+
18
+ import requests
19
+
20
+ from veadk.utils.logger import get_logger
21
+ from veadk.utils.misc import formatted_timestamp
22
+ from veadk.utils.volcengine_sign import ve_request
23
+
24
+ logger = get_logger(__name__)
25
+
26
+ SPEC = Template("""version: 1.0.0
27
+ agentPool: public/prod-v2-public
28
+ sources:
29
+ - name: ${code_connection_name}
30
+ type: Github
31
+ url: ${github_url}
32
+ branch: ${github_branch}
33
+ branchingModel: false
34
+ credential:
35
+ type: serviceConnection
36
+ serviceConnectionId: ${code_connection_id}
37
+ cloneDepth: 1
38
+ stages:
39
+ - stage: stage-1
40
+ displayName: 函数构建
41
+ tasks:
42
+ - task: task-1
43
+ displayName: 函数构建
44
+ timeout: 2h
45
+ steps:
46
+ - step: step-c1
47
+ displayName: 镜像构建推送到镜像仓库服务
48
+ component: build@2.0.0/buildkit-cr@3.0.0
49
+ inputs:
50
+ buildParams: ""
51
+ compression: gzip
52
+ contextPath: .
53
+ crDomain: ${cr_domain}
54
+ crNamespace: ${cr_namespace_name}
55
+ crRegion: ${cr_region}
56
+ crRegistryInstance: ${cr_instance_name}
57
+ crRepo: ${cr_repo_name}
58
+ crTag: $(DATETIME)
59
+ disableSSLVerify: false
60
+ dockerfiles:
61
+ default:
62
+ content: |-
63
+ ${docker_file}
64
+ loginCredential: []
65
+ useCache: false
66
+ outputs:
67
+ - imageOutput_step-c1
68
+ workspace:
69
+ resources:
70
+ - ref: ${code_connection_name}
71
+ directory: $(CP_WORKSPACE)
72
+ resourcesPolicy: all
73
+ resources:
74
+ limits:
75
+ cpu: 1C
76
+ memory: 2Gi
77
+ - stage: stage-2
78
+ displayName: 函数部署
79
+ tasks:
80
+ - task: task-2
81
+ displayName: 函数部署
82
+ component: deploy@1.0.0/faas-deploy
83
+ inputs:
84
+ artifact:
85
+ mode: output
86
+ type: image
87
+ value: $(stages.stage-1.tasks.task-1.outputs.imageOutput_step-c1)
88
+ deployPolicy:
89
+ type: full
90
+ functionId: ${function_id}
91
+ functionVersion: 0
92
+ region: cn-beijing
93
+ outputs:
94
+ - releaseId
95
+ - releaseStatus
96
+ workspace: {}
97
+ """)
98
+
99
+
100
+ def get_dockerfile(tag: str = "latest") -> str:
101
+ dockerfile = f"""FROM veadk-cn-beijing.cr.volces.com/veadk/veadk-python:{tag}
102
+ WORKDIR /app
103
+ COPY . .
104
+ RUN pip3 install --no-cache-dir -r requirements.txt
105
+ ENTRYPOINT ["bash", "./run.sh"]"""
106
+ return dockerfile
107
+
108
+
109
+ class VeCodePipeline:
110
+ def __init__(
111
+ self,
112
+ volcengine_access_key: str,
113
+ volcengine_secret_key: str,
114
+ region: str = "cn-beijing",
115
+ ) -> None:
116
+ self.volcengine_access_key = volcengine_access_key
117
+ self.volcengine_secret_key = volcengine_secret_key
118
+ self.region = region
119
+
120
+ self.service = "CP"
121
+ self.version = "2023-05-01"
122
+ self.host = "open.volcengineapi.com"
123
+ self.content_type = "application/json"
124
+
125
+ def _create_code_connection(
126
+ self, github_token: str, github_url: str
127
+ ) -> tuple[str, str]:
128
+ logger.info("Creating code connection...")
129
+
130
+ conn_name = f"veadk-conn-{formatted_timestamp()}"
131
+ res = ve_request(
132
+ request_body={
133
+ "Id": f"VEADK_CONN_{formatted_timestamp()}",
134
+ "Name": conn_name,
135
+ "Description": "Created by Volcengine Agent Development Kit (VeADK)",
136
+ "Type": "Github",
137
+ "Credential": {"Token": github_token},
138
+ "IsAllWsShared": True,
139
+ "URL": github_url,
140
+ },
141
+ action="CreateServiceConnection",
142
+ ak=self.volcengine_access_key,
143
+ sk=self.volcengine_secret_key,
144
+ service=self.service,
145
+ version=self.version,
146
+ region=self.region,
147
+ host=self.host,
148
+ content_type=self.content_type,
149
+ )
150
+
151
+ try:
152
+ logger.info(
153
+ f"Code connection created successfully, code connection id {res['Result']['Id']}",
154
+ )
155
+ return res["Result"]["Id"], conn_name
156
+ except KeyError:
157
+ raise Exception(f"Create code connection failed: {res}")
158
+
159
+ def _get_default_workspace(self) -> str:
160
+ logger.info("Getting default workspace...")
161
+
162
+ res = ve_request(
163
+ request_body={},
164
+ action="GetDefaultWorkspaceInner",
165
+ ak=self.volcengine_access_key,
166
+ sk=self.volcengine_secret_key,
167
+ service=self.service,
168
+ version=self.version,
169
+ region=self.region,
170
+ host=self.host,
171
+ content_type=self.content_type,
172
+ )
173
+
174
+ try:
175
+ logger.info(
176
+ f"Default workspace retrieved successfully, workspace id {res['Result']['Id']}",
177
+ )
178
+ return res["Result"]["Id"]
179
+ except KeyError:
180
+ raise Exception(f"Get default workspace failed: {res}")
181
+
182
+ def _create_pipeline(
183
+ self,
184
+ workspace_id: str,
185
+ code_connection_id: str,
186
+ code_connection_name: str,
187
+ github_url: str,
188
+ github_branch: str,
189
+ cr_domain: str,
190
+ cr_namespace_name: str,
191
+ cr_region: str,
192
+ cr_instance_name: str,
193
+ cr_repo_name: str,
194
+ docker_file: str,
195
+ function_id: str,
196
+ ) -> str:
197
+ logger.info("Creating pipeline...")
198
+
199
+ spec = SPEC.safe_substitute(
200
+ github_url=github_url,
201
+ github_branch=github_branch,
202
+ workspace_id=workspace_id,
203
+ code_connection_id=code_connection_id,
204
+ code_connection_name=code_connection_name,
205
+ cr_domain=cr_domain,
206
+ cr_namespace_name=cr_namespace_name,
207
+ cr_region=cr_region,
208
+ cr_instance_name=cr_instance_name,
209
+ cr_repo_name=cr_repo_name,
210
+ docker_file=docker_file,
211
+ function_id=function_id,
212
+ )
213
+
214
+ print(spec)
215
+
216
+ res = ve_request(
217
+ request_body={
218
+ "WorkspaceId": workspace_id,
219
+ "Name": f"veadk-pipeline-{formatted_timestamp()}",
220
+ "spec": spec,
221
+ },
222
+ action="CreatePipeline",
223
+ ak=self.volcengine_access_key,
224
+ sk=self.volcengine_secret_key,
225
+ service="CP",
226
+ version="2023-05-01",
227
+ region="cn-beijing",
228
+ host="open.volcengineapi.com",
229
+ content_type="application/json",
230
+ )
231
+
232
+ try:
233
+ logger.info(
234
+ f"Pipeline created successfully, pipeline id {res['Result']['Id']}",
235
+ )
236
+ return res["Result"]["Id"]
237
+ except KeyError:
238
+ raise Exception(f"Create pipeline failed: {res}")
239
+
240
+ def _create_webhook_trigger(self, workspace_id: str, pipeline_id: str) -> str:
241
+ logger.info("Creating webhook trigger...")
242
+
243
+ res = ve_request(
244
+ request_body={
245
+ "WorkspaceId": workspace_id,
246
+ "PipelineId": pipeline_id,
247
+ "Type": "GitWebhook",
248
+ },
249
+ action="CreatePipelineWebhookURL",
250
+ ak=self.volcengine_access_key,
251
+ sk=self.volcengine_secret_key,
252
+ service=self.service,
253
+ version=self.version,
254
+ region=self.region,
255
+ host=self.host,
256
+ content_type=self.content_type,
257
+ )
258
+
259
+ webhook_url = ""
260
+ try:
261
+ logger.info(
262
+ f"Webhook trigger created successfully, webhook trigger url {res['Result']['WebhookURL']}",
263
+ )
264
+ webhook_url = res["Result"]["WebhookURL"]
265
+ except KeyError:
266
+ raise Exception(f"Create webhook trigger failed: {res}")
267
+
268
+ # create a trigger with webhook url and pipeline id
269
+
270
+ return webhook_url
271
+
272
+ def _set_github_webhook(
273
+ self, webhook_url: str, github_url: str, github_token: str
274
+ ) -> None:
275
+ logger.info("Setting GitHub webhook...")
276
+
277
+ github_url = github_url.replace("https://", "").replace("http://", "")
278
+ github_url_parts = [part for part in github_url.split("/") if part]
279
+ owner = github_url_parts[-2]
280
+ repo = github_url_parts[-1]
281
+
282
+ logger.debug(f"Parsed GitHub URL, owner: {owner}, repo: {repo}")
283
+
284
+ headers = {
285
+ "Accept": "application/vnd.github+json",
286
+ "Authorization": f"Bearer {github_token}",
287
+ "X-GitHub-Api-Version": "2022-11-28",
288
+ "Content-Type": "application/json",
289
+ }
290
+
291
+ webhook_config = {
292
+ "name": "web",
293
+ "active": True,
294
+ "events": ["push"],
295
+ "config": {"url": webhook_url, "content_type": "json", "insecure_ssl": "1"},
296
+ }
297
+
298
+ try:
299
+ response = requests.post(
300
+ url=f"https://api.github.com/repos/{owner}/{repo}/hooks",
301
+ headers=headers,
302
+ data=json.dumps(webhook_config),
303
+ )
304
+
305
+ if response.status_code == 201:
306
+ logger.info("Create github Webhook successfully.")
307
+ result = response.json()
308
+ logger.info(
309
+ f"Webhook ID: {result['id']}, Webhook URL: {result['url']}, Listening events: {', '.join(result['events'])}"
310
+ )
311
+ return result
312
+ else:
313
+ logger.error(f"Create Webhook failed: HTTP {response.status_code}")
314
+ logger.error(f"Error message: {response.text}")
315
+ return None
316
+
317
+ except requests.exceptions.RequestException as e:
318
+ logger.error(f"Request exception: {e}")
319
+ return None
320
+
321
+ def _create_trigger(
322
+ self,
323
+ workspace_id: str,
324
+ pipeline_id: str,
325
+ webhook_url: str,
326
+ code_connection_name: str,
327
+ github_branch: str,
328
+ ) -> None:
329
+ """Create and bind a trigger to pipeline instance with webhook url."""
330
+ logger.info("Creating trigger and bind it to pipeline instance...")
331
+
332
+ res = ve_request(
333
+ request_body={
334
+ "WorkspaceId": workspace_id,
335
+ "PipelineId": pipeline_id,
336
+ "Name": f"veadk-event-trigger-{formatted_timestamp()}",
337
+ "Type": "GitWebhook",
338
+ "Configuration": {
339
+ "Webhook": {
340
+ "URL": webhook_url,
341
+ "Git": {
342
+ "SourceName": code_connection_name,
343
+ "Filters": [
344
+ {
345
+ "EventType": "Push",
346
+ "Config": {"References": [github_branch]},
347
+ },
348
+ {
349
+ "EventType": "CreateTag",
350
+ "Config": {"References": []},
351
+ },
352
+ ],
353
+ "TriggerExecutionType": "AllEvents",
354
+ },
355
+ }
356
+ },
357
+ "Sources": [
358
+ {
359
+ "SourceName": code_connection_name,
360
+ "Reference": "main",
361
+ }
362
+ ],
363
+ },
364
+ action="CreateTrigger",
365
+ ak=self.volcengine_access_key,
366
+ sk=self.volcengine_secret_key,
367
+ service=self.service,
368
+ version=self.version,
369
+ region=self.region,
370
+ host=self.host,
371
+ content_type=self.content_type,
372
+ )
373
+
374
+ try:
375
+ logger.info(
376
+ f"Trigger created and bind successfully, result Id is {res['Result']['Id']}",
377
+ )
378
+ except KeyError:
379
+ raise Exception(f"Create webhook trigger failed: {res}")
380
+
381
+ def deploy(
382
+ self,
383
+ base_image_tag: str,
384
+ github_url: str,
385
+ github_branch: str,
386
+ github_token: str,
387
+ cr_domain: str,
388
+ cr_namespace_name: str,
389
+ cr_region: str,
390
+ cr_instance_name: str,
391
+ cr_repo_name: str,
392
+ function_id: str,
393
+ ) -> str:
394
+ workspace_id = self._get_default_workspace()
395
+
396
+ code_connection_id, code_connection_name = self._create_code_connection(
397
+ github_token=github_token, github_url=github_url
398
+ )
399
+
400
+ pipeline_id = self._create_pipeline(
401
+ workspace_id=workspace_id,
402
+ code_connection_id=code_connection_id,
403
+ code_connection_name=code_connection_name,
404
+ github_url=github_url,
405
+ github_branch=github_branch,
406
+ cr_domain=cr_domain,
407
+ cr_namespace_name=cr_namespace_name,
408
+ cr_region=cr_region,
409
+ cr_instance_name=cr_instance_name,
410
+ cr_repo_name=cr_repo_name,
411
+ docker_file=get_dockerfile(tag=base_image_tag),
412
+ function_id=function_id,
413
+ )
414
+
415
+ webhook_url = self._create_webhook_trigger(
416
+ workspace_id=workspace_id, pipeline_id=pipeline_id
417
+ )
418
+
419
+ self._set_github_webhook(
420
+ webhook_url=webhook_url, github_url=github_url, github_token=github_token
421
+ )
422
+
423
+ self._create_trigger(
424
+ workspace_id=workspace_id,
425
+ pipeline_id=pipeline_id,
426
+ webhook_url=webhook_url,
427
+ code_connection_name=code_connection_name,
428
+ github_branch=github_branch,
429
+ )
430
+
431
+ return pipeline_id
@@ -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.
@@ -0,0 +1,96 @@
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 requests
16
+
17
+ from veadk.consts import DEFAULT_COZELOOP_SPACE_NAME
18
+ from veadk.utils.logger import get_logger
19
+
20
+ logger = get_logger(__name__)
21
+
22
+
23
+ class VeCozeloop:
24
+ def __init__(self, api_key: str) -> None:
25
+ self.api_key = api_key
26
+
27
+ def create_workspace(
28
+ self, workspace_name: str = DEFAULT_COZELOOP_SPACE_NAME
29
+ ) -> str:
30
+ logger.info(
31
+ f"Automatically create Cozeloop workspace with name {workspace_name}"
32
+ )
33
+
34
+ try:
35
+ workspace_id = self.search_workspace_id(workspace_name=workspace_name)
36
+ logger.info(f"Get existing Cozeloop workspace ID: {workspace_id}")
37
+
38
+ return workspace_id
39
+ except Exception as _:
40
+ URL = "https://api.coze.cn/v1/workspaces"
41
+
42
+ headers = {
43
+ "Authorization": f"Bearer {self.api_key}",
44
+ "Content-Type": "application/json",
45
+ }
46
+
47
+ data = {
48
+ "name": workspace_name,
49
+ "description": "Created by Volcengine Agent Development Kit (VeADK)",
50
+ }
51
+
52
+ response = requests.post(URL, headers=headers, json=data)
53
+
54
+ if response.json().get("code") == 0:
55
+ workspace_id = response.json().get("data").get("id")
56
+ logger.info(f"New created Cozeloop workspace ID: {workspace_id}")
57
+ return workspace_id
58
+ else:
59
+ raise Exception(
60
+ f"Failed to automatically create workspace: {response.json()}"
61
+ )
62
+
63
+ def search_workspace_id(
64
+ self, workspace_name: str = DEFAULT_COZELOOP_SPACE_NAME
65
+ ) -> str:
66
+ logger.info(
67
+ f"Automatically fetching Cozeloop workspace ID with name {workspace_name}"
68
+ )
69
+
70
+ URL = "https://api.coze.cn/v1/workspaces"
71
+
72
+ headers = {
73
+ "Authorization": f"Bearer {self.api_key}",
74
+ "Content-Type": "application/json",
75
+ }
76
+
77
+ data = {
78
+ "page_num": 1,
79
+ "page_size": 50,
80
+ }
81
+
82
+ response = requests.get(URL, headers=headers, json=data)
83
+
84
+ if response.json().get("code") == 0:
85
+ workspaces = response.json().get("data").get("workspaces", [])
86
+
87
+ workspace_id = ""
88
+ for workspace in workspaces:
89
+ if workspace.get("name") == workspace_name:
90
+ workspace_id = workspace.get("id")
91
+ logger.info(f"Get Cozeloop workspace ID: {workspace_id}")
92
+ return workspace_id
93
+
94
+ raise Exception(f"Workspace with name {workspace_name} not found.")
95
+ else:
96
+ raise Exception(f"Failed to get workspace ID: {response.json()}")
@@ -12,14 +12,15 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- from veadk.utils.volcengine_sign import ve_request
16
- from veadk.utils.logger import get_logger
15
+ import time
16
+
17
17
  from veadk.consts import (
18
18
  DEFAULT_CR_INSTANCE_NAME,
19
19
  DEFAULT_CR_NAMESPACE_NAME,
20
20
  DEFAULT_CR_REPO_NAME,
21
21
  )
22
- import time
22
+ from veadk.utils.logger import get_logger
23
+ from veadk.utils.volcengine_sign import ve_request
23
24
 
24
25
  logger = get_logger(__name__)
25
26
 
@@ -63,6 +64,20 @@ class VeCR:
63
64
  )
64
65
  logger.debug(f"create cr instance {instance_name}: {response}")
65
66
 
67
+ if "Error" in response["ResponseMetadata"]:
68
+ error_code = response["ResponseMetadata"]["Error"]["Code"]
69
+ error_message = response["ResponseMetadata"]["Error"]["Message"]
70
+ if error_code == "AlreadyExists.Registry":
71
+ logger.debug(f"cr instance {instance_name} already exists")
72
+ return instance_name
73
+ else:
74
+ logger.error(
75
+ f"Error create cr instance {instance_name}: {error_code} {error_message}"
76
+ )
77
+ raise ValueError(
78
+ f"Error create cr instance {instance_name}: {error_code} {error_message}"
79
+ )
80
+
66
81
  while True:
67
82
  status = self._check_instance(instance_name)
68
83
  if status == "Running":
@@ -71,7 +86,7 @@ class VeCR:
71
86
  raise ValueError(f"cr instance {instance_name} create failed")
72
87
  else:
73
88
  logger.debug(f"cr instance status: {status}")
74
- time.sleep(5)
89
+ time.sleep(30)
75
90
 
76
91
  return instance_name
77
92
 
@@ -142,7 +157,7 @@ class VeCR:
142
157
  error_code = response["ResponseMetadata"]["Error"]["Code"]
143
158
  error_message = response["ResponseMetadata"]["Error"]["Message"]
144
159
  if error_code == "AlreadyExists.Namespace":
145
- logger.debug(f"cr namespace {namespace_name} already exists")
160
+ logger.warning(f"cr namespace {namespace_name} already exists")
146
161
  return namespace_name
147
162
  else:
148
163
  logger.error(
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "local_dir_name": "veadk_vefaas_proj",
3
- "app_name": "weather-report",
3
+ "app_name": "weather_report",
4
4
  "agent_module_name": "weather_agent",
5
5
  "short_term_memory_backend": "local",
6
6
  "vefaas_application_name": "weather-reporter",
@@ -95,8 +95,8 @@ async def main():
95
95
  message = "How is the weather like in Beijing?"
96
96
  print(f"Test message: {message}")
97
97
 
98
- await _send_msg_with_a2a(cloud_app=cloud_app, message=message)
99
- await _send_msg_with_mcp(cloud_app=cloud_app, message=message)
98
+ # await _send_msg_with_a2a(cloud_app=cloud_app, message=message)
99
+ # await _send_msg_with_mcp(cloud_app=cloud_app, message=message)
100
100
 
101
101
 
102
102
  if __name__ == "__main__":
@@ -12,7 +12,7 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- from {{ cookiecutter.app_name|replace('-', '_') }}.agent import agent # type: ignore
15
+ from {{ cookiecutter.app_name }}.agent import agent # type: ignore
16
16
 
17
17
  from veadk.memory.short_term_memory import ShortTermMemory
18
18
  from veadk.types import AgentRunConfig
@@ -16,6 +16,7 @@ export SERVER_HOST=$HOST
16
16
  export SERVER_PORT=$PORT
17
17
 
18
18
  export PYTHONPATH=$PYTHONPATH:./site-packages
19
+
19
20
  # Parse arguments
20
21
  while [[ $# -gt 0 ]]; do
21
22
  case $1 in
@@ -33,11 +34,6 @@ while [[ $# -gt 0 ]]; do
33
34
  esac
34
35
  done
35
36
 
36
- # Check if MODEL_AGENT_API_KEY is set
37
- if [ -z "$MODEL_AGENT_API_KEY" ]; then
38
- echo "MODEL_AGENT_API_KEY is not set. Please set it in your environment variables."
39
- exit 1
40
- fi
41
37
 
42
38
  USE_ADK_WEB=${USE_ADK_WEB:-False}
43
39