veadk-python 0.1.0__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.
- veadk/__init__.py +31 -0
- veadk/a2a/__init__.py +13 -0
- veadk/a2a/agent_card.py +45 -0
- veadk/a2a/remote_ve_agent.py +19 -0
- veadk/a2a/ve_a2a_server.py +77 -0
- veadk/a2a/ve_agent_executor.py +78 -0
- veadk/a2a/ve_task_store.py +37 -0
- veadk/agent.py +253 -0
- veadk/cli/__init__.py +13 -0
- veadk/cli/main.py +278 -0
- veadk/cli/services/agentpilot/__init__.py +17 -0
- veadk/cli/services/agentpilot/agentpilot.py +77 -0
- veadk/cli/services/veapig/__init__.py +17 -0
- veadk/cli/services/veapig/apig.py +224 -0
- veadk/cli/services/veapig/apig_utils.py +332 -0
- veadk/cli/services/vefaas/__init__.py +17 -0
- veadk/cli/services/vefaas/template/deploy.py +44 -0
- veadk/cli/services/vefaas/template/src/app.py +30 -0
- veadk/cli/services/vefaas/template/src/config.py +58 -0
- veadk/cli/services/vefaas/vefaas.py +346 -0
- veadk/cli/services/vefaas/vefaas_utils.py +408 -0
- veadk/cli/services/vetls/__init__.py +17 -0
- veadk/cli/services/vetls/vetls.py +87 -0
- veadk/cli/studio/__init__.py +13 -0
- veadk/cli/studio/agent_processor.py +247 -0
- veadk/cli/studio/fast_api.py +232 -0
- veadk/cli/studio/model.py +116 -0
- veadk/cloud/__init__.py +13 -0
- veadk/cloud/cloud_agent_engine.py +144 -0
- veadk/cloud/cloud_app.py +123 -0
- veadk/cloud/template/app.py +30 -0
- veadk/cloud/template/config.py +55 -0
- veadk/config.py +131 -0
- veadk/consts.py +17 -0
- veadk/database/__init__.py +17 -0
- veadk/database/base_database.py +45 -0
- veadk/database/database_factory.py +80 -0
- veadk/database/kv/__init__.py +13 -0
- veadk/database/kv/redis_database.py +109 -0
- veadk/database/local_database.py +43 -0
- veadk/database/relational/__init__.py +13 -0
- veadk/database/relational/mysql_database.py +114 -0
- veadk/database/vector/__init__.py +13 -0
- veadk/database/vector/opensearch_vector_database.py +205 -0
- veadk/database/vector/type.py +50 -0
- veadk/database/viking/__init__.py +13 -0
- veadk/database/viking/viking_database.py +378 -0
- veadk/database/viking/viking_memory_db.py +521 -0
- veadk/evaluation/__init__.py +17 -0
- veadk/evaluation/adk_evaluator/__init__.py +13 -0
- veadk/evaluation/adk_evaluator/adk_evaluator.py +291 -0
- veadk/evaluation/base_evaluator.py +242 -0
- veadk/evaluation/deepeval_evaluator/__init__.py +17 -0
- veadk/evaluation/deepeval_evaluator/deepeval_evaluator.py +223 -0
- veadk/evaluation/eval_set_file_loader.py +28 -0
- veadk/evaluation/eval_set_recorder.py +91 -0
- veadk/evaluation/utils/prometheus.py +142 -0
- veadk/knowledgebase/__init__.py +17 -0
- veadk/knowledgebase/knowledgebase.py +83 -0
- veadk/knowledgebase/knowledgebase_database_adapter.py +259 -0
- veadk/memory/__init__.py +13 -0
- veadk/memory/long_term_memory.py +119 -0
- veadk/memory/memory_database_adapter.py +235 -0
- veadk/memory/short_term_memory.py +124 -0
- veadk/memory/short_term_memory_processor.py +90 -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 +158 -0
- veadk/runner.py +252 -0
- veadk/tools/__init__.py +13 -0
- veadk/tools/builtin_tools/__init__.py +13 -0
- veadk/tools/builtin_tools/lark.py +67 -0
- veadk/tools/builtin_tools/las.py +23 -0
- veadk/tools/builtin_tools/vesearch.py +49 -0
- veadk/tools/builtin_tools/web_scraper.py +76 -0
- veadk/tools/builtin_tools/web_search.py +192 -0
- veadk/tools/demo_tools.py +58 -0
- veadk/tools/load_knowledgebase_tool.py +144 -0
- veadk/tools/sandbox/__init__.py +13 -0
- veadk/tools/sandbox/browser_sandbox.py +27 -0
- veadk/tools/sandbox/code_sandbox.py +30 -0
- veadk/tools/sandbox/computer_sandbox.py +27 -0
- veadk/tracing/__init__.py +13 -0
- veadk/tracing/base_tracer.py +172 -0
- veadk/tracing/telemetry/__init__.py +13 -0
- veadk/tracing/telemetry/exporters/__init__.py +13 -0
- veadk/tracing/telemetry/exporters/apiserver_exporter.py +60 -0
- veadk/tracing/telemetry/exporters/apmplus_exporter.py +101 -0
- veadk/tracing/telemetry/exporters/base_exporter.py +28 -0
- veadk/tracing/telemetry/exporters/cozeloop_exporter.py +69 -0
- veadk/tracing/telemetry/exporters/inmemory_exporter.py +88 -0
- veadk/tracing/telemetry/exporters/tls_exporter.py +78 -0
- veadk/tracing/telemetry/metrics/__init__.py +13 -0
- veadk/tracing/telemetry/metrics/opentelemetry_metrics.py +73 -0
- veadk/tracing/telemetry/opentelemetry_tracer.py +167 -0
- veadk/types.py +23 -0
- veadk/utils/__init__.py +13 -0
- veadk/utils/logger.py +59 -0
- veadk/utils/misc.py +33 -0
- veadk/utils/patches.py +85 -0
- veadk/utils/volcengine_sign.py +199 -0
- veadk/version.py +15 -0
- veadk_python-0.1.0.dist-info/METADATA +124 -0
- veadk_python-0.1.0.dist-info/RECORD +110 -0
- veadk_python-0.1.0.dist-info/WHEEL +5 -0
- veadk_python-0.1.0.dist-info/entry_points.txt +2 -0
- veadk_python-0.1.0.dist-info/licenses/LICENSE +201 -0
- veadk_python-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import os
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
from typing import Any
|
|
18
|
+
|
|
19
|
+
from pydantic import BaseModel
|
|
20
|
+
|
|
21
|
+
from veadk.cli.services.vefaas import VeFaaS
|
|
22
|
+
from veadk.cloud.cloud_app import CloudApp
|
|
23
|
+
from veadk.config import getenv
|
|
24
|
+
from veadk.utils.logger import get_logger
|
|
25
|
+
from veadk.utils.misc import formatted_timestamp
|
|
26
|
+
|
|
27
|
+
logger = get_logger(__name__)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class CloudAgentEngine(BaseModel):
|
|
31
|
+
volcengine_access_key: str = getenv("VOLCENGINE_ACCESS_KEY")
|
|
32
|
+
volcengine_secret_key: str = getenv("VOLCENGINE_SECRET_KEY")
|
|
33
|
+
region: str = "cn-beijing"
|
|
34
|
+
|
|
35
|
+
def model_post_init(self, context: Any, /) -> None:
|
|
36
|
+
self._vefaas_service = VeFaaS(
|
|
37
|
+
access_key=self.volcengine_access_key,
|
|
38
|
+
secret_key=self.volcengine_secret_key,
|
|
39
|
+
region=self.region,
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
def _prepare(self, path: str, name: str):
|
|
43
|
+
# VeFaaS path check
|
|
44
|
+
if "_" in name:
|
|
45
|
+
raise ValueError(
|
|
46
|
+
f"Invalid Volcengine FaaS function name `{name}`, please use lowercase letters and numbers, or replace it with a `-` char."
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
# project path check
|
|
50
|
+
assert os.path.exists(path), f"Local agent project path `{path}` not exists."
|
|
51
|
+
assert os.path.isdir(path), (
|
|
52
|
+
f"Local agent project path `{path}` is not a directory."
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
assert os.path.exists(os.path.join(path, "config.py")), (
|
|
56
|
+
f"Local agent project path `{path}` does not contain `config.py` file. Please prepare it according to veadk-python/cloud/template/config.py.example"
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
if os.path.exists(os.path.join(path, "app.py")):
|
|
60
|
+
logger.warning(
|
|
61
|
+
f"Local agent project path `{path}` contains an `app.py` file. Use your own `app.py` file may cause unexpected behavior."
|
|
62
|
+
)
|
|
63
|
+
else:
|
|
64
|
+
logger.info(
|
|
65
|
+
f"No `app.py` detected in local agent project path `{path}`. Prepare it."
|
|
66
|
+
)
|
|
67
|
+
template_app_py = (
|
|
68
|
+
f"{Path(__file__).resolve().parent.resolve()}/template/app.py"
|
|
69
|
+
)
|
|
70
|
+
import shutil
|
|
71
|
+
|
|
72
|
+
shutil.copy(template_app_py, os.path.join(path, "app.py"))
|
|
73
|
+
|
|
74
|
+
if os.path.exists(os.path.join(path, "run.sh")):
|
|
75
|
+
logger.warning(
|
|
76
|
+
f"Local agent project path `{path}` contains a `run.sh` file. Use your own `run.sh` file may cause unexpected behavior."
|
|
77
|
+
)
|
|
78
|
+
else:
|
|
79
|
+
logger.info(
|
|
80
|
+
f"No `run.sh` detected in local agent project path `{path}`. Prepare it."
|
|
81
|
+
)
|
|
82
|
+
template_run_sh = (
|
|
83
|
+
f"{Path(__file__).resolve().parent.resolve()}/template/run.sh"
|
|
84
|
+
)
|
|
85
|
+
import shutil
|
|
86
|
+
|
|
87
|
+
shutil.copy(template_run_sh, os.path.join(path, "run.sh"))
|
|
88
|
+
|
|
89
|
+
def deploy(
|
|
90
|
+
self,
|
|
91
|
+
path: str,
|
|
92
|
+
name: str,
|
|
93
|
+
gateway_name: str = "",
|
|
94
|
+
gateway_service_name: str = "",
|
|
95
|
+
gateway_upstream_name: str = "",
|
|
96
|
+
) -> CloudApp:
|
|
97
|
+
"""Deploy local agent project to Volcengine FaaS platform.
|
|
98
|
+
|
|
99
|
+
Args:
|
|
100
|
+
path (str): Local agent project path.
|
|
101
|
+
name (str): Volcengine FaaS function name.
|
|
102
|
+
|
|
103
|
+
Returns:
|
|
104
|
+
str: Volcengine FaaS function endpoint.
|
|
105
|
+
"""
|
|
106
|
+
# convert `path` to absolute path
|
|
107
|
+
path = str(Path(path).resolve())
|
|
108
|
+
self._prepare(path, name)
|
|
109
|
+
|
|
110
|
+
if not gateway_name:
|
|
111
|
+
gateway_name = f"{name}-gw-{formatted_timestamp()}"
|
|
112
|
+
if not gateway_service_name:
|
|
113
|
+
gateway_service_name = f"{name}-gw-svr-{formatted_timestamp()}"
|
|
114
|
+
if not gateway_upstream_name:
|
|
115
|
+
gateway_upstream_name = f"{name}-gw-us-{formatted_timestamp()}"
|
|
116
|
+
|
|
117
|
+
try:
|
|
118
|
+
vefaas_application_url, app_id, function_id = self._vefaas_service.deploy(
|
|
119
|
+
path=path,
|
|
120
|
+
name=name,
|
|
121
|
+
gateway_name=gateway_name,
|
|
122
|
+
gateway_service_name=gateway_service_name,
|
|
123
|
+
gateway_upstream_name=gateway_upstream_name,
|
|
124
|
+
)
|
|
125
|
+
_ = function_id # for future use
|
|
126
|
+
|
|
127
|
+
return CloudApp(
|
|
128
|
+
name=name,
|
|
129
|
+
endpoint=vefaas_application_url,
|
|
130
|
+
app_id=app_id,
|
|
131
|
+
)
|
|
132
|
+
except Exception as e:
|
|
133
|
+
raise ValueError(
|
|
134
|
+
f"Failed to deploy local agent project to Volcengine FaaS platform. Error: {e}"
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
def remove(self, app_name: str):
|
|
138
|
+
confirm = input(f"Confirm delete cloud app {app_name}? (y/N): ")
|
|
139
|
+
if confirm.lower() != "y":
|
|
140
|
+
print("Delete cancelled.")
|
|
141
|
+
return
|
|
142
|
+
else:
|
|
143
|
+
app_id = self._vefaas_service.find_app_id_by_name(app_name)
|
|
144
|
+
self._vefaas_service.delete(app_id)
|
veadk/cloud/cloud_app.py
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
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
|
+
from uuid import uuid4
|
|
17
|
+
|
|
18
|
+
import httpx
|
|
19
|
+
from a2a.client import A2ACardResolver, A2AClient
|
|
20
|
+
from a2a.types import AgentCard, Message, MessageSendParams, SendMessageRequest
|
|
21
|
+
|
|
22
|
+
from veadk.utils.logger import get_logger
|
|
23
|
+
|
|
24
|
+
logger = get_logger(__name__)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class CloudApp:
|
|
28
|
+
"""CloudApp class.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
name (str): The name of the cloud app.
|
|
32
|
+
endpoint (str): The endpoint of the cloud app.
|
|
33
|
+
use_agent_card (bool): Whether to use agent card to invoke agent. If True, the client will post to the url in agent card. Otherwise, the client will post to the endpoint directly. Default False (cause the agent card and agent usually use the same endpoint).
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
def __init__(
|
|
37
|
+
self,
|
|
38
|
+
name: str,
|
|
39
|
+
endpoint: str,
|
|
40
|
+
app_id: str,
|
|
41
|
+
use_agent_card: bool = False,
|
|
42
|
+
):
|
|
43
|
+
self.endpoint = endpoint
|
|
44
|
+
self.app_id = app_id
|
|
45
|
+
self.name = name
|
|
46
|
+
self.use_agent_card = use_agent_card
|
|
47
|
+
|
|
48
|
+
if not endpoint.startswith("http") and not endpoint.startswith("https"):
|
|
49
|
+
raise ValueError(
|
|
50
|
+
f"Invalid endpoint: {endpoint}. The endpoint must start with `http` or `https`."
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
if use_agent_card:
|
|
54
|
+
logger.info(
|
|
55
|
+
"Use agent card to invoke agent. The agent endpoint will use the `url` in agent card."
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
self.httpx_client = httpx.AsyncClient()
|
|
59
|
+
|
|
60
|
+
async def _get_a2a_client(self) -> A2AClient:
|
|
61
|
+
if self.use_agent_card:
|
|
62
|
+
async with self.httpx_client as httpx_client:
|
|
63
|
+
resolver = A2ACardResolver(
|
|
64
|
+
httpx_client=httpx_client, base_url=self.endpoint
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
final_agent_card_to_use: AgentCard | None = None
|
|
68
|
+
_public_card = (
|
|
69
|
+
await resolver.get_agent_card()
|
|
70
|
+
) # Fetches from default public path
|
|
71
|
+
final_agent_card_to_use = _public_card
|
|
72
|
+
|
|
73
|
+
return A2AClient(
|
|
74
|
+
httpx_client=self.httpx_client, agent_card=final_agent_card_to_use
|
|
75
|
+
)
|
|
76
|
+
else:
|
|
77
|
+
return A2AClient(httpx_client=self.httpx_client, url=self.endpoint)
|
|
78
|
+
|
|
79
|
+
def delete_self(self, volcengine_ak: str, volcengine_sk: str):
|
|
80
|
+
confirm = input(f"Confirm delete cloud app {self.app_id}? (y/N): ")
|
|
81
|
+
if confirm.lower() != "y":
|
|
82
|
+
print("Delete cancelled.")
|
|
83
|
+
return
|
|
84
|
+
else:
|
|
85
|
+
from veadk.cli.services.vefaas.vefaas import VeFaaS
|
|
86
|
+
|
|
87
|
+
vefaas_client = VeFaaS(access_key=volcengine_ak, secret_key=volcengine_sk)
|
|
88
|
+
vefaas_client.delete(self.app_id)
|
|
89
|
+
print(f"Cloud app {self.app_id} is deleting...")
|
|
90
|
+
|
|
91
|
+
async def message_send(
|
|
92
|
+
self, message: str, session_id: str, user_id: str, timeout: float = 600.0
|
|
93
|
+
) -> Message | None:
|
|
94
|
+
"""
|
|
95
|
+
timeout is in seconds, default 600s (10 minutes)
|
|
96
|
+
"""
|
|
97
|
+
a2a_client = await self._get_a2a_client()
|
|
98
|
+
|
|
99
|
+
async with self.httpx_client:
|
|
100
|
+
send_message_payload: dict[str, Any] = {
|
|
101
|
+
"message": {
|
|
102
|
+
"role": "user",
|
|
103
|
+
"parts": [{"type": "text", "text": message}],
|
|
104
|
+
"messageId": uuid4().hex,
|
|
105
|
+
},
|
|
106
|
+
"metadata": {
|
|
107
|
+
"user_id": user_id,
|
|
108
|
+
"session_id": session_id,
|
|
109
|
+
},
|
|
110
|
+
}
|
|
111
|
+
try:
|
|
112
|
+
message_send_request = SendMessageRequest(
|
|
113
|
+
id=uuid4().hex,
|
|
114
|
+
params=MessageSendParams(**send_message_payload),
|
|
115
|
+
)
|
|
116
|
+
res = await a2a_client.send_message(
|
|
117
|
+
message_send_request,
|
|
118
|
+
http_kwargs={"timeout": httpx.Timeout(timeout)},
|
|
119
|
+
)
|
|
120
|
+
return res.root.result
|
|
121
|
+
except Exception as e:
|
|
122
|
+
print(e)
|
|
123
|
+
return None
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import os
|
|
16
|
+
|
|
17
|
+
from config import AGENT, APP_NAME, SHORT_TERM_MEMORY, TRACERS
|
|
18
|
+
|
|
19
|
+
from veadk.a2a.ve_a2a_server import init_app
|
|
20
|
+
|
|
21
|
+
SERVER_HOST = os.getenv("SERVER_HOST")
|
|
22
|
+
|
|
23
|
+
AGENT.tracers = TRACERS
|
|
24
|
+
|
|
25
|
+
app = init_app(
|
|
26
|
+
server_url=SERVER_HOST,
|
|
27
|
+
app_name=APP_NAME,
|
|
28
|
+
agent=AGENT,
|
|
29
|
+
short_term_memory=SHORT_TERM_MEMORY,
|
|
30
|
+
)
|
|
@@ -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
|
+
import os
|
|
16
|
+
|
|
17
|
+
from veadk import Agent
|
|
18
|
+
from veadk.memory.short_term_memory import ShortTermMemory
|
|
19
|
+
from veadk.tracing.base_tracer import BaseTracer
|
|
20
|
+
from veadk.tracing.telemetry.opentelemetry_tracer import OpentelemetryTracer
|
|
21
|
+
|
|
22
|
+
# =============
|
|
23
|
+
# Generated by VeADK, do not edit!!!
|
|
24
|
+
# =============
|
|
25
|
+
TRACERS: list[BaseTracer] = []
|
|
26
|
+
|
|
27
|
+
exporters = []
|
|
28
|
+
if os.getenv("VEADK_TRACER_APMPLUS") == "true":
|
|
29
|
+
from veadk.tracing.telemetry.exporters.apmplus_exporter import APMPlusExporter
|
|
30
|
+
|
|
31
|
+
exporters.append(APMPlusExporter())
|
|
32
|
+
|
|
33
|
+
if os.getenv("VEADK_TRACER_COZELOOP") == "true":
|
|
34
|
+
from veadk.tracing.telemetry.exporters.cozeloop_exporter import CozeloopExporter
|
|
35
|
+
|
|
36
|
+
exporters.append(CozeloopExporter())
|
|
37
|
+
|
|
38
|
+
if os.getenv("VEADK_TRACER_TLS") == "true":
|
|
39
|
+
from veadk.tracing.telemetry.exporters.tls_exporter import TLSExporter
|
|
40
|
+
|
|
41
|
+
exporters.append(TLSExporter())
|
|
42
|
+
|
|
43
|
+
TRACERS.append(OpentelemetryTracer(exporters=exporters))
|
|
44
|
+
|
|
45
|
+
# =============
|
|
46
|
+
# Required [you can edit here]
|
|
47
|
+
# =============
|
|
48
|
+
APP_NAME: str = ... # <--- export your app name
|
|
49
|
+
AGENT: Agent = ... # <--- export your agent
|
|
50
|
+
SHORT_TERM_MEMORY: ShortTermMemory = ... # <--- export your short term memory
|
|
51
|
+
|
|
52
|
+
# =============
|
|
53
|
+
# Optional
|
|
54
|
+
# =============
|
|
55
|
+
# Other global variables
|
veadk/config.py
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import os
|
|
16
|
+
from typing import Any, Dict, List, MutableMapping, Tuple
|
|
17
|
+
|
|
18
|
+
from dotenv import find_dotenv
|
|
19
|
+
from pydantic_settings import (
|
|
20
|
+
BaseSettings,
|
|
21
|
+
InitSettingsSource,
|
|
22
|
+
PydanticBaseSettingsSource,
|
|
23
|
+
SettingsConfigDict,
|
|
24
|
+
YamlConfigSettingsSource,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
settings = None
|
|
28
|
+
veadk_environments = {}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def flatten_dict(
|
|
32
|
+
d: MutableMapping[str, Any], parent_key: str = "", sep: str = "_"
|
|
33
|
+
) -> Dict[str, Any]:
|
|
34
|
+
"""Flatten a nested dictionary, using a separator in the keys.
|
|
35
|
+
Useful for pydantic_v1 models with nested fields -- first use
|
|
36
|
+
dct = mdl.model_dump()
|
|
37
|
+
to get a nested dictionary, then use this function to flatten it.
|
|
38
|
+
"""
|
|
39
|
+
items: List[Tuple[str, Any]] = []
|
|
40
|
+
for k, v in d.items():
|
|
41
|
+
new_key = f"{parent_key}{sep}{k}" if parent_key else k
|
|
42
|
+
if isinstance(v, MutableMapping):
|
|
43
|
+
items.extend(flatten_dict(v, new_key, sep=sep).items())
|
|
44
|
+
else:
|
|
45
|
+
items.append((new_key, v))
|
|
46
|
+
return dict(items)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class Settings(BaseSettings):
|
|
50
|
+
model_config = SettingsConfigDict(
|
|
51
|
+
yaml_file=find_dotenv(filename="config.yaml", usecwd=True), extra="allow"
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
@classmethod
|
|
55
|
+
def settings_customise_sources(
|
|
56
|
+
cls,
|
|
57
|
+
settings_cls: type[BaseSettings],
|
|
58
|
+
init_settings: PydanticBaseSettingsSource,
|
|
59
|
+
env_settings: PydanticBaseSettingsSource,
|
|
60
|
+
dotenv_settings: PydanticBaseSettingsSource,
|
|
61
|
+
file_secret_settings: PydanticBaseSettingsSource,
|
|
62
|
+
) -> tuple[PydanticBaseSettingsSource, ...]:
|
|
63
|
+
yaml_source = YamlConfigSettingsSource(settings_cls)
|
|
64
|
+
raw_data = yaml_source()
|
|
65
|
+
flat_data = flatten_dict(raw_data)
|
|
66
|
+
|
|
67
|
+
init_source = InitSettingsSource(settings_cls, flat_data)
|
|
68
|
+
return (
|
|
69
|
+
init_source,
|
|
70
|
+
env_settings,
|
|
71
|
+
dotenv_settings,
|
|
72
|
+
file_secret_settings,
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def prepare_settings():
|
|
77
|
+
path = find_dotenv(filename="config.yaml", usecwd=True)
|
|
78
|
+
|
|
79
|
+
if path == "" or path is None or not os.path.exists(path):
|
|
80
|
+
# logger.warning(
|
|
81
|
+
# "Default and recommanded config file `config.yaml` not found. Please put it in the root directory of your project."
|
|
82
|
+
# )
|
|
83
|
+
pass
|
|
84
|
+
else:
|
|
85
|
+
# logger.info(f"Loading config file from {path}")
|
|
86
|
+
global settings
|
|
87
|
+
settings = Settings()
|
|
88
|
+
|
|
89
|
+
for k, v in settings.model_dump().items():
|
|
90
|
+
global veadk_environments
|
|
91
|
+
|
|
92
|
+
k = k.upper()
|
|
93
|
+
if k in os.environ:
|
|
94
|
+
veadk_environments[k] = os.environ[k]
|
|
95
|
+
continue
|
|
96
|
+
veadk_environments[k] = str(v)
|
|
97
|
+
os.environ[k] = str(v)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
prepare_settings()
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def get_envlist():
|
|
104
|
+
return os.environ.keys()
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def getenv(
|
|
108
|
+
env_name: str, default_value: Any = "", allow_false_values: bool = False
|
|
109
|
+
) -> str:
|
|
110
|
+
"""
|
|
111
|
+
Get environment variable.
|
|
112
|
+
|
|
113
|
+
Args:
|
|
114
|
+
env_name (str): The name of the environment variable.
|
|
115
|
+
default_value (str): The default value of the environment variable.
|
|
116
|
+
allow_false_values (bool, optional): Whether to allow the environment variable to be None or false values. Defaults to False.
|
|
117
|
+
|
|
118
|
+
Returns:
|
|
119
|
+
str: The value of the environment variable.
|
|
120
|
+
"""
|
|
121
|
+
value = os.getenv(env_name, default_value)
|
|
122
|
+
|
|
123
|
+
if allow_false_values:
|
|
124
|
+
return value
|
|
125
|
+
|
|
126
|
+
if value:
|
|
127
|
+
return value
|
|
128
|
+
else:
|
|
129
|
+
raise ValueError(
|
|
130
|
+
f"The environment variable `{env_name}` not exists. Please set this in your environment variable or config.yaml."
|
|
131
|
+
)
|
veadk/consts.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
DEFAULT_MODEL_AGENT_NAME = "doubao-seed-1-6-250615"
|
|
16
|
+
DEFALUT_MODEL_AGENT_PROVIDER = "openai"
|
|
17
|
+
DEFAULT_MODEL_AGENT_API_BASE = "https://ark.cn-beijing.volces.com/api/v3/"
|
|
@@ -0,0 +1,17 @@
|
|
|
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 .database_factory import DatabaseFactory
|
|
16
|
+
|
|
17
|
+
__all__ = ["DatabaseFactory"]
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
from typing import Any
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class DatabaseType:
|
|
20
|
+
LOCAL = "local"
|
|
21
|
+
RELATIONAL = "relational"
|
|
22
|
+
VECTOR = "vector"
|
|
23
|
+
KV = "kv"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class BaseDatabase(ABC):
|
|
27
|
+
"""Base class for database.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
type: type of the database
|
|
31
|
+
|
|
32
|
+
Note:
|
|
33
|
+
No `update` function support currently.
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
def __init__(self):
|
|
37
|
+
pass
|
|
38
|
+
|
|
39
|
+
def add(self, texts: list[Any], **kwargs: Any): ...
|
|
40
|
+
|
|
41
|
+
@abstractmethod
|
|
42
|
+
def delete(self, **kwargs: Any): ...
|
|
43
|
+
|
|
44
|
+
@abstractmethod
|
|
45
|
+
def query(self, query: str, **kwargs: Any) -> list[str]: ...
|
|
@@ -0,0 +1,80 @@
|
|
|
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.utils.logger import get_logger
|
|
16
|
+
|
|
17
|
+
from .base_database import BaseDatabase
|
|
18
|
+
|
|
19
|
+
logger = get_logger(__name__)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class DatabaseBackend:
|
|
23
|
+
OPENSEARCH = "opensearch"
|
|
24
|
+
LOCAL = "local"
|
|
25
|
+
MYSQL = "mysql"
|
|
26
|
+
REDIS = "redis"
|
|
27
|
+
VIKING = "viking"
|
|
28
|
+
VIKING_MEM = "viking_mem"
|
|
29
|
+
|
|
30
|
+
@classmethod
|
|
31
|
+
def get_attr(cls) -> set[str]:
|
|
32
|
+
return {
|
|
33
|
+
value
|
|
34
|
+
for attr, value in cls.__dict__.items()
|
|
35
|
+
if not attr.startswith("__") and attr != "get_attr"
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class DatabaseFactory:
|
|
40
|
+
@staticmethod
|
|
41
|
+
def create(backend: str, config=None) -> BaseDatabase:
|
|
42
|
+
if backend not in DatabaseBackend.get_attr():
|
|
43
|
+
logger.warning(f"Unknown backend: {backend}), change backend to `local`")
|
|
44
|
+
backend = "local"
|
|
45
|
+
|
|
46
|
+
if backend == DatabaseBackend.LOCAL:
|
|
47
|
+
from .local_database import LocalDataBase
|
|
48
|
+
|
|
49
|
+
return LocalDataBase()
|
|
50
|
+
if backend == DatabaseBackend.OPENSEARCH:
|
|
51
|
+
from .vector.opensearch_vector_database import OpenSearchVectorDatabase
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
OpenSearchVectorDatabase()
|
|
55
|
+
if config is None
|
|
56
|
+
else OpenSearchVectorDatabase(config=config)
|
|
57
|
+
)
|
|
58
|
+
if backend == DatabaseBackend.MYSQL:
|
|
59
|
+
from .relational.mysql_database import MysqlDatabase
|
|
60
|
+
|
|
61
|
+
return MysqlDatabase() if config is None else MysqlDatabase(config=config)
|
|
62
|
+
if backend == DatabaseBackend.REDIS:
|
|
63
|
+
from .kv.redis_database import RedisDatabase
|
|
64
|
+
|
|
65
|
+
return RedisDatabase() if config is None else RedisDatabase(config=config)
|
|
66
|
+
if backend == DatabaseBackend.VIKING:
|
|
67
|
+
from .viking.viking_database import VikingDatabase
|
|
68
|
+
|
|
69
|
+
return VikingDatabase() if config is None else VikingDatabase(config=config)
|
|
70
|
+
|
|
71
|
+
if backend == DatabaseBackend.VIKING_MEM:
|
|
72
|
+
from .viking.viking_memory_db import VikingDatabaseMemory
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
VikingDatabaseMemory()
|
|
76
|
+
if config is None
|
|
77
|
+
else VikingDatabaseMemory(config=config)
|
|
78
|
+
)
|
|
79
|
+
else:
|
|
80
|
+
raise ValueError(f"Unsupported database type: {backend}")
|
|
@@ -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.
|