veadk-python 0.2.2__py3-none-any.whl → 0.2.5__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 (149) hide show
  1. veadk/agent.py +31 -21
  2. veadk/agents/loop_agent.py +55 -0
  3. veadk/agents/parallel_agent.py +60 -0
  4. veadk/agents/sequential_agent.py +55 -0
  5. veadk/cli/cli_deploy.py +14 -1
  6. veadk/cli/cli_web.py +27 -0
  7. veadk/cloud/cloud_app.py +21 -6
  8. veadk/consts.py +14 -1
  9. veadk/database/viking/viking_database.py +3 -3
  10. veadk/evaluation/adk_evaluator/__init__.py +4 -0
  11. veadk/evaluation/adk_evaluator/adk_evaluator.py +170 -217
  12. veadk/evaluation/base_evaluator.py +26 -20
  13. veadk/evaluation/deepeval_evaluator/deepeval_evaluator.py +8 -5
  14. veadk/{tracing/telemetry/metrics/__init__.py → integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/clean.py} +10 -0
  15. veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/app.py +40 -7
  16. veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/run.sh +11 -5
  17. veadk/integrations/ve_faas/ve_faas.py +5 -1
  18. veadk/integrations/ve_tos/ve_tos.py +176 -0
  19. veadk/runner.py +162 -39
  20. veadk/tools/builtin_tools/image_edit.py +236 -0
  21. veadk/tools/builtin_tools/image_generate.py +236 -0
  22. veadk/tools/builtin_tools/video_generate.py +326 -0
  23. veadk/tools/sandbox/browser_sandbox.py +19 -9
  24. veadk/tools/sandbox/code_sandbox.py +21 -11
  25. veadk/tools/sandbox/computer_sandbox.py +16 -9
  26. veadk/tracing/base_tracer.py +6 -200
  27. veadk/tracing/telemetry/attributes/attributes.py +29 -0
  28. veadk/tracing/telemetry/attributes/extractors/common_attributes_extractors.py +71 -0
  29. veadk/tracing/telemetry/attributes/extractors/llm_attributes_extractors.py +451 -0
  30. veadk/tracing/telemetry/attributes/extractors/tool_attributes_extractors.py +76 -0
  31. veadk/tracing/telemetry/attributes/extractors/types.py +75 -0
  32. veadk/tracing/telemetry/exporters/apmplus_exporter.py +97 -38
  33. veadk/tracing/telemetry/exporters/base_exporter.py +10 -10
  34. veadk/tracing/telemetry/exporters/cozeloop_exporter.py +20 -13
  35. veadk/tracing/telemetry/exporters/inmemory_exporter.py +49 -32
  36. veadk/tracing/telemetry/exporters/tls_exporter.py +18 -12
  37. veadk/tracing/telemetry/opentelemetry_tracer.py +105 -102
  38. veadk/tracing/telemetry/telemetry.py +238 -0
  39. veadk/types.py +6 -1
  40. veadk/utils/misc.py +41 -1
  41. veadk/utils/patches.py +25 -0
  42. veadk/version.py +1 -1
  43. veadk_python-0.2.5.dist-info/METADATA +345 -0
  44. veadk_python-0.2.5.dist-info/RECORD +127 -0
  45. veadk/__pycache__/__init__.cpython-310.pyc +0 -0
  46. veadk/__pycache__/agent.cpython-310.pyc +0 -0
  47. veadk/__pycache__/config.cpython-310.pyc +0 -0
  48. veadk/__pycache__/consts.cpython-310.pyc +0 -0
  49. veadk/__pycache__/runner.cpython-310.pyc +0 -0
  50. veadk/__pycache__/types.cpython-310.pyc +0 -0
  51. veadk/__pycache__/version.cpython-310.pyc +0 -0
  52. veadk/a2a/__pycache__/__init__.cpython-310.pyc +0 -0
  53. veadk/a2a/__pycache__/agent_card.cpython-310.pyc +0 -0
  54. veadk/a2a/__pycache__/remote_ve_agent.cpython-310.pyc +0 -0
  55. veadk/a2a/__pycache__/ve_a2a_server.cpython-310.pyc +0 -0
  56. veadk/a2a/__pycache__/ve_agent_executor.cpython-310.pyc +0 -0
  57. veadk/cli/__pycache__/__init__.cpython-310.pyc +0 -0
  58. veadk/cli/__pycache__/cli.cpython-310.pyc +0 -0
  59. veadk/cli/__pycache__/cli_deploy.cpython-310.pyc +0 -0
  60. veadk/cli/__pycache__/cli_init.cpython-310.pyc +0 -0
  61. veadk/cli/__pycache__/cli_prompt.cpython-310.pyc +0 -0
  62. veadk/cli/__pycache__/cli_studio.cpython-310.pyc +0 -0
  63. veadk/cli/__pycache__/cli_web.cpython-310.pyc +0 -0
  64. veadk/cli/__pycache__/main.cpython-310.pyc +0 -0
  65. veadk/cloud/__pycache__/__init__.cpython-310.pyc +0 -0
  66. veadk/cloud/__pycache__/cloud_agent_engine.cpython-310.pyc +0 -0
  67. veadk/cloud/__pycache__/cloud_app.cpython-310.pyc +0 -0
  68. veadk/database/__pycache__/__init__.cpython-310.pyc +0 -0
  69. veadk/database/__pycache__/base_database.cpython-310.pyc +0 -0
  70. veadk/database/__pycache__/database_adapter.cpython-310.pyc +0 -0
  71. veadk/database/__pycache__/database_factory.cpython-310.pyc +0 -0
  72. veadk/database/__pycache__/local_database.cpython-310.pyc +0 -0
  73. veadk/database/kv/__pycache__/__init__.cpython-310.pyc +0 -0
  74. veadk/database/relational/__pycache__/__init__.cpython-310.pyc +0 -0
  75. veadk/database/vector/__pycache__/__init__.cpython-310.pyc +0 -0
  76. veadk/database/vector/__pycache__/opensearch_vector_database.cpython-310.pyc +0 -0
  77. veadk/database/vector/__pycache__/type.cpython-310.pyc +0 -0
  78. veadk/database/viking/__pycache__/__init__.cpython-310.pyc +0 -0
  79. veadk/evaluation/__pycache__/__init__.cpython-310.pyc +0 -0
  80. veadk/evaluation/__pycache__/base_evaluator.cpython-310.pyc +0 -0
  81. veadk/evaluation/__pycache__/eval_set_file_loader.cpython-310.pyc +0 -0
  82. veadk/evaluation/__pycache__/eval_set_recorder.cpython-310.pyc +0 -0
  83. veadk/evaluation/__pycache__/types.cpython-310.pyc +0 -0
  84. veadk/evaluation/adk_evaluator/__pycache__/__init__.cpython-310.pyc +0 -0
  85. veadk/evaluation/deepeval_evaluator/__pycache__/__init__.cpython-310.pyc +0 -0
  86. veadk/evaluation/deepeval_evaluator/__pycache__/deepeval_evaluator.cpython-310.pyc +0 -0
  87. veadk/evaluation/utils/__pycache__/prometheus.cpython-310.pyc +0 -0
  88. veadk/integrations/ve_apig/__pycache__/__init__.cpython-310.pyc +0 -0
  89. veadk/integrations/ve_apig/__pycache__/apig.cpython-310.pyc +0 -0
  90. veadk/integrations/ve_apig/__pycache__/ve_apig.cpython-310.pyc +0 -0
  91. veadk/integrations/ve_faas/__pycache__/__init__.cpython-310.pyc +0 -0
  92. veadk/integrations/ve_faas/__pycache__/types.cpython-310.pyc +0 -0
  93. veadk/integrations/ve_faas/__pycache__/ve_faas.cpython-310.pyc +0 -0
  94. veadk/integrations/ve_faas/__pycache__/ve_faas_utils.cpython-310.pyc +0 -0
  95. veadk/integrations/ve_faas/__pycache__/vefaas.cpython-310.pyc +0 -0
  96. veadk/integrations/ve_faas/__pycache__/vefaas_utils.cpython-310.pyc +0 -0
  97. veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/__pycache__/agent.cpython-310.pyc +0 -0
  98. veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/__pycache__/app.cpython-310.pyc +0 -0
  99. veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/__pycache__/studio_app.cpython-310.pyc +0 -0
  100. veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/{{ cookiecutter.app_name|replace('-', '_') }}/__pycache__/__init__.cpython-310.pyc +0 -0
  101. veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/{{ cookiecutter.app_name|replace('-', '_') }}/__pycache__/agent.cpython-310.pyc +0 -0
  102. veadk/integrations/ve_prompt_pilot/__pycache__/__init__.cpython-310.pyc +0 -0
  103. veadk/integrations/ve_prompt_pilot/__pycache__/agentpilot.cpython-310.pyc +0 -0
  104. veadk/knowledgebase/__pycache__/__init__.cpython-310.pyc +0 -0
  105. veadk/knowledgebase/__pycache__/knowledgebase.cpython-310.pyc +0 -0
  106. veadk/knowledgebase/__pycache__/knowledgebase_database_adapter.cpython-310.pyc +0 -0
  107. veadk/memory/__pycache__/__init__.cpython-310.pyc +0 -0
  108. veadk/memory/__pycache__/long_term_memory.cpython-310.pyc +0 -0
  109. veadk/memory/__pycache__/memory_database_adapter.cpython-310.pyc +0 -0
  110. veadk/memory/__pycache__/short_term_memory.cpython-310.pyc +0 -0
  111. veadk/memory/__pycache__/short_term_memory_processor.cpython-310.pyc +0 -0
  112. veadk/prompts/__pycache__/__init__.cpython-310.pyc +0 -0
  113. veadk/prompts/__pycache__/agent_default_prompt.cpython-310.pyc +0 -0
  114. veadk/prompts/__pycache__/prompt_memory_processor.cpython-310.pyc +0 -0
  115. veadk/prompts/__pycache__/prompt_optimization.cpython-310.pyc +0 -0
  116. veadk/tools/__pycache__/__init__.cpython-310.pyc +0 -0
  117. veadk/tools/__pycache__/demo_tools.cpython-310.pyc +0 -0
  118. veadk/tools/__pycache__/load_knowledgebase_tool.cpython-310.pyc +0 -0
  119. veadk/tools/builtin_tools/__pycache__/__init__.cpython-310.pyc +0 -0
  120. veadk/tools/builtin_tools/__pycache__/lark.cpython-310.pyc +0 -0
  121. veadk/tools/builtin_tools/__pycache__/vesearch.cpython-310.pyc +0 -0
  122. veadk/tools/builtin_tools/__pycache__/web_search.cpython-310.pyc +0 -0
  123. veadk/tools/sandbox/__pycache__/__init__.cpython-310.pyc +0 -0
  124. veadk/tracing/__pycache__/__init__.cpython-310.pyc +0 -0
  125. veadk/tracing/__pycache__/base_tracer.cpython-310.pyc +0 -0
  126. veadk/tracing/telemetry/__pycache__/__init__.cpython-310.pyc +0 -0
  127. veadk/tracing/telemetry/__pycache__/opentelemetry_tracer.cpython-310.pyc +0 -0
  128. veadk/tracing/telemetry/exporters/__pycache__/__init__.cpython-310.pyc +0 -0
  129. veadk/tracing/telemetry/exporters/__pycache__/apiserver_exporter.cpython-310.pyc +0 -0
  130. veadk/tracing/telemetry/exporters/__pycache__/apmplus_exporter.cpython-310.pyc +0 -0
  131. veadk/tracing/telemetry/exporters/__pycache__/base_exporter.cpython-310.pyc +0 -0
  132. veadk/tracing/telemetry/exporters/__pycache__/cozeloop_exporter.cpython-310.pyc +0 -0
  133. veadk/tracing/telemetry/exporters/__pycache__/inmemory_exporter.cpython-310.pyc +0 -0
  134. veadk/tracing/telemetry/exporters/__pycache__/tls_exporter.cpython-310.pyc +0 -0
  135. veadk/tracing/telemetry/metrics/__pycache__/__init__.cpython-310.pyc +0 -0
  136. veadk/tracing/telemetry/metrics/__pycache__/opentelemetry_metrics.cpython-310.pyc +0 -0
  137. veadk/tracing/telemetry/metrics/opentelemetry_metrics.py +0 -73
  138. veadk/utils/__pycache__/__init__.cpython-310.pyc +0 -0
  139. veadk/utils/__pycache__/logger.cpython-310.pyc +0 -0
  140. veadk/utils/__pycache__/mcp_utils.cpython-310.pyc +0 -0
  141. veadk/utils/__pycache__/misc.cpython-310.pyc +0 -0
  142. veadk/utils/__pycache__/patches.cpython-310.pyc +0 -0
  143. veadk/utils/__pycache__/volcengine_sign.cpython-310.pyc +0 -0
  144. veadk_python-0.2.2.dist-info/METADATA +0 -144
  145. veadk_python-0.2.2.dist-info/RECORD +0 -213
  146. {veadk_python-0.2.2.dist-info → veadk_python-0.2.5.dist-info}/WHEEL +0 -0
  147. {veadk_python-0.2.2.dist-info → veadk_python-0.2.5.dist-info}/entry_points.txt +0 -0
  148. {veadk_python-0.2.2.dist-info → veadk_python-0.2.5.dist-info}/licenses/LICENSE +0 -0
  149. {veadk_python-0.2.2.dist-info → veadk_python-0.2.5.dist-info}/top_level.txt +0 -0
