veadk-python 0.2.27__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- veadk/__init__.py +37 -0
- veadk/a2a/__init__.py +13 -0
- veadk/a2a/agent_card.py +45 -0
- veadk/a2a/remote_ve_agent.py +390 -0
- veadk/a2a/utils/__init__.py +13 -0
- veadk/a2a/utils/agent_to_a2a.py +170 -0
- veadk/a2a/ve_a2a_server.py +93 -0
- veadk/a2a/ve_agent_executor.py +78 -0
- veadk/a2a/ve_middlewares.py +313 -0
- veadk/a2a/ve_task_store.py +37 -0
- veadk/agent.py +402 -0
- veadk/agent_builder.py +93 -0
- veadk/agents/loop_agent.py +68 -0
- veadk/agents/parallel_agent.py +72 -0
- veadk/agents/sequential_agent.py +64 -0
- veadk/auth/__init__.py +13 -0
- veadk/auth/base_auth.py +22 -0
- veadk/auth/ve_credential_service.py +203 -0
- veadk/auth/veauth/__init__.py +13 -0
- veadk/auth/veauth/apmplus_veauth.py +58 -0
- veadk/auth/veauth/ark_veauth.py +75 -0
- veadk/auth/veauth/base_veauth.py +50 -0
- veadk/auth/veauth/cozeloop_veauth.py +13 -0
- veadk/auth/veauth/opensearch_veauth.py +75 -0
- veadk/auth/veauth/postgresql_veauth.py +75 -0
- veadk/auth/veauth/prompt_pilot_veauth.py +60 -0
- veadk/auth/veauth/speech_veauth.py +54 -0
- veadk/auth/veauth/utils.py +69 -0
- veadk/auth/veauth/vesearch_veauth.py +62 -0
- veadk/auth/veauth/viking_mem0_veauth.py +91 -0
- veadk/cli/__init__.py +13 -0
- veadk/cli/cli.py +58 -0
- veadk/cli/cli_clean.py +87 -0
- veadk/cli/cli_create.py +163 -0
- veadk/cli/cli_deploy.py +233 -0
- veadk/cli/cli_eval.py +215 -0
- veadk/cli/cli_init.py +214 -0
- veadk/cli/cli_kb.py +110 -0
- veadk/cli/cli_pipeline.py +285 -0
- veadk/cli/cli_prompt.py +86 -0
- veadk/cli/cli_update.py +106 -0
- veadk/cli/cli_uploadevalset.py +139 -0
- veadk/cli/cli_web.py +143 -0
- veadk/cloud/__init__.py +13 -0
- veadk/cloud/cloud_agent_engine.py +485 -0
- veadk/cloud/cloud_app.py +475 -0
- veadk/config.py +115 -0
- veadk/configs/__init__.py +13 -0
- veadk/configs/auth_configs.py +133 -0
- veadk/configs/database_configs.py +132 -0
- veadk/configs/model_configs.py +78 -0
- veadk/configs/tool_configs.py +54 -0
- veadk/configs/tracing_configs.py +110 -0
- veadk/consts.py +74 -0
- veadk/evaluation/__init__.py +17 -0
- veadk/evaluation/adk_evaluator/__init__.py +17 -0
- veadk/evaluation/adk_evaluator/adk_evaluator.py +302 -0
- veadk/evaluation/base_evaluator.py +642 -0
- veadk/evaluation/deepeval_evaluator/__init__.py +17 -0
- veadk/evaluation/deepeval_evaluator/deepeval_evaluator.py +339 -0
- veadk/evaluation/eval_set_file_loader.py +48 -0
- veadk/evaluation/eval_set_recorder.py +146 -0
- veadk/evaluation/types.py +65 -0
- veadk/evaluation/utils/prometheus.py +196 -0
- veadk/integrations/__init__.py +13 -0
- veadk/integrations/ve_apig/__init__.py +13 -0
- veadk/integrations/ve_apig/ve_apig.py +349 -0
- veadk/integrations/ve_apig/ve_apig_utils.py +332 -0
- veadk/integrations/ve_code_pipeline/__init__.py +13 -0
- veadk/integrations/ve_code_pipeline/ve_code_pipeline.py +431 -0
- veadk/integrations/ve_cozeloop/__init__.py +13 -0
- veadk/integrations/ve_cozeloop/ve_cozeloop.py +96 -0
- veadk/integrations/ve_cr/__init__.py +13 -0
- veadk/integrations/ve_cr/ve_cr.py +220 -0
- veadk/integrations/ve_faas/__init__.py +13 -0
- veadk/integrations/ve_faas/template/cookiecutter.json +15 -0
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/__init__.py +13 -0
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/clean.py +23 -0
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/config.yaml.example +6 -0
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/deploy.py +106 -0
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/__init__.py +13 -0
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/agent.py +25 -0
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/app.py +202 -0
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/requirements.txt +3 -0
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/run.sh +49 -0
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/{{ cookiecutter.app_name }}/__init__.py +14 -0
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/{{ cookiecutter.app_name }}/agent.py +27 -0
- veadk/integrations/ve_faas/ve_faas.py +754 -0
- veadk/integrations/ve_faas/ve_faas_utils.py +408 -0
- veadk/integrations/ve_faas/web_template/cookiecutter.json +20 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/__init__.py +13 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/clean.py +23 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/config.yaml.example +2 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/deploy.py +44 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/Dockerfile +23 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/app.py +123 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/init_db.py +46 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/models.py +36 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/requirements.txt +4 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/run.sh +21 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/static/css/style.css +368 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/static/js/admin.js +0 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/templates/admin/dashboard.html +21 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/templates/admin/edit_post.html +24 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/templates/admin/login.html +21 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/templates/admin/posts.html +53 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/templates/base.html +45 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/templates/index.html +29 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/templates/post.html +14 -0
- veadk/integrations/ve_identity/__init__.py +110 -0
- veadk/integrations/ve_identity/auth_config.py +261 -0
- veadk/integrations/ve_identity/auth_mixins.py +650 -0
- veadk/integrations/ve_identity/auth_processor.py +385 -0
- veadk/integrations/ve_identity/function_tool.py +158 -0
- veadk/integrations/ve_identity/identity_client.py +864 -0
- veadk/integrations/ve_identity/mcp_tool.py +181 -0
- veadk/integrations/ve_identity/mcp_toolset.py +431 -0
- veadk/integrations/ve_identity/models.py +228 -0
- veadk/integrations/ve_identity/token_manager.py +188 -0
- veadk/integrations/ve_identity/utils.py +151 -0
- veadk/integrations/ve_prompt_pilot/__init__.py +13 -0
- veadk/integrations/ve_prompt_pilot/ve_prompt_pilot.py +85 -0
- veadk/integrations/ve_tls/__init__.py +13 -0
- veadk/integrations/ve_tls/utils.py +116 -0
- veadk/integrations/ve_tls/ve_tls.py +212 -0
- veadk/integrations/ve_tos/ve_tos.py +710 -0
- veadk/integrations/ve_viking_db_memory/__init__.py +13 -0
- veadk/integrations/ve_viking_db_memory/ve_viking_db_memory.py +308 -0
- veadk/knowledgebase/__init__.py +17 -0
- veadk/knowledgebase/backends/__init__.py +13 -0
- veadk/knowledgebase/backends/base_backend.py +72 -0
- veadk/knowledgebase/backends/in_memory_backend.py +91 -0
- veadk/knowledgebase/backends/opensearch_backend.py +162 -0
- veadk/knowledgebase/backends/redis_backend.py +172 -0
- veadk/knowledgebase/backends/utils.py +92 -0
- veadk/knowledgebase/backends/vikingdb_knowledge_backend.py +608 -0
- veadk/knowledgebase/entry.py +25 -0
- veadk/knowledgebase/knowledgebase.py +307 -0
- veadk/memory/__init__.py +35 -0
- veadk/memory/long_term_memory.py +365 -0
- veadk/memory/long_term_memory_backends/__init__.py +13 -0
- veadk/memory/long_term_memory_backends/base_backend.py +35 -0
- veadk/memory/long_term_memory_backends/in_memory_backend.py +67 -0
- veadk/memory/long_term_memory_backends/mem0_backend.py +155 -0
- veadk/memory/long_term_memory_backends/opensearch_backend.py +124 -0
- veadk/memory/long_term_memory_backends/redis_backend.py +140 -0
- veadk/memory/long_term_memory_backends/vikingdb_memory_backend.py +189 -0
- veadk/memory/short_term_memory.py +252 -0
- veadk/memory/short_term_memory_backends/__init__.py +13 -0
- veadk/memory/short_term_memory_backends/base_backend.py +31 -0
- veadk/memory/short_term_memory_backends/mysql_backend.py +49 -0
- veadk/memory/short_term_memory_backends/postgresql_backend.py +49 -0
- veadk/memory/short_term_memory_backends/sqlite_backend.py +55 -0
- veadk/memory/short_term_memory_processor.py +100 -0
- veadk/processors/__init__.py +26 -0
- veadk/processors/base_run_processor.py +120 -0
- veadk/prompts/__init__.py +13 -0
- veadk/prompts/agent_default_prompt.py +30 -0
- veadk/prompts/prompt_evaluator.py +20 -0
- veadk/prompts/prompt_memory_processor.py +55 -0
- veadk/prompts/prompt_optimization.py +150 -0
- veadk/runner.py +732 -0
- veadk/tools/__init__.py +13 -0
- veadk/tools/builtin_tools/__init__.py +13 -0
- veadk/tools/builtin_tools/agent_authorization.py +94 -0
- veadk/tools/builtin_tools/generate_image.py +23 -0
- veadk/tools/builtin_tools/image_edit.py +300 -0
- veadk/tools/builtin_tools/image_generate.py +446 -0
- veadk/tools/builtin_tools/lark.py +67 -0
- veadk/tools/builtin_tools/las.py +24 -0
- veadk/tools/builtin_tools/link_reader.py +66 -0
- veadk/tools/builtin_tools/llm_shield.py +381 -0
- veadk/tools/builtin_tools/load_knowledgebase.py +97 -0
- veadk/tools/builtin_tools/mcp_router.py +29 -0
- veadk/tools/builtin_tools/run_code.py +113 -0
- veadk/tools/builtin_tools/tts.py +253 -0
- veadk/tools/builtin_tools/vesearch.py +49 -0
- veadk/tools/builtin_tools/video_generate.py +363 -0
- veadk/tools/builtin_tools/web_scraper.py +76 -0
- veadk/tools/builtin_tools/web_search.py +83 -0
- veadk/tools/demo_tools.py +58 -0
- veadk/tools/load_knowledgebase_tool.py +149 -0
- veadk/tools/sandbox/__init__.py +13 -0
- veadk/tools/sandbox/browser_sandbox.py +37 -0
- veadk/tools/sandbox/code_sandbox.py +40 -0
- veadk/tools/sandbox/computer_sandbox.py +34 -0
- veadk/tracing/__init__.py +13 -0
- veadk/tracing/base_tracer.py +58 -0
- veadk/tracing/telemetry/__init__.py +13 -0
- veadk/tracing/telemetry/attributes/attributes.py +29 -0
- veadk/tracing/telemetry/attributes/extractors/common_attributes_extractors.py +180 -0
- veadk/tracing/telemetry/attributes/extractors/llm_attributes_extractors.py +858 -0
- veadk/tracing/telemetry/attributes/extractors/tool_attributes_extractors.py +152 -0
- veadk/tracing/telemetry/attributes/extractors/types.py +164 -0
- veadk/tracing/telemetry/exporters/__init__.py +13 -0
- veadk/tracing/telemetry/exporters/apmplus_exporter.py +558 -0
- veadk/tracing/telemetry/exporters/base_exporter.py +39 -0
- veadk/tracing/telemetry/exporters/cozeloop_exporter.py +129 -0
- veadk/tracing/telemetry/exporters/inmemory_exporter.py +248 -0
- veadk/tracing/telemetry/exporters/tls_exporter.py +139 -0
- veadk/tracing/telemetry/opentelemetry_tracer.py +320 -0
- veadk/tracing/telemetry/telemetry.py +411 -0
- veadk/types.py +47 -0
- veadk/utils/__init__.py +13 -0
- veadk/utils/audio_manager.py +95 -0
- veadk/utils/auth.py +294 -0
- veadk/utils/logger.py +59 -0
- veadk/utils/mcp_utils.py +44 -0
- veadk/utils/misc.py +184 -0
- veadk/utils/patches.py +101 -0
- veadk/utils/volcengine_sign.py +205 -0
- veadk/version.py +15 -0
- veadk_python-0.2.27.dist-info/METADATA +373 -0
- veadk_python-0.2.27.dist-info/RECORD +218 -0
- veadk_python-0.2.27.dist-info/WHEEL +5 -0
- veadk_python-0.2.27.dist-info/entry_points.txt +2 -0
- veadk_python-0.2.27.dist-info/licenses/LICENSE +201 -0
- veadk_python-0.2.27.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,76 @@
|
|
|
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 typing import Any
|
|
16
|
+
|
|
17
|
+
import requests
|
|
18
|
+
|
|
19
|
+
from veadk.config import getenv
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def web_scraper(query: str) -> dict[str, Any]:
|
|
23
|
+
"""query a single keyword from some search engineer
|
|
24
|
+
|
|
25
|
+
Args:
|
|
26
|
+
query (str, optional): query keyword. Defaults to None.
|
|
27
|
+
|
|
28
|
+
Returns:
|
|
29
|
+
dict[str, Any]: search results
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
endpoint = getenv("TOOL_WEB_SCRAPER_ENDPOINT")
|
|
33
|
+
token = getenv("TOOL_WEB_SCRAPER_API_KEY")
|
|
34
|
+
|
|
35
|
+
try:
|
|
36
|
+
url = f"https://{endpoint}/v1/queries"
|
|
37
|
+
headers = {
|
|
38
|
+
"Content-Type": "application/json",
|
|
39
|
+
"X-VE-Source": "google_search",
|
|
40
|
+
"X-VE-API-Key": token,
|
|
41
|
+
}
|
|
42
|
+
data = {
|
|
43
|
+
"query": query,
|
|
44
|
+
"source": "google_search",
|
|
45
|
+
"parse": True,
|
|
46
|
+
"limit": "10",
|
|
47
|
+
"start_page": "1",
|
|
48
|
+
"pages": "1",
|
|
49
|
+
"context": [
|
|
50
|
+
{"key": "nfpr", "value": True},
|
|
51
|
+
{"key": "safe_search", "value": False},
|
|
52
|
+
{"key": "filter", "value": 1},
|
|
53
|
+
],
|
|
54
|
+
}
|
|
55
|
+
response = requests.post(url, headers=headers, json=data, verify=False)
|
|
56
|
+
|
|
57
|
+
response.raise_for_status()
|
|
58
|
+
|
|
59
|
+
response_json = response.json() if response.content else None
|
|
60
|
+
results_dict = (
|
|
61
|
+
response_json.get("results")[0].get("content").get("results").get("organic")
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
results_str = ""
|
|
65
|
+
for r in results_dict:
|
|
66
|
+
dic = {
|
|
67
|
+
"url": r.get("url"),
|
|
68
|
+
"title": r.get("title"),
|
|
69
|
+
"description": r.get("desc"),
|
|
70
|
+
}
|
|
71
|
+
results_str += str(dic)
|
|
72
|
+
return results_str
|
|
73
|
+
|
|
74
|
+
except requests.exceptions.RequestException as e:
|
|
75
|
+
error_message = f"Error: {str(e)}, response: {response}"
|
|
76
|
+
raise ValueError(error_message)
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
"""
|
|
16
|
+
The document of this tool see: https://www.volcengine.com/docs/85508/1650263
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
import os
|
|
20
|
+
|
|
21
|
+
from google.adk.tools import ToolContext
|
|
22
|
+
|
|
23
|
+
from veadk.auth.veauth.utils import get_credential_from_vefaas_iam
|
|
24
|
+
from veadk.utils.logger import get_logger
|
|
25
|
+
from veadk.utils.volcengine_sign import ve_request
|
|
26
|
+
|
|
27
|
+
logger = get_logger(__name__)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def web_search(query: str, tool_context: ToolContext) -> list[str]:
|
|
31
|
+
"""Search a query in websites.
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
query: The query to search.
|
|
35
|
+
|
|
36
|
+
Returns:
|
|
37
|
+
A list of result documents.
|
|
38
|
+
"""
|
|
39
|
+
ak = tool_context.state.get("VOLCENGINE_ACCESS_KEY")
|
|
40
|
+
sk = tool_context.state.get("VOLCENGINE_SECRET_KEY")
|
|
41
|
+
session_token = ""
|
|
42
|
+
|
|
43
|
+
if not (ak and sk):
|
|
44
|
+
logger.debug("Get AK/SK from tool context failed.")
|
|
45
|
+
ak = os.getenv("VOLCENGINE_ACCESS_KEY")
|
|
46
|
+
sk = os.getenv("VOLCENGINE_SECRET_KEY")
|
|
47
|
+
if not (ak and sk):
|
|
48
|
+
logger.debug("Get AK/SK from environment variables failed.")
|
|
49
|
+
credential = get_credential_from_vefaas_iam()
|
|
50
|
+
ak = credential.access_key_id
|
|
51
|
+
sk = credential.secret_access_key
|
|
52
|
+
session_token = credential.session_token
|
|
53
|
+
else:
|
|
54
|
+
logger.debug("Successfully get AK/SK from environment variables.")
|
|
55
|
+
else:
|
|
56
|
+
logger.debug("Successfully get AK/SK from tool context.")
|
|
57
|
+
|
|
58
|
+
response = ve_request(
|
|
59
|
+
request_body={
|
|
60
|
+
"Query": query,
|
|
61
|
+
"SearchType": "web",
|
|
62
|
+
"Count": 5,
|
|
63
|
+
"NeedSummary": True,
|
|
64
|
+
},
|
|
65
|
+
action="WebSearch",
|
|
66
|
+
ak=ak,
|
|
67
|
+
sk=sk,
|
|
68
|
+
service="volc_torchlight_api",
|
|
69
|
+
version="2025-01-01",
|
|
70
|
+
region="cn-beijing",
|
|
71
|
+
host="mercury.volcengineapi.com",
|
|
72
|
+
header={"X-Security-Token": session_token},
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
try:
|
|
76
|
+
results: list = response["Result"]["WebResults"]
|
|
77
|
+
final_results = []
|
|
78
|
+
for result in results:
|
|
79
|
+
final_results.append(result["Summary"].strip())
|
|
80
|
+
return final_results
|
|
81
|
+
except Exception as e:
|
|
82
|
+
logger.error(f"Web search failed {e}, response body: {response}")
|
|
83
|
+
return [response]
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def get_city_weather(city: str) -> dict[str, str]:
|
|
17
|
+
"""Retrieves the weather information of a given city. the args must in English"""
|
|
18
|
+
fixed_weather = {
|
|
19
|
+
"beijing": {"condition": "Sunny", "temperature": 25},
|
|
20
|
+
"shanghai": {"condition": "Cloudy", "temperature": 22},
|
|
21
|
+
"guangzhou": {"condition": "Rainy", "temperature": 28},
|
|
22
|
+
"shenzhen": {"condition": "Partly cloudy", "temperature": 29},
|
|
23
|
+
"chengdu": {"condition": "Windy", "temperature": 20},
|
|
24
|
+
"hangzhou": {"condition": "Snowy", "temperature": -2},
|
|
25
|
+
"wuhan": {"condition": "Humid", "temperature": 26},
|
|
26
|
+
"chongqing": {"condition": "Hazy", "temperature": 30},
|
|
27
|
+
"xi'an": {"condition": "Cool", "temperature": 18},
|
|
28
|
+
"nanjing": {"condition": "Hot", "temperature": 32},
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
city = city.lower().strip()
|
|
32
|
+
if city in fixed_weather:
|
|
33
|
+
info = fixed_weather[city]
|
|
34
|
+
return {"result": f"{info['condition']}, {info['temperature']}°C"}
|
|
35
|
+
else:
|
|
36
|
+
return {"result": f"Weather information not found for {city}"}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def get_location_weather(city: str) -> dict[str, str]:
|
|
40
|
+
"""Retrieves the weather information of a given city. the args must in English"""
|
|
41
|
+
import random
|
|
42
|
+
|
|
43
|
+
condition = random.choice(
|
|
44
|
+
[
|
|
45
|
+
"Sunny",
|
|
46
|
+
"Cloudy",
|
|
47
|
+
"Rainy",
|
|
48
|
+
"Partly cloudy",
|
|
49
|
+
"Windy",
|
|
50
|
+
"Snowy",
|
|
51
|
+
"Humid",
|
|
52
|
+
"Hazy",
|
|
53
|
+
"Cool",
|
|
54
|
+
"Hot",
|
|
55
|
+
]
|
|
56
|
+
)
|
|
57
|
+
temperature = random.randint(-10, 40)
|
|
58
|
+
return {"result": f"{condition}, {temperature}°C"}
|
|
@@ -0,0 +1,149 @@
|
|
|
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 typing import TYPE_CHECKING
|
|
18
|
+
|
|
19
|
+
import wrapt
|
|
20
|
+
from google.adk.tools.function_tool import FunctionTool
|
|
21
|
+
from google.adk.tools.tool_context import ToolContext
|
|
22
|
+
from google.genai import types
|
|
23
|
+
from pydantic import BaseModel, Field
|
|
24
|
+
from typing_extensions import override
|
|
25
|
+
|
|
26
|
+
from veadk.knowledgebase import KnowledgeBase
|
|
27
|
+
from veadk.knowledgebase.entry import KnowledgebaseEntry
|
|
28
|
+
from veadk.utils.logger import get_logger
|
|
29
|
+
|
|
30
|
+
logger = get_logger(__name__)
|
|
31
|
+
|
|
32
|
+
if TYPE_CHECKING:
|
|
33
|
+
from google.adk.models.llm_request import LlmRequest
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
knowledgebase: KnowledgeBase | None = None
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class LoadKnowledgebaseResponse(BaseModel):
|
|
40
|
+
knowledges: list[KnowledgebaseEntry] = Field(default_factory=list)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class SearchKnowledgebaseResponse(BaseModel):
|
|
44
|
+
"""Represents the response from a knowledgebase search.
|
|
45
|
+
|
|
46
|
+
Attributes:
|
|
47
|
+
knowledges: A list of knowledgebase entries that relate to the search query.
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
knowledges: list[KnowledgebaseEntry] = Field(default_factory=list)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
async def search_knowledgebase(
|
|
54
|
+
self, query: str, app_name: str
|
|
55
|
+
) -> SearchKnowledgebaseResponse:
|
|
56
|
+
"""Searches the knowledgebase of the current user."""
|
|
57
|
+
if isinstance(knowledgebase, KnowledgeBase):
|
|
58
|
+
entry_list = knowledgebase.search(query)
|
|
59
|
+
return SearchKnowledgebaseResponse(knowledges=entry_list)
|
|
60
|
+
else:
|
|
61
|
+
return SearchKnowledgebaseResponse(knowledges=[])
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
@wrapt.when_imported("google.adk.tools.tool_context")
|
|
65
|
+
def on_tool_context_imported(module):
|
|
66
|
+
class_ = getattr(module, "ToolContext", None)
|
|
67
|
+
if not class_:
|
|
68
|
+
raise ImportError("Could not find ToolContext in module")
|
|
69
|
+
|
|
70
|
+
if not hasattr(class_, "search_knowledgebase"):
|
|
71
|
+
class_.search_knowledgebase = search_knowledgebase
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
async def load_knowledgebase(
|
|
75
|
+
query: str, tool_context: ToolContext
|
|
76
|
+
) -> LoadKnowledgebaseResponse:
|
|
77
|
+
"""Loads the knowledgebase for the user.
|
|
78
|
+
|
|
79
|
+
Args:
|
|
80
|
+
query: The query to load the knowledgebase for.
|
|
81
|
+
|
|
82
|
+
Returns:
|
|
83
|
+
A list of knowledgebase results.
|
|
84
|
+
"""
|
|
85
|
+
|
|
86
|
+
search_knowledgebase_response = await tool_context.search_knowledgebase( # type: ignore[attr-defined]
|
|
87
|
+
query, tool_context._invocation_context.app_name
|
|
88
|
+
)
|
|
89
|
+
return LoadKnowledgebaseResponse(
|
|
90
|
+
knowledges=search_knowledgebase_response.knowledges
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
class LoadKnowledgebaseTool(FunctionTool):
|
|
95
|
+
"""A tool that loads the common knowledgebase.
|
|
96
|
+
|
|
97
|
+
In the future, we will support multiple knowledgebase based on different user.
|
|
98
|
+
"""
|
|
99
|
+
|
|
100
|
+
def __init__(self):
|
|
101
|
+
super().__init__(load_knowledgebase)
|
|
102
|
+
global knowledgebase
|
|
103
|
+
if knowledgebase is None:
|
|
104
|
+
logger.info(
|
|
105
|
+
"Get global knowledgebase instance failed, failed to set knowledgebase tool backend."
|
|
106
|
+
)
|
|
107
|
+
else:
|
|
108
|
+
if not self.custom_metadata:
|
|
109
|
+
self.custom_metadata = {}
|
|
110
|
+
self.custom_metadata["backend"] = knowledgebase.backend
|
|
111
|
+
|
|
112
|
+
@override
|
|
113
|
+
def _get_declaration(self) -> types.FunctionDeclaration | None:
|
|
114
|
+
return types.FunctionDeclaration(
|
|
115
|
+
name=self.name,
|
|
116
|
+
description=self.description,
|
|
117
|
+
parameters=types.Schema(
|
|
118
|
+
type=types.Type.OBJECT,
|
|
119
|
+
properties={
|
|
120
|
+
"query": types.Schema(
|
|
121
|
+
type=types.Type.STRING,
|
|
122
|
+
)
|
|
123
|
+
},
|
|
124
|
+
required=["query"],
|
|
125
|
+
),
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
@override
|
|
129
|
+
async def process_llm_request(
|
|
130
|
+
self,
|
|
131
|
+
*,
|
|
132
|
+
tool_context: ToolContext,
|
|
133
|
+
llm_request: LlmRequest,
|
|
134
|
+
) -> None:
|
|
135
|
+
await super().process_llm_request(
|
|
136
|
+
tool_context=tool_context, llm_request=llm_request
|
|
137
|
+
)
|
|
138
|
+
# Tell the model about the knowledgebase.
|
|
139
|
+
llm_request.append_instructions(
|
|
140
|
+
[
|
|
141
|
+
"""
|
|
142
|
+
You have a knowledgebase. You can use it to answer questions. If any questions need
|
|
143
|
+
you to look up the knowledgebase, you should call load_knowledgebase function with a query.
|
|
144
|
+
"""
|
|
145
|
+
]
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
load_knowledgebase_tool = LoadKnowledgebaseTool()
|
|
@@ -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,37 @@
|
|
|
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 google.adk.tools.mcp_tool.mcp_toolset import MCPToolset
|
|
16
|
+
|
|
17
|
+
from veadk.config import getenv
|
|
18
|
+
from veadk.utils.mcp_utils import get_mcp_params
|
|
19
|
+
|
|
20
|
+
url = getenv("TOOL_BROWSER_SANDBOX_URL")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
browser_sandbox = MCPToolset(connection_params=get_mcp_params(url=url))
|
|
24
|
+
|
|
25
|
+
# browser_sandbox = ...
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# def browser_use(prompt: str) -> str:
|
|
29
|
+
# """Using the remote browser sandbox to according to the prompt.
|
|
30
|
+
|
|
31
|
+
# Args:
|
|
32
|
+
# prompt (str): The prompt to be used.
|
|
33
|
+
|
|
34
|
+
# Returns:
|
|
35
|
+
# str: The response from the sandbox.
|
|
36
|
+
# """
|
|
37
|
+
# ...
|
|
@@ -0,0 +1,40 @@
|
|
|
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 google.adk.tools.mcp_tool.mcp_toolset import MCPToolset
|
|
16
|
+
|
|
17
|
+
from veadk.config import getenv
|
|
18
|
+
from veadk.utils.mcp_utils import get_mcp_params
|
|
19
|
+
|
|
20
|
+
url = getenv("TOOL_CODE_SANDBOX_URL")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
code_sandbox = MCPToolset(connection_params=get_mcp_params(url=url))
|
|
24
|
+
|
|
25
|
+
# code_sandbox = ...
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# def code_execution(code: str, language: str) -> str:
|
|
29
|
+
# """Execute code in sandbox.
|
|
30
|
+
|
|
31
|
+
# Args:
|
|
32
|
+
# code (str): The code to be executed.
|
|
33
|
+
# language (str): The language of the code.
|
|
34
|
+
|
|
35
|
+
# Returns:
|
|
36
|
+
# str: The response from the sandbox.
|
|
37
|
+
# """
|
|
38
|
+
|
|
39
|
+
# res = code_sandbox(code, language)
|
|
40
|
+
# return res
|
|
@@ -0,0 +1,34 @@
|
|
|
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 google.adk.tools.mcp_tool.mcp_toolset import MCPToolset
|
|
16
|
+
|
|
17
|
+
from veadk.config import getenv
|
|
18
|
+
from veadk.utils.mcp_utils import get_mcp_params
|
|
19
|
+
|
|
20
|
+
url = getenv("TOOL_COMPUTER_SANDBOX_URL")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
computer_sandbox = MCPToolset(connection_params=get_mcp_params(url=url))
|
|
24
|
+
|
|
25
|
+
# def computer_use(prompt: str) -> str:
|
|
26
|
+
# """Using the remote computer sandbox to according to the prompt.
|
|
27
|
+
|
|
28
|
+
# Args:
|
|
29
|
+
# prompt (str): The prompt to be used.
|
|
30
|
+
|
|
31
|
+
# Returns:
|
|
32
|
+
# str: The response from the sandbox.
|
|
33
|
+
# """
|
|
34
|
+
# ...
|
|
@@ -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,58 @@
|
|
|
1
|
+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from abc import ABC, abstractmethod
|
|
16
|
+
|
|
17
|
+
from veadk.utils.logger import get_logger
|
|
18
|
+
|
|
19
|
+
logger = get_logger(__name__)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class BaseTracer(ABC):
|
|
23
|
+
"""Abstract base class for implementing tracing functionality in VeADK agents.
|
|
24
|
+
|
|
25
|
+
BaseTracer provides the foundation for collecting, managing, and exporting
|
|
26
|
+
trace data from agent execution sessions. It defines the interface that all
|
|
27
|
+
concrete tracer implementations must follow, enabling pluggable tracing
|
|
28
|
+
backends for different observability platforms.
|
|
29
|
+
|
|
30
|
+
Attributes:
|
|
31
|
+
name: Unique identifier for this tracer instance
|
|
32
|
+
_trace_id: Internal trace identifier for current execution context
|
|
33
|
+
_trace_file_path: Path to the current trace data file
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
def __init__(self, name: str):
|
|
37
|
+
"""Initialize a new BaseTracer instance.
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
name: Unique identifier for this tracer instance.
|
|
41
|
+
"""
|
|
42
|
+
self.name = name
|
|
43
|
+
self._trace_id = "<unknown_trace_id>"
|
|
44
|
+
self._trace_file_path = "<unknown_trace_file_path>"
|
|
45
|
+
|
|
46
|
+
@abstractmethod
|
|
47
|
+
def dump(self, user_id: str, session_id: str, path: str) -> str:
|
|
48
|
+
"""Dump the collected trace data to a local file.
|
|
49
|
+
|
|
50
|
+
This method must be implemented by concrete tracer classes to export
|
|
51
|
+
trace data in a format suitable for analysis or storage.
|
|
52
|
+
|
|
53
|
+
Args:
|
|
54
|
+
user_id: User identifier for trace organization and file naming
|
|
55
|
+
session_id: Session identifier for filtering and organizing spans
|
|
56
|
+
path: Directory path for the output file
|
|
57
|
+
"""
|
|
58
|
+
...
|
|
@@ -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,29 @@
|
|
|
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 veadk.tracing.telemetry.attributes.extractors.common_attributes_extractors import (
|
|
16
|
+
COMMON_ATTRIBUTES,
|
|
17
|
+
)
|
|
18
|
+
from veadk.tracing.telemetry.attributes.extractors.llm_attributes_extractors import (
|
|
19
|
+
LLM_ATTRIBUTES,
|
|
20
|
+
)
|
|
21
|
+
from veadk.tracing.telemetry.attributes.extractors.tool_attributes_extractors import (
|
|
22
|
+
TOOL_ATTRIBUTES,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
ATTRIBUTES = {
|
|
26
|
+
"common": COMMON_ATTRIBUTES,
|
|
27
|
+
"llm": LLM_ATTRIBUTES,
|
|
28
|
+
"tool": TOOL_ATTRIBUTES,
|
|
29
|
+
}
|