veadk-python 0.2.15__py3-none-any.whl → 0.2.17__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/a2a/remote_ve_agent.py +56 -1
- veadk/agent.py +118 -26
- veadk/agents/loop_agent.py +22 -9
- veadk/agents/parallel_agent.py +21 -9
- veadk/agents/sequential_agent.py +18 -9
- veadk/auth/veauth/apmplus_veauth.py +32 -39
- veadk/auth/veauth/ark_veauth.py +3 -1
- veadk/auth/veauth/utils.py +12 -0
- veadk/auth/veauth/viking_mem0_veauth.py +91 -0
- veadk/cli/cli.py +5 -1
- veadk/cli/cli_create.py +83 -42
- veadk/cli/cli_deploy.py +36 -1
- veadk/cli/cli_eval.py +55 -0
- veadk/cli/cli_init.py +44 -3
- veadk/cli/cli_kb.py +36 -1
- veadk/cli/cli_pipeline.py +66 -1
- veadk/cli/cli_prompt.py +16 -1
- veadk/cli/cli_uploadevalset.py +15 -1
- veadk/cli/cli_web.py +35 -4
- veadk/cloud/cloud_agent_engine.py +142 -25
- veadk/cloud/cloud_app.py +219 -12
- veadk/config.py +12 -1
- veadk/configs/database_configs.py +4 -0
- veadk/configs/model_configs.py +5 -1
- veadk/configs/tracing_configs.py +2 -2
- veadk/evaluation/adk_evaluator/adk_evaluator.py +77 -17
- veadk/evaluation/base_evaluator.py +219 -3
- veadk/evaluation/deepeval_evaluator/deepeval_evaluator.py +116 -1
- veadk/evaluation/eval_set_file_loader.py +20 -0
- veadk/evaluation/eval_set_recorder.py +54 -0
- veadk/evaluation/types.py +32 -0
- veadk/evaluation/utils/prometheus.py +61 -0
- veadk/knowledgebase/backends/base_backend.py +14 -1
- veadk/knowledgebase/backends/in_memory_backend.py +10 -1
- veadk/knowledgebase/backends/opensearch_backend.py +26 -0
- veadk/knowledgebase/backends/redis_backend.py +29 -2
- veadk/knowledgebase/backends/vikingdb_knowledge_backend.py +43 -5
- veadk/knowledgebase/knowledgebase.py +173 -12
- veadk/memory/long_term_memory.py +148 -4
- veadk/memory/long_term_memory_backends/mem0_backend.py +11 -0
- veadk/memory/short_term_memory.py +119 -5
- veadk/runner.py +412 -1
- veadk/tools/builtin_tools/llm_shield.py +381 -0
- veadk/tools/builtin_tools/mcp_router.py +9 -2
- veadk/tools/builtin_tools/run_code.py +30 -6
- veadk/tools/builtin_tools/web_search.py +38 -154
- veadk/tracing/base_tracer.py +28 -1
- veadk/tracing/telemetry/attributes/extractors/common_attributes_extractors.py +105 -1
- veadk/tracing/telemetry/attributes/extractors/llm_attributes_extractors.py +260 -0
- veadk/tracing/telemetry/attributes/extractors/tool_attributes_extractors.py +69 -0
- veadk/tracing/telemetry/attributes/extractors/types.py +78 -0
- veadk/tracing/telemetry/exporters/apmplus_exporter.py +157 -0
- veadk/tracing/telemetry/exporters/base_exporter.py +8 -0
- veadk/tracing/telemetry/exporters/cozeloop_exporter.py +60 -1
- veadk/tracing/telemetry/exporters/inmemory_exporter.py +118 -1
- veadk/tracing/telemetry/exporters/tls_exporter.py +66 -0
- veadk/tracing/telemetry/opentelemetry_tracer.py +117 -4
- veadk/tracing/telemetry/telemetry.py +118 -2
- veadk/utils/misc.py +7 -0
- veadk/version.py +1 -1
- {veadk_python-0.2.15.dist-info → veadk_python-0.2.17.dist-info}/METADATA +1 -1
- {veadk_python-0.2.15.dist-info → veadk_python-0.2.17.dist-info}/RECORD +66 -64
- {veadk_python-0.2.15.dist-info → veadk_python-0.2.17.dist-info}/WHEEL +0 -0
- {veadk_python-0.2.15.dist-info → veadk_python-0.2.17.dist-info}/entry_points.txt +0 -0
- {veadk_python-0.2.15.dist-info → veadk_python-0.2.17.dist-info}/licenses/LICENSE +0 -0
- {veadk_python-0.2.15.dist-info → veadk_python-0.2.17.dist-info}/top_level.txt +0 -0
|
@@ -22,7 +22,7 @@ from typing import Any
|
|
|
22
22
|
from pydantic import BaseModel
|
|
23
23
|
|
|
24
24
|
from veadk.cloud.cloud_app import CloudApp
|
|
25
|
-
from veadk.config import getenv
|
|
25
|
+
from veadk.config import getenv, veadk_environments
|
|
26
26
|
from veadk.integrations.ve_faas.ve_faas import VeFaaS
|
|
27
27
|
from veadk.utils.logger import get_logger
|
|
28
28
|
from veadk.utils.misc import formatted_timestamp
|
|
@@ -31,11 +31,51 @@ logger = get_logger(__name__)
|
|
|
31
31
|
|
|
32
32
|
|
|
33
33
|
class CloudAgentEngine(BaseModel):
|
|
34
|
+
"""Manages cloud agent deployment and operations on Volcengine FaaS platform.
|
|
35
|
+
|
|
36
|
+
This class handles authentication with Volcengine, deploys local projects to FaaS,
|
|
37
|
+
updates function code, removes applications, and supports local testing.
|
|
38
|
+
|
|
39
|
+
Attributes:
|
|
40
|
+
volcengine_access_key (str): Access key for Volcengine authentication.
|
|
41
|
+
Defaults to VOLCENGINE_ACCESS_KEY environment variable.
|
|
42
|
+
volcengine_secret_key (str): Secret key for Volcengine authentication.
|
|
43
|
+
Defaults to VOLCENGINE_SECRET_KEY environment variable.
|
|
44
|
+
region (str): Region for Volcengine services. Defaults to "cn-beijing".
|
|
45
|
+
_vefaas_service (VeFaaS): Internal VeFaaS client instance, initialized post-creation.
|
|
46
|
+
|
|
47
|
+
Note:
|
|
48
|
+
Credentials must be set via environment variables for default behavior.
|
|
49
|
+
This class performs interactive confirmations for destructive operations like removal.
|
|
50
|
+
|
|
51
|
+
Examples:
|
|
52
|
+
```python
|
|
53
|
+
from veadk.cloud.cloud_agent_engine import CloudAgentEngine
|
|
54
|
+
engine = CloudAgentEngine()
|
|
55
|
+
app = engine.deploy("test-app", "/path/to/local/project")
|
|
56
|
+
print(app.vefaas_endpoint)
|
|
57
|
+
```
|
|
58
|
+
"""
|
|
59
|
+
|
|
34
60
|
volcengine_access_key: str = getenv("VOLCENGINE_ACCESS_KEY")
|
|
35
61
|
volcengine_secret_key: str = getenv("VOLCENGINE_SECRET_KEY")
|
|
36
62
|
region: str = "cn-beijing"
|
|
37
63
|
|
|
38
64
|
def model_post_init(self, context: Any, /) -> None:
|
|
65
|
+
"""Initializes the internal VeFaaS service after Pydantic model validation.
|
|
66
|
+
|
|
67
|
+
Creates a VeFaaS instance using the configured access key, secret key, and region.
|
|
68
|
+
|
|
69
|
+
Args:
|
|
70
|
+
self: The CloudAgentEngine instance.
|
|
71
|
+
context: Pydantic post-init context parameter (not used).
|
|
72
|
+
|
|
73
|
+
Returns:
|
|
74
|
+
None
|
|
75
|
+
|
|
76
|
+
Note:
|
|
77
|
+
This is a Pydantic lifecycle method, ensuring service readiness after init.
|
|
78
|
+
"""
|
|
39
79
|
self._vefaas_service = VeFaaS(
|
|
40
80
|
access_key=self.volcengine_access_key,
|
|
41
81
|
secret_key=self.volcengine_secret_key,
|
|
@@ -43,6 +83,25 @@ class CloudAgentEngine(BaseModel):
|
|
|
43
83
|
)
|
|
44
84
|
|
|
45
85
|
def _prepare(self, path: str, name: str):
|
|
86
|
+
"""Prepares the local project for deployment by validating path and name.
|
|
87
|
+
|
|
88
|
+
Checks if the path exists and is a directory, validates application name format.
|
|
89
|
+
|
|
90
|
+
Args:
|
|
91
|
+
path (str): Full or relative path to the local agent project directory.
|
|
92
|
+
name (str): Intended VeFaaS application name.
|
|
93
|
+
|
|
94
|
+
Returns:
|
|
95
|
+
None
|
|
96
|
+
|
|
97
|
+
Raises:
|
|
98
|
+
AssertionError: If path does not exist or is not a directory.
|
|
99
|
+
ValueError: If name contains invalid characters like underscores.
|
|
100
|
+
|
|
101
|
+
Note:
|
|
102
|
+
Includes commented code for handling requirements.txt; not executed currently.
|
|
103
|
+
Called internally by deploy and update methods.
|
|
104
|
+
"""
|
|
46
105
|
# basic check
|
|
47
106
|
assert os.path.exists(path), f"Local agent project path `{path}` not exists."
|
|
48
107
|
assert os.path.isdir(path), (
|
|
@@ -73,10 +132,23 @@ class CloudAgentEngine(BaseModel):
|
|
|
73
132
|
# )
|
|
74
133
|
|
|
75
134
|
def _try_launch_fastapi_server(self, path: str):
|
|
76
|
-
"""
|
|
135
|
+
"""Tries to start a FastAPI server locally for testing deployment readiness.
|
|
136
|
+
|
|
137
|
+
Runs the project's run.sh script and checks connectivity on port 8000.
|
|
77
138
|
|
|
78
139
|
Args:
|
|
79
|
-
path (str):
|
|
140
|
+
path (str): Path to the local project containing run.sh.
|
|
141
|
+
|
|
142
|
+
Returns:
|
|
143
|
+
None
|
|
144
|
+
|
|
145
|
+
Raises:
|
|
146
|
+
RuntimeError: If server startup times out after 30 seconds.
|
|
147
|
+
|
|
148
|
+
Note:
|
|
149
|
+
Sets _FAAS_FUNC_TIMEOUT environment to 900 seconds.
|
|
150
|
+
Streams output to console and terminates process after successful check.
|
|
151
|
+
Assumes run.sh launches server on 0.0.0.0:8000.
|
|
80
152
|
"""
|
|
81
153
|
RUN_SH = f"{path}/run.sh"
|
|
82
154
|
|
|
@@ -128,33 +200,42 @@ class CloudAgentEngine(BaseModel):
|
|
|
128
200
|
use_adk_web: bool = False,
|
|
129
201
|
local_test: bool = False,
|
|
130
202
|
) -> CloudApp:
|
|
131
|
-
"""
|
|
203
|
+
"""Deploys a local agent project to Volcengine FaaS, creating necessary resources.
|
|
204
|
+
|
|
205
|
+
Prepares project, optionally tests locally, deploys via VeFaaS, and returns app instance.
|
|
132
206
|
|
|
133
207
|
Args:
|
|
134
|
-
application_name (str):
|
|
135
|
-
path (str): Local agent project
|
|
136
|
-
gateway_name (str):
|
|
137
|
-
gateway_service_name (str):
|
|
138
|
-
gateway_upstream_name (str):
|
|
139
|
-
use_adk_web (bool):
|
|
140
|
-
local_test (bool):
|
|
208
|
+
application_name (str): Unique name for the VeFaaS application.
|
|
209
|
+
path (str): Local directory path of the agent project.
|
|
210
|
+
gateway_name (str, optional): Custom gateway resource name. Defaults to timestamped.
|
|
211
|
+
gateway_service_name (str, optional): Custom service name. Defaults to timestamped.
|
|
212
|
+
gateway_upstream_name (str, optional): Custom upstream name. Defaults to timestamped.
|
|
213
|
+
use_adk_web (bool): Enable ADK Web configuration. Defaults to False.
|
|
214
|
+
local_test (bool): Perform FastAPI server test before deploy. Defaults to False.
|
|
141
215
|
|
|
142
216
|
Returns:
|
|
143
|
-
CloudApp:
|
|
217
|
+
CloudApp: Deployed application with endpoint, name, and ID.
|
|
218
|
+
|
|
219
|
+
Raises:
|
|
220
|
+
ValueError: On deployment failure, such as invalid config or VeFaaS errors.
|
|
221
|
+
|
|
222
|
+
Note:
|
|
223
|
+
Converts path to absolute; sets telemetry opt-out and ADK Web env vars.
|
|
224
|
+
Generates default gateway names if not specified.
|
|
225
|
+
|
|
226
|
+
Examples:
|
|
227
|
+
```python
|
|
228
|
+
app = engine.deploy("my-agent", "./agent-project", local_test=True)
|
|
229
|
+
print(f"Deployed at: {app.vefaas_endpoint}")
|
|
230
|
+
```
|
|
144
231
|
"""
|
|
145
232
|
# prevent deepeval writing operations
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
veadk.config.veadk_environments["DEEPEVAL_TELEMETRY_OPT_OUT"] = "YES"
|
|
233
|
+
veadk_environments["DEEPEVAL_TELEMETRY_OPT_OUT"] = "YES"
|
|
149
234
|
|
|
150
235
|
if use_adk_web:
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
veadk.config.veadk_environments["USE_ADK_WEB"] = "True"
|
|
236
|
+
veadk_environments["USE_ADK_WEB"] = "True"
|
|
154
237
|
else:
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
veadk.config.veadk_environments["USE_ADK_WEB"] = "False"
|
|
238
|
+
veadk_environments["USE_ADK_WEB"] = "False"
|
|
158
239
|
|
|
159
240
|
# convert `path` to absolute path
|
|
160
241
|
path = str(Path(path).resolve())
|
|
@@ -191,6 +272,28 @@ class CloudAgentEngine(BaseModel):
|
|
|
191
272
|
)
|
|
192
273
|
|
|
193
274
|
def remove(self, app_name: str):
|
|
275
|
+
"""Deletes a deployed cloud application after user confirmation.
|
|
276
|
+
|
|
277
|
+
Locates app by name, confirms, and issues delete via VeFaaS.
|
|
278
|
+
|
|
279
|
+
Args:
|
|
280
|
+
app_name (str): Name of the application to remove.
|
|
281
|
+
|
|
282
|
+
Returns:
|
|
283
|
+
None
|
|
284
|
+
|
|
285
|
+
Raises:
|
|
286
|
+
ValueError: If application not found by name.
|
|
287
|
+
|
|
288
|
+
Note:
|
|
289
|
+
Interactive prompt required; cancels on non-'y' input.
|
|
290
|
+
Deletion is processed asynchronously by VeFaaS.
|
|
291
|
+
|
|
292
|
+
Examples:
|
|
293
|
+
```python
|
|
294
|
+
engine.remove("my-agent")
|
|
295
|
+
```
|
|
296
|
+
"""
|
|
194
297
|
confirm = input(f"Confirm delete cloud app {app_name}? (y/N): ")
|
|
195
298
|
if confirm.lower() != "y":
|
|
196
299
|
print("Delete cancelled.")
|
|
@@ -208,14 +311,28 @@ class CloudAgentEngine(BaseModel):
|
|
|
208
311
|
application_name: str,
|
|
209
312
|
path: str,
|
|
210
313
|
) -> CloudApp:
|
|
211
|
-
"""
|
|
314
|
+
"""Updates the code in an existing VeFaaS application without changing endpoint.
|
|
315
|
+
|
|
316
|
+
Prepares new code from local path and updates function via VeFaaS.
|
|
212
317
|
|
|
213
318
|
Args:
|
|
214
|
-
application_name (str):
|
|
215
|
-
path (str): Local
|
|
319
|
+
application_name (str): Name of the existing application to update.
|
|
320
|
+
path (str): Local path containing updated project files.
|
|
216
321
|
|
|
217
322
|
Returns:
|
|
218
|
-
CloudApp: Updated
|
|
323
|
+
CloudApp: Updated application instance with same endpoint.
|
|
324
|
+
|
|
325
|
+
Raises:
|
|
326
|
+
ValueError: If update fails due to preparation or VeFaaS issues.
|
|
327
|
+
|
|
328
|
+
Note:
|
|
329
|
+
Preserves gateway and other resources; only function code is updated.
|
|
330
|
+
Path is resolved to absolute before processing.
|
|
331
|
+
|
|
332
|
+
Examples:
|
|
333
|
+
```python
|
|
334
|
+
updated_app = engine.update_function_code("my-agent", "./updated-project")
|
|
335
|
+
```
|
|
219
336
|
"""
|
|
220
337
|
# convert `path` to absolute path
|
|
221
338
|
path = str(Path(path).resolve())
|
veadk/cloud/cloud_app.py
CHANGED
|
@@ -23,17 +23,37 @@ from a2a.types import AgentCard, Message, MessageSendParams, SendMessageRequest
|
|
|
23
23
|
|
|
24
24
|
from veadk.config import getenv
|
|
25
25
|
from veadk.utils.logger import get_logger
|
|
26
|
+
from veadk.integrations.ve_faas.ve_faas import VeFaaS
|
|
26
27
|
|
|
27
28
|
logger = get_logger(__name__)
|
|
28
29
|
|
|
29
30
|
|
|
30
31
|
class CloudApp:
|
|
31
|
-
"""
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
"""Represents a deployed cloud agent application on Volcengine FaaS platform.
|
|
33
|
+
|
|
34
|
+
This class facilitates interaction with the deployed agent via A2A protocol,
|
|
35
|
+
supports self-management like update and delete, and handles endpoint resolution.
|
|
36
|
+
|
|
37
|
+
It uses HTTP client for async communications.
|
|
38
|
+
|
|
39
|
+
Attributes:
|
|
40
|
+
vefaas_application_name (str): Name of the VeFaaS application. Defaults to "".
|
|
41
|
+
vefaas_endpoint (str): URL for accessing the application. Resolved if not provided.
|
|
42
|
+
vefaas_application_id (str): Unique identifier of the application. Defaults to "".
|
|
43
|
+
use_agent_card (bool): Flag to resolve endpoint via agent card. Defaults to False.
|
|
44
|
+
httpx_client (httpx.AsyncClient): Async HTTP client for requests.
|
|
45
|
+
|
|
46
|
+
Note:
|
|
47
|
+
At least one of name, endpoint, or ID must be provided during init.
|
|
48
|
+
Agent card mode fetches card from the endpoint's public path.
|
|
49
|
+
|
|
50
|
+
Examples:
|
|
51
|
+
```python
|
|
52
|
+
from veadk.cloud.cloud_app import CloudApp
|
|
53
|
+
app = CloudApp(vefaas_endpoint="https://my-agent.volcengine.com")
|
|
54
|
+
response = await app.message_send("Query", "session-1", "user-123")
|
|
55
|
+
print(response.message_id)
|
|
56
|
+
```
|
|
37
57
|
"""
|
|
38
58
|
|
|
39
59
|
def __init__(
|
|
@@ -43,6 +63,31 @@ class CloudApp:
|
|
|
43
63
|
vefaas_application_id: str = "",
|
|
44
64
|
use_agent_card: bool = False,
|
|
45
65
|
):
|
|
66
|
+
"""Initializes the CloudApp with VeFaaS application details.
|
|
67
|
+
|
|
68
|
+
Sets attributes, validates inputs, resolves endpoint if missing, and creates HTTP client.
|
|
69
|
+
|
|
70
|
+
Args:
|
|
71
|
+
vefaas_application_name (str, optional): Application name for lookup. Defaults to "".
|
|
72
|
+
vefaas_endpoint (str, optional): Direct endpoint URL. Defaults to "".
|
|
73
|
+
vefaas_application_id (str, optional): Application ID for lookup. Defaults to "".
|
|
74
|
+
use_agent_card (bool): Use agent card to determine invocation URL. Defaults to False.
|
|
75
|
+
|
|
76
|
+
Returns:
|
|
77
|
+
None
|
|
78
|
+
|
|
79
|
+
Raises:
|
|
80
|
+
ValueError: If no app identifiers provided or endpoint lacks http/https prefix.
|
|
81
|
+
|
|
82
|
+
Note:
|
|
83
|
+
Logs info if agent card mode enabled.
|
|
84
|
+
Endpoint is fetched via _get_vefaas_endpoint if not set.
|
|
85
|
+
|
|
86
|
+
Examples:
|
|
87
|
+
```python
|
|
88
|
+
app = CloudApp(vefaas_application_id="app-123", use_agent_card=True)
|
|
89
|
+
```
|
|
90
|
+
"""
|
|
46
91
|
self.vefaas_endpoint = vefaas_endpoint
|
|
47
92
|
self.vefaas_application_id = vefaas_application_id
|
|
48
93
|
self.vefaas_application_name = vefaas_application_name
|
|
@@ -82,6 +127,29 @@ class CloudApp:
|
|
|
82
127
|
volcengine_ak: str = getenv("VOLCENGINE_ACCESS_KEY"),
|
|
83
128
|
volcengine_sk: str = getenv("VOLCENGINE_SECRET_KEY"),
|
|
84
129
|
) -> str:
|
|
130
|
+
"""Fetches the application endpoint from VeFaaS details if not directly provided.
|
|
131
|
+
|
|
132
|
+
Uses VeFaaS client to get app info and parse CloudResource JSON for URL.
|
|
133
|
+
|
|
134
|
+
Args:
|
|
135
|
+
volcengine_ak (str, optional): Volcengine access key. Defaults to env var.
|
|
136
|
+
volcengine_sk (str, optional): Volcengine secret key. Defaults to env var.
|
|
137
|
+
|
|
138
|
+
Returns:
|
|
139
|
+
str: The system URL from CloudResource or empty string on failure.
|
|
140
|
+
|
|
141
|
+
Raises:
|
|
142
|
+
ValueError: If application not found by ID or name.
|
|
143
|
+
|
|
144
|
+
Note:
|
|
145
|
+
Logs warning if JSON parsing fails; returns empty on error.
|
|
146
|
+
Called during init if endpoint missing.
|
|
147
|
+
|
|
148
|
+
Examples:
|
|
149
|
+
```python
|
|
150
|
+
endpoint = app._get_vefaas_endpoint("custom-ak", "custom-sk")
|
|
151
|
+
```
|
|
152
|
+
"""
|
|
85
153
|
from veadk.integrations.ve_faas.ve_faas import VeFaaS
|
|
86
154
|
|
|
87
155
|
vefaas_client = VeFaaS(access_key=volcengine_ak, secret_key=volcengine_sk)
|
|
@@ -105,6 +173,26 @@ class CloudApp:
|
|
|
105
173
|
return vefaas_endpoint
|
|
106
174
|
|
|
107
175
|
def _get_vefaas_application_id_by_name(self) -> str:
|
|
176
|
+
"""Retrieves the application ID using the configured name.
|
|
177
|
+
|
|
178
|
+
Instantiates VeFaaS client and queries by name.
|
|
179
|
+
|
|
180
|
+
Returns:
|
|
181
|
+
str: The found application ID.
|
|
182
|
+
|
|
183
|
+
Raises:
|
|
184
|
+
ValueError: If vefaas_application_name is not set.
|
|
185
|
+
|
|
186
|
+
Note:
|
|
187
|
+
Uses default environment credentials.
|
|
188
|
+
Internal method for ID resolution.
|
|
189
|
+
|
|
190
|
+
Examples:
|
|
191
|
+
```python
|
|
192
|
+
app.vefaas_application_name = "my-app"
|
|
193
|
+
id = app._get_vefaas_application_id_by_name()
|
|
194
|
+
```
|
|
195
|
+
"""
|
|
108
196
|
if not self.vefaas_application_name:
|
|
109
197
|
raise ValueError(
|
|
110
198
|
"VeFaaS CloudAPP must be set application_name to get application_id."
|
|
@@ -121,6 +209,20 @@ class CloudApp:
|
|
|
121
209
|
return vefaas_application_id
|
|
122
210
|
|
|
123
211
|
async def _get_a2a_client(self) -> A2AClient:
|
|
212
|
+
"""Constructs an A2A client configured for this cloud app.
|
|
213
|
+
|
|
214
|
+
If use_agent_card, resolves agent card and uses its URL; otherwise uses direct endpoint.
|
|
215
|
+
|
|
216
|
+
Args:
|
|
217
|
+
self: The CloudApp instance.
|
|
218
|
+
|
|
219
|
+
Returns:
|
|
220
|
+
A2AClient: Ready-to-use A2A client.
|
|
221
|
+
|
|
222
|
+
Note:
|
|
223
|
+
Manages httpx_client context.
|
|
224
|
+
For card mode, fetches from base_url/ (public card).
|
|
225
|
+
"""
|
|
124
226
|
if self.use_agent_card:
|
|
125
227
|
async with self.httpx_client as httpx_client:
|
|
126
228
|
resolver = A2ACardResolver(
|
|
@@ -141,19 +243,81 @@ class CloudApp:
|
|
|
141
243
|
|
|
142
244
|
def update_self(
|
|
143
245
|
self,
|
|
246
|
+
path: str,
|
|
144
247
|
volcengine_ak: str = getenv("VOLCENGINE_ACCESS_KEY"),
|
|
145
248
|
volcengine_sk: str = getenv("VOLCENGINE_SECRET_KEY"),
|
|
146
249
|
):
|
|
250
|
+
"""Updates the configuration of this cloud application.
|
|
251
|
+
|
|
252
|
+
Currently a placeholder; implementation pending.
|
|
253
|
+
|
|
254
|
+
Args:
|
|
255
|
+
volcengine_ak (str, optional): Access key for VeFaaS. Defaults to env var.
|
|
256
|
+
volcengine_sk (str, optional): Secret key for VeFaaS. Defaults to env var.
|
|
257
|
+
|
|
258
|
+
Returns:
|
|
259
|
+
None
|
|
260
|
+
|
|
261
|
+
Raises:
|
|
262
|
+
ValueError: If access key or secret key missing.
|
|
263
|
+
|
|
264
|
+
Examples:
|
|
265
|
+
```python
|
|
266
|
+
app.update_self("ak", "sk")
|
|
267
|
+
```
|
|
268
|
+
"""
|
|
147
269
|
if not volcengine_ak or not volcengine_sk:
|
|
148
270
|
raise ValueError("Volcengine access key and secret key must be set.")
|
|
149
271
|
|
|
150
|
-
|
|
272
|
+
if not self.vefaas_application_id:
|
|
273
|
+
self.vefaas_application_id = self._get_vefaas_application_id_by_name()
|
|
274
|
+
|
|
275
|
+
vefaas_client = VeFaaS(access_key=volcengine_ak, secret_key=volcengine_sk)
|
|
276
|
+
|
|
277
|
+
try:
|
|
278
|
+
vefaas_application_url, app_id, function_id = (
|
|
279
|
+
vefaas_client._update_function_code(
|
|
280
|
+
application_name=self.vefaas_application_name,
|
|
281
|
+
path=path,
|
|
282
|
+
)
|
|
283
|
+
)
|
|
284
|
+
self.vefaas_endpoint = vefaas_application_url
|
|
285
|
+
self.vefaas_application_id = app_id
|
|
286
|
+
logger.info(
|
|
287
|
+
f"Cloud app {self.vefaas_application_name} updated successfully."
|
|
288
|
+
)
|
|
289
|
+
except Exception as e:
|
|
290
|
+
raise ValueError(f"Failed to update cloud app. Error: {e}")
|
|
151
291
|
|
|
152
292
|
def delete_self(
|
|
153
293
|
self,
|
|
154
294
|
volcengine_ak: str = getenv("VOLCENGINE_ACCESS_KEY"),
|
|
155
295
|
volcengine_sk: str = getenv("VOLCENGINE_SECRET_KEY"),
|
|
156
296
|
):
|
|
297
|
+
"""Deletes this cloud application after interactive confirmation.
|
|
298
|
+
|
|
299
|
+
Issues delete to VeFaaS and polls for completion.
|
|
300
|
+
|
|
301
|
+
Args:
|
|
302
|
+
volcengine_ak (str, optional): Access key. Defaults to env var.
|
|
303
|
+
volcengine_sk (str, optional): Secret key. Defaults to env var.
|
|
304
|
+
|
|
305
|
+
Returns:
|
|
306
|
+
None
|
|
307
|
+
|
|
308
|
+
Raises:
|
|
309
|
+
ValueError: If credentials not provided.
|
|
310
|
+
|
|
311
|
+
Note:
|
|
312
|
+
Fetches ID if not set using name.
|
|
313
|
+
Polls every 3 seconds until app no longer exists.
|
|
314
|
+
Prints status messages.
|
|
315
|
+
|
|
316
|
+
Examples:
|
|
317
|
+
```python
|
|
318
|
+
app.delete_self()
|
|
319
|
+
```
|
|
320
|
+
"""
|
|
157
321
|
if not volcengine_ak or not volcengine_sk:
|
|
158
322
|
raise ValueError("Volcengine access key and secret key must be set.")
|
|
159
323
|
|
|
@@ -187,8 +351,33 @@ class CloudApp:
|
|
|
187
351
|
async def message_send(
|
|
188
352
|
self, message: str, session_id: str, user_id: str, timeout: float = 600.0
|
|
189
353
|
) -> Message | None:
|
|
190
|
-
"""
|
|
191
|
-
|
|
354
|
+
"""Sends a user message to the cloud agent and retrieves the response.
|
|
355
|
+
|
|
356
|
+
Constructs A2A SendMessageRequest and executes via client.
|
|
357
|
+
|
|
358
|
+
Args:
|
|
359
|
+
message (str): Text content of the user message.
|
|
360
|
+
session_id (str): Identifier for the conversation session.
|
|
361
|
+
user_id (str): Identifier for the user.
|
|
362
|
+
timeout (float): Maximum wait time in seconds. Defaults to 600.0.
|
|
363
|
+
|
|
364
|
+
Returns:
|
|
365
|
+
Message | None: Assistant response message or None if error occurs.
|
|
366
|
+
|
|
367
|
+
Raises:
|
|
368
|
+
Exception: Communication or processing errors; error is printed.
|
|
369
|
+
|
|
370
|
+
Note:
|
|
371
|
+
Uses UUID for message and request IDs.
|
|
372
|
+
Payload includes role 'user' and text part.
|
|
373
|
+
Debug logs the full response.
|
|
374
|
+
Ignores type checks for result as it may not be Task.
|
|
375
|
+
|
|
376
|
+
Examples:
|
|
377
|
+
```python
|
|
378
|
+
response = await app.message_send("What is AI?", "chat-1", "user-1", timeout=300)
|
|
379
|
+
print(response.content)
|
|
380
|
+
```
|
|
192
381
|
"""
|
|
193
382
|
a2a_client = await self._get_a2a_client()
|
|
194
383
|
|
|
@@ -223,13 +412,31 @@ class CloudApp:
|
|
|
223
412
|
# from CloudApp will not be `Task` type
|
|
224
413
|
return res.root.result # type: ignore
|
|
225
414
|
except Exception as e:
|
|
226
|
-
|
|
227
|
-
print(e)
|
|
415
|
+
logger.error(f"Failed to send message to cloud app. Error: {e}")
|
|
228
416
|
return None
|
|
229
417
|
|
|
230
418
|
|
|
231
419
|
def get_message_id(message: Message):
|
|
232
|
-
"""
|
|
420
|
+
"""Extracts the unique ID from an A2A Message object.
|
|
421
|
+
|
|
422
|
+
Checks for both legacy 'messageId' and current 'message_id' attributes.
|
|
423
|
+
|
|
424
|
+
Args:
|
|
425
|
+
message (Message): The A2A message instance.
|
|
426
|
+
|
|
427
|
+
Returns:
|
|
428
|
+
str: The message identifier.
|
|
429
|
+
|
|
430
|
+
Note:
|
|
431
|
+
Ensures compatibility with a2a-python versions before and after 0.3.0.
|
|
432
|
+
Prefers 'message_id' if available, falls back to 'messageId'.
|
|
433
|
+
|
|
434
|
+
Examples:
|
|
435
|
+
```python
|
|
436
|
+
mid = get_message_id(response_message)
|
|
437
|
+
print(mid)
|
|
438
|
+
```
|
|
439
|
+
"""
|
|
233
440
|
if getattr(message, "messageId", None):
|
|
234
441
|
# Compatible with the messageId of the old a2a-python version (<0.3.0) in cloud app
|
|
235
442
|
return message.messageId # type: ignore
|
veadk/config.py
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
import os
|
|
16
16
|
from typing import Any
|
|
17
17
|
|
|
18
|
-
from dotenv import find_dotenv
|
|
18
|
+
from dotenv import find_dotenv, load_dotenv
|
|
19
19
|
from pydantic import BaseModel, Field
|
|
20
20
|
|
|
21
21
|
from veadk.configs.database_configs import (
|
|
@@ -33,8 +33,16 @@ from veadk.configs.tracing_configs import (
|
|
|
33
33
|
PrometheusConfig,
|
|
34
34
|
TLSConfig,
|
|
35
35
|
)
|
|
36
|
+
from veadk.utils.logger import get_logger
|
|
36
37
|
from veadk.utils.misc import set_envs
|
|
37
38
|
|
|
39
|
+
logger = get_logger(__name__)
|
|
40
|
+
|
|
41
|
+
if load_dotenv(find_dotenv(usecwd=True)):
|
|
42
|
+
logger.info(f"Find `.env` file in {find_dotenv(usecwd=True)}, load envs.")
|
|
43
|
+
else:
|
|
44
|
+
logger.info("No env file found.")
|
|
45
|
+
|
|
38
46
|
|
|
39
47
|
class VeADKConfig(BaseModel):
|
|
40
48
|
model: ModelConfig = Field(default_factory=ModelConfig)
|
|
@@ -89,7 +97,10 @@ config_yaml_path = find_dotenv(filename="config.yaml", usecwd=True)
|
|
|
89
97
|
veadk_environments = {}
|
|
90
98
|
|
|
91
99
|
if config_yaml_path:
|
|
100
|
+
logger.info(f"Find `config.yaml` file in {config_yaml_path}")
|
|
92
101
|
config_dict, _veadk_environments = set_envs(config_yaml_path=config_yaml_path)
|
|
93
102
|
veadk_environments.update(_veadk_environments)
|
|
103
|
+
else:
|
|
104
|
+
logger.warning("No `config.yaml` file found.")
|
|
94
105
|
|
|
95
106
|
settings = VeADKConfig()
|
veadk/configs/model_configs.py
CHANGED
|
@@ -56,7 +56,11 @@ class EmbeddingModelConfig(BaseSettings):
|
|
|
56
56
|
|
|
57
57
|
@cached_property
|
|
58
58
|
def api_key(self) -> str:
|
|
59
|
-
return
|
|
59
|
+
return (
|
|
60
|
+
os.getenv("MODEL_EMBEDDING_API_KEY")
|
|
61
|
+
or os.getenv("MODEL_AGENT_API_KEY") # try to use agent's model api key
|
|
62
|
+
or get_ark_token()
|
|
63
|
+
)
|
|
60
64
|
|
|
61
65
|
|
|
62
66
|
class NormalEmbeddingModelConfig(BaseSettings):
|
veadk/configs/tracing_configs.py
CHANGED
|
@@ -18,7 +18,7 @@ from functools import cached_property
|
|
|
18
18
|
from pydantic import Field
|
|
19
19
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
20
20
|
|
|
21
|
-
from veadk.auth.veauth.apmplus_veauth import
|
|
21
|
+
from veadk.auth.veauth.apmplus_veauth import get_apmplus_token
|
|
22
22
|
from veadk.consts import (
|
|
23
23
|
DEFAULT_APMPLUS_OTEL_EXPORTER_ENDPOINT,
|
|
24
24
|
DEFAULT_APMPLUS_OTEL_EXPORTER_SERVICE_NAME,
|
|
@@ -46,7 +46,7 @@ class APMPlusConfig(BaseSettings):
|
|
|
46
46
|
def otel_exporter_api_key(self) -> str:
|
|
47
47
|
return (
|
|
48
48
|
os.getenv("OBSERVABILITY_OPENTELEMETRY_APMPLUS_API_KEY")
|
|
49
|
-
or
|
|
49
|
+
or get_apmplus_token()
|
|
50
50
|
)
|
|
51
51
|
|
|
52
52
|
|