veadk/agent.py CHANGED
@@ -28,9 +28,10 @@ from typing_extensions import Any
28
28
 
29
29
  from veadk.config import getenv
30
30
  from veadk.consts import (
31
- DEFALUT_MODEL_AGENT_PROVIDER,
31
+ DEFAULT_MODEL_AGENT_PROVIDER,
32
32
  DEFAULT_MODEL_AGENT_API_BASE,
33
33
  DEFAULT_MODEL_AGENT_NAME,
34
+ DEFAULT_MODEL_EXTRA_HEADERS,
34
35
  )
35
36
  from veadk.evaluation import EvalSetRecorder
36
37
  from veadk.knowledgebase import KnowledgeBase
@@ -40,6 +41,7 @@ from veadk.prompts.agent_default_prompt import DEFAULT_DESCRIPTION, DEFAULT_INST
40
41
  from veadk.tracing.base_tracer import BaseTracer
41
42
  from veadk.utils.logger import get_logger
42
43
  from veadk.utils.patches import patch_asyncio
44
+ from veadk.version import VERSION
43
45
 
44
46
  patch_asyncio()
45
47
  logger = get_logger(__name__)
@@ -60,11 +62,10 @@ class Agent(LlmAgent):
60
62
  instruction: str = DEFAULT_INSTRUCTION
61
63
  """The instruction for the agent, such as principles of function calling."""
62
64
 
63
- # factory
64
65
  model_name: str = getenv("MODEL_AGENT_NAME", DEFAULT_MODEL_AGENT_NAME)
65
66
  """The name of the model for agent running."""
66
67
 
67
- model_provider: str = getenv("MODEL_AGENT_PROVIDER", DEFALUT_MODEL_AGENT_PROVIDER)
68
+ model_provider: str = getenv("MODEL_AGENT_PROVIDER", DEFAULT_MODEL_AGENT_PROVIDER)
68
69
  """The provider of the model for agent running."""
69
70
 
70
71
  model_api_base: str = getenv("MODEL_AGENT_API_BASE", DEFAULT_MODEL_AGENT_API_BASE)
@@ -73,6 +74,9 @@ class Agent(LlmAgent):
73
74
  model_api_key: str = Field(default_factory=lambda: getenv("MODEL_AGENT_API_KEY"))
74
75
  """The api key of the model for agent running."""
75
76
 
77
+ model_extra_config: dict = Field(default_factory=dict)
78
+ """The extra config to include in the model requests."""
79
+
76
80
  tools: list[ToolUnion] = []
77
81
  """The tools provided to agent."""
78
82
 
@@ -96,11 +100,27 @@ class Agent(LlmAgent):
96
100
 
97
101
  def model_post_init(self, __context: Any) -> None:
98
102
  super().model_post_init(None) # for sub_agents init
99
- self.model = LiteLlm(
100
- model=f"{self.model_provider}/{self.model_name}",
101
- api_key=self.model_api_key,
102
- api_base=self.model_api_base,
103
- )
103
+
104
+ # add model request source (veadk) in extra headers
105
+ if self.model_extra_config and "extra_headers" in self.model_extra_config:
106
+ self.model_extra_config["extra_headers"] |= DEFAULT_MODEL_EXTRA_HEADERS
107
+ else:
108
+ self.model_extra_config["extra_headers"] = DEFAULT_MODEL_EXTRA_HEADERS
109
+
110
+ if not self.model:
111
+ self.model = LiteLlm(
112
+ model=f"{self.model_provider}/{self.model_name}",
113
+ api_key=self.model_api_key,
114
+ api_base=self.model_api_base,
115
+ **self.model_extra_config,
116
+ )
117
+ logger.debug(
118
+ f"LiteLLM client created with config: {self.model_extra_config}"
119
+ )
120
+ else:
121
+ logger.warning(
122
+ "You are trying to use your own LiteLLM client, some default request headers may be missing."
123
+ )
104
124
 
105
125
  if self.knowledgebase:
106
126
  from veadk.tools import load_knowledgebase_tool
@@ -113,18 +133,11 @@ class Agent(LlmAgent):
113
133
 
114
134
  self.tools.append(load_memory)
115
135
 
116
- if self.tracers:
117
- self.before_model_callback = []
118
- self.after_model_callback = []
119
- self.after_tool_callback = []
120
- for tracer in self.tracers:
121
- self.before_model_callback.append(tracer.tracer_hook_before_model)
122
- self.after_model_callback.append(tracer.tracer_hook_after_model)
123
- self.after_tool_callback.append(tracer.tracer_hook_after_tool)
136
+ logger.info(f"VeADK version: {VERSION}")
124
137
 
125
- logger.info(f"Agent `{self.name}` init done.")
138
+ logger.info(f"{self.__class__.__name__} `{self.name}` init done.")
126
139
  logger.debug(
127
- f"Agent: {self.model_dump(include={'name', 'model_name', 'model_api_base', 'tools', 'serve_url'})}"
140
+ f"Agent: {self.model_dump(include={'name', 'model_name', 'model_api_base', 'tools'})}"
128
141
  )
129
142
 
130
143
  async def _run(
@@ -221,9 +234,6 @@ class Agent(LlmAgent):
221
234
  session_service=session_service,
222
235
  memory_service=self.long_term_memory,
223
236
  )
224
- if getattr(self, "tracers", None):
225
- for tracer in self.tracers:
226
- tracer.set_app_name(app_name)
227
237
 
228
238
  logger.info(f"Begin to process prompt {prompt}")
229
239
  # run
@@ -0,0 +1,55 @@
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
+ from __future__ import annotations
16
+
17
+ from google.adk.agents import LoopAgent as GoogleADKLoopAgent
18
+ from google.adk.agents.base_agent import BaseAgent
19
+ from pydantic import ConfigDict, Field
20
+ from typing_extensions import Any
21
+
22
+ from veadk.prompts.agent_default_prompt import DEFAULT_DESCRIPTION, DEFAULT_INSTRUCTION
23
+ from veadk.tracing.base_tracer import BaseTracer
24
+ from veadk.utils.logger import get_logger
25
+ from veadk.utils.patches import patch_asyncio
26
+
27
+ patch_asyncio()
28
+ logger = get_logger(__name__)
29
+
30
+
31
+ class LoopAgent(GoogleADKLoopAgent):
32
+ """Loop Agent with Volcengine capabilities."""
33
+
34
+ model_config = ConfigDict(arbitrary_types_allowed=True, extra="allow")
35
+ """The model config"""
36
+
37
+ name: str = "veLoopAgent"
38
+ """The name of the agent."""
39
+
40
+ description: str = DEFAULT_DESCRIPTION
41
+ """The description of the agent. This will be helpful in A2A scenario."""
42
+
43
+ instruction: str = DEFAULT_INSTRUCTION
44
+ """The instruction for the agent, such as principles of function calling."""
45
+
46
+ sub_agents: list[BaseAgent] = Field(default_factory=list, exclude=True)
47
+ """The sub agents provided to agent."""
48
+
49
+ tracers: list[BaseTracer] = []
50
+ """The tracers provided to agent."""
51
+
52
+ def model_post_init(self, __context: Any) -> None:
53
+ super().model_post_init(None) # for sub_agents init
54
+
55
+ logger.info(f"{self.__class__.__name__} `{self.name}` init done.")
@@ -0,0 +1,60 @@
1
+ # Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ from __future__ import annotations
16
+
17
+ from google.adk.agents import ParallelAgent as GoogleADKParallelAgent
18
+ from google.adk.agents.base_agent import BaseAgent
19
+ from pydantic import ConfigDict, Field
20
+ from typing_extensions import Any
21
+
22
+ from veadk.prompts.agent_default_prompt import DEFAULT_DESCRIPTION, DEFAULT_INSTRUCTION
23
+ from veadk.tracing.base_tracer import BaseTracer
24
+ from veadk.utils.logger import get_logger
25
+ from veadk.utils.patches import patch_asyncio
26
+
27
+ patch_asyncio()
28
+ logger = get_logger(__name__)
29
+
30
+
31
+ class ParallelAgent(GoogleADKParallelAgent):
32
+ """LLM-based Agent with Volcengine capabilities."""
33
+
34
+ model_config = ConfigDict(arbitrary_types_allowed=True, extra="allow")
35
+ """The model config"""
36
+
37
+ name: str = "veParallelAgent"
38
+ """The name of the agent."""
39
+
40
+ description: str = DEFAULT_DESCRIPTION
41
+ """The description of the agent. This will be helpful in A2A scenario."""
42
+
43
+ instruction: str = DEFAULT_INSTRUCTION
44
+ """The instruction for the agent, such as principles of function calling."""
45
+
46
+ sub_agents: list[BaseAgent] = Field(default_factory=list, exclude=True)
47
+ """The sub agents provided to agent."""
48
+
49
+ tracers: list[BaseTracer] = []
50
+ """The tracers provided to agent."""
51
+
52
+ def model_post_init(self, __context: Any) -> None:
53
+ super().model_post_init(None) # for sub_agents init
54
+
55
+ if self.tracers:
56
+ logger.warning(
57
+ "Enable tracing in ParallelAgent may cause OpenTelemetry context error. Issue see https://github.com/google/adk-python/issues/1670"
58
+ )
59
+
60
+ logger.info(f"{self.__class__.__name__} `{self.name}` init done.")
@@ -0,0 +1,55 @@
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
+ from __future__ import annotations
16
+
17
+ from google.adk.agents import SequentialAgent as GoogleADKSequentialAgent
18
+ from google.adk.agents.base_agent import BaseAgent
19
+ from pydantic import ConfigDict, Field
20
+ from typing_extensions import Any
21
+
22
+ from veadk.prompts.agent_default_prompt import DEFAULT_DESCRIPTION, DEFAULT_INSTRUCTION
23
+ from veadk.tracing.base_tracer import BaseTracer
24
+ from veadk.utils.logger import get_logger
25
+ from veadk.utils.patches import patch_asyncio
26
+
27
+ patch_asyncio()
28
+ logger = get_logger(__name__)
29
+
30
+
31
+ class SequentialAgent(GoogleADKSequentialAgent):
32
+ """Sequential Agent with Volcengine capabilities."""
33
+
34
+ model_config = ConfigDict(arbitrary_types_allowed=True, extra="allow")
35
+ """The model config"""
36
+
37
+ name: str = "veSequentialAgent"
38
+ """The name of the agent."""
39
+
40
+ description: str = DEFAULT_DESCRIPTION
41
+ """The description of the agent. This will be helpful in A2A scenario."""
42
+
43
+ instruction: str = DEFAULT_INSTRUCTION
44
+ """The instruction for the agent, such as principles of function calling."""
45
+
46
+ sub_agents: list[BaseAgent] = Field(default_factory=list, exclude=True)
47
+ """The sub agents provided to agent."""
48
+
49
+ tracers: list[BaseTracer] = []
50
+ """The tracers provided to agent."""
51
+
52
+ def model_post_init(self, __context: Any) -> None:
53
+ super().model_post_init(None) # for sub_agents init
54
+
55
+ logger.info(f"{self.__class__.__name__} `{self.name}` init done.")
veadk/cli/cli_deploy.py CHANGED
@@ -29,7 +29,9 @@ TEMP_PATH = "/tmp"
29
29
  default=None,
30
30
  help="Volcengine secret key",
31
31
  )
32
- @click.option("--vefaas-app-name", help="Expected Volcengine FaaS application name")
32
+ @click.option(
33
+ "--vefaas-app-name", required=True, help="Expected Volcengine FaaS application name"
34
+ )
33
35
  @click.option(
34
36
  "--veapig-instance-name", default="", help="Expected Volcengine APIG instance name"
35
37
  )
@@ -131,6 +133,17 @@ def deploy(
131
133
  "No requirements.txt found in the user project, we will use a default one."
132
134
  )
133
135
 
136
+ # avoid upload user's config.yaml
137
+ if (user_proj_abs_path / "config.yaml").exists():
138
+ logger.warning(
139
+ f"Find a config.yaml in {user_proj_abs_path}/config.yaml, we will not upload it by default."
140
+ )
141
+ shutil.move(agent_dir / "config.yaml", Path(TEMP_PATH) / tmp_dir_name)
142
+ else:
143
+ logger.info(
144
+ "No config.yaml found in the user project. Some environment variables may not be set."
145
+ )
146
+
134
147
  # load
135
148
  logger.debug(
136
149
  f"Load deploy module from {Path(TEMP_PATH) / tmp_dir_name / 'deploy.py'}"
veadk/cli/cli_web.py CHANGED
@@ -102,6 +102,32 @@ def _get_memory(
102
102
  return short_term_memory, long_term_memory
103
103
 
104
104
 
105
+ def patch_adkwebserver_disable_openapi():
106
+ """
107
+ Monkey patch AdkWebServer.get_fast_api to remove openapi.json route.
108
+ """
109
+ import google.adk.cli.adk_web_server
110
+ from fastapi.routing import APIRoute
111
+ from starlette.routing import Route
112
+
113
+ original_get_fast_api = google.adk.cli.adk_web_server.AdkWebServer.get_fast_api_app
114
+
115
+ def wrapped_get_fast_api(self, *args, **kwargs):
116
+ app = original_get_fast_api(self, *args, **kwargs)
117
+
118
+ paths = ["/openapi.json", "/docs", "/redoc"]
119
+ new_routes = []
120
+ for route in app.router.routes:
121
+ if isinstance(route, (APIRoute, Route)) and route.path in paths:
122
+ continue
123
+ new_routes.append(route)
124
+ app.router.routes = new_routes
125
+
126
+ return app
127
+
128
+ google.adk.cli.adk_web_server.AdkWebServer.get_fast_api_app = wrapped_get_fast_api
129
+
130
+
105
131
  @click.command()
106
132
  @click.option("--host", default="127.0.0.1", help="Host to run the web server on")
107
133
  def web(host: str) -> None:
@@ -145,6 +171,7 @@ def web(host: str) -> None:
145
171
  import google.adk.cli.adk_web_server
146
172
 
147
173
  google.adk.cli.adk_web_server.AdkWebServer.__init__ = init_for_veadk
174
+ patch_adkwebserver_disable_openapi()
148
175
 
149
176
  import google.adk.cli.cli_tools_click as cli_tools_click
150
177
 
veadk/cloud/cloud_app.py CHANGED
@@ -13,6 +13,7 @@
13
13
  # limitations under the License.
14
14
 
15
15
  import json
16
+ import time
16
17
  from typing import Any
17
18
  from uuid import uuid4
18
19
 
@@ -60,9 +61,11 @@ class CloudApp:
60
61
  if not vefaas_endpoint:
61
62
  self.vefaas_endpoint = self._get_vefaas_endpoint()
62
63
 
63
- if not self.vefaas_endpoint.startswith(
64
- "http"
65
- ) and not self.vefaas_endpoint.startswith("https"):
64
+ if (
65
+ self.vefaas_endpoint
66
+ and not self.vefaas_endpoint.startswith("http")
67
+ and not self.vefaas_endpoint.startswith("https")
68
+ ):
66
69
  raise ValueError(
67
70
  f"Invalid endpoint: {vefaas_endpoint}. The endpoint must start with `http` or `https`."
68
71
  )
@@ -92,12 +95,13 @@ class CloudApp:
92
95
  raise ValueError(
93
96
  f"VeFaaS CloudAPP with application_id `{self.vefaas_application_id}` or application_name `{self.vefaas_application_name}` not found."
94
97
  )
95
- cloud_resource = json.loads(app["CloudResource"])
96
98
 
97
99
  try:
100
+ cloud_resource = json.loads(app["CloudResource"])
98
101
  vefaas_endpoint = cloud_resource["framework"]["url"]["system_url"]
99
102
  except Exception as e:
100
- raise ValueError(f"VeFaaS cloudAPP could not get endpoint. Error: {e}")
103
+ logger.warning(f"VeFaaS cloudAPP could not get endpoint. Error: {e}")
104
+ vefaas_endpoint = ""
101
105
  return vefaas_endpoint
102
106
 
103
107
  def _get_vefaas_application_id_by_name(self) -> str:
@@ -167,7 +171,18 @@ class CloudApp:
167
171
 
168
172
  vefaas_client = VeFaaS(access_key=volcengine_ak, secret_key=volcengine_sk)
169
173
  vefaas_client.delete(self.vefaas_application_id)
170
- print(f"Cloud app {self.vefaas_application_id} is deleting...")
174
+ print(
175
+ f"Cloud app {self.vefaas_application_id} delete request has been sent to VeFaaS"
176
+ )
177
+ while True:
178
+ try:
179
+ id = self._get_vefaas_application_id_by_name()
180
+ if not id:
181
+ break
182
+ time.sleep(3)
183
+ except Exception as _:
184
+ break
185
+ print("Delete application done.")
171
186
 
172
187
  async def message_send(
173
188
  self, message: str, session_id: str, user_id: str, timeout: float = 600.0
veadk/consts.py CHANGED
@@ -12,6 +12,19 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
+ from veadk.version import VERSION
16
+
15
17
  DEFAULT_MODEL_AGENT_NAME = "doubao-seed-1-6-250615"
16
- DEFALUT_MODEL_AGENT_PROVIDER = "openai"
18
+ DEFAULT_MODEL_AGENT_PROVIDER = "openai"
17
19
  DEFAULT_MODEL_AGENT_API_BASE = "https://ark.cn-beijing.volces.com/api/v3/"
20
+ DEFAULT_MODEL_EXTRA_HEADERS = {"veadk-source": "veadk", "veadk-version": VERSION}
21
+
22
+ DEFAULT_APMPLUS_OTEL_EXPORTER_ENDPOINT = "http://apmplus-cn-beijing.volces.com:4317"
23
+ DEFAULT_APMPLUS_OTEL_EXPORTER_SERVICE_NAME = "veadk_tracing"
24
+
25
+ DEFAULT_COZELOOP_OTEL_EXPORTER_ENDPOINT = (
26
+ "https://api.coze.cn/v1/loop/opentelemetry/v1/traces"
27
+ )
28
+
29
+ DEFAULT_TLS_OTEL_EXPORTER_ENDPOINT = "https://tls-cn-beijing.volces.com:4318/v1/traces"
30
+ DEFAULT_TLS_OTEL_EXPORTER_REGION = "cn-beijing"
@@ -387,9 +387,9 @@ class VikingDatabase(BaseModel, BaseDatabase):
387
387
  logger.error(f"Error in list_collections: {result['message']}")
388
388
  raise ValueError(f"Error in list_collections: {result['message']}")
389
389
 
390
- collections = result["data"]["collection_list"]
391
- if not collections:
392
- raise ValueError(f"No collections found in project {self.config.project}.")
390
+ collections = result["data"].get("collection_list", [])
391
+ if len(collections) == 0:
392
+ return False
393
393
 
394
394
  collection_list = set()
395
395
 
@@ -11,3 +11,7 @@
11
11
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
+
15
+ from .adk_evaluator import ADKEvaluator
16
+
17
+ __all__ = ["ADKEvaluator"]