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,152 @@
|
|
|
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.types import (
|
|
16
|
+
ExtractorResponse,
|
|
17
|
+
ToolAttributesParams,
|
|
18
|
+
)
|
|
19
|
+
from veadk.utils.misc import safe_json_serialize
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def tool_gen_ai_operation_name(params: ToolAttributesParams) -> ExtractorResponse:
|
|
23
|
+
"""Extract the operation name for tool execution spans.
|
|
24
|
+
|
|
25
|
+
Provides a standardized operation name identifier for tool execution
|
|
26
|
+
operations, enabling consistent categorization across all tool invocations.
|
|
27
|
+
|
|
28
|
+
Args:
|
|
29
|
+
params: Tool execution parameters (unused in this extractor)
|
|
30
|
+
|
|
31
|
+
Returns:
|
|
32
|
+
ExtractorResponse: Response containing "execute_tool" as the operation name
|
|
33
|
+
"""
|
|
34
|
+
return ExtractorResponse(content="execute_tool")
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def tool_gen_ai_span_kind(params: ToolAttributesParams) -> ExtractorResponse:
|
|
38
|
+
"""Extract the span kind for tool execution spans.
|
|
39
|
+
|
|
40
|
+
Provides span kind classification following OpenTelemetry semantic
|
|
41
|
+
conventions for generative AI tool operations.
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
params: Tool execution parameters (unused in this extractor)
|
|
45
|
+
|
|
46
|
+
Returns:
|
|
47
|
+
ExtractorResponse: Response containing "tool" as the span kind
|
|
48
|
+
"""
|
|
49
|
+
return ExtractorResponse(content="tool")
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def tool_gen_ai_tool_message(params: ToolAttributesParams) -> ExtractorResponse:
|
|
53
|
+
"""Extract tool message event data for span annotation.
|
|
54
|
+
|
|
55
|
+
Creates a structured tool message event containing tool metadata and
|
|
56
|
+
execution parameters in a format suitable for observability platforms
|
|
57
|
+
and debugging workflows.
|
|
58
|
+
|
|
59
|
+
Args:
|
|
60
|
+
params: Tool execution parameters containing tool instance and arguments
|
|
61
|
+
|
|
62
|
+
Returns:
|
|
63
|
+
ExtractorResponse: Event response with tool message data including:
|
|
64
|
+
- role: "tool" for message classification
|
|
65
|
+
- content: JSON serialized tool information
|
|
66
|
+
"""
|
|
67
|
+
tool_input = {
|
|
68
|
+
"role": "tool",
|
|
69
|
+
"content": safe_json_serialize(
|
|
70
|
+
{
|
|
71
|
+
"name": params.tool.name,
|
|
72
|
+
"description": params.tool.description,
|
|
73
|
+
"parameters": params.args,
|
|
74
|
+
}
|
|
75
|
+
),
|
|
76
|
+
}
|
|
77
|
+
return ExtractorResponse(type="event", content=tool_input)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def tool_gen_ai_tool_input(params: ToolAttributesParams) -> ExtractorResponse:
|
|
81
|
+
"""Extract tool input data for span attributes.
|
|
82
|
+
|
|
83
|
+
Captures comprehensive tool input information including tool metadata
|
|
84
|
+
and execution parameters in JSON format for analysis and debugging.
|
|
85
|
+
|
|
86
|
+
Args:
|
|
87
|
+
params: Tool execution parameters containing tool instance and arguments
|
|
88
|
+
|
|
89
|
+
Returns:
|
|
90
|
+
ExtractorResponse: Response containing JSON serialized tool input data
|
|
91
|
+
"""
|
|
92
|
+
tool_input = {
|
|
93
|
+
"name": params.tool.name,
|
|
94
|
+
"description": params.tool.description,
|
|
95
|
+
"parameters": params.args,
|
|
96
|
+
}
|
|
97
|
+
return ExtractorResponse(
|
|
98
|
+
content=safe_json_serialize(tool_input) or "<unknown_tool_input>"
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def tool_gen_ai_tool_name(params: ToolAttributesParams) -> ExtractorResponse:
|
|
103
|
+
"""Extract the tool name for span identification.
|
|
104
|
+
|
|
105
|
+
Provides the tool function name for identification and categorization
|
|
106
|
+
purposes in observability platforms and analysis workflows.
|
|
107
|
+
|
|
108
|
+
Args:
|
|
109
|
+
params: Tool execution parameters containing tool instance
|
|
110
|
+
|
|
111
|
+
Returns:
|
|
112
|
+
ExtractorResponse: Response containing the tool name or placeholder
|
|
113
|
+
"""
|
|
114
|
+
return ExtractorResponse(content=params.tool.name or "<unknown_tool_name>")
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def tool_gen_ai_tool_output(params: ToolAttributesParams) -> ExtractorResponse:
|
|
118
|
+
"""Extract tool output data for span attributes.
|
|
119
|
+
|
|
120
|
+
Captures tool execution results including response data and metadata
|
|
121
|
+
in JSON format for analysis, debugging, and evaluation purposes.
|
|
122
|
+
|
|
123
|
+
Args:
|
|
124
|
+
params: Tool execution parameters containing function response event
|
|
125
|
+
|
|
126
|
+
Returns:
|
|
127
|
+
ExtractorResponse: Response containing JSON serialized tool output data
|
|
128
|
+
"""
|
|
129
|
+
function_response = params.function_response_event.get_function_responses()[
|
|
130
|
+
0
|
|
131
|
+
].model_dump()
|
|
132
|
+
tool_output = {
|
|
133
|
+
"id": function_response["id"],
|
|
134
|
+
"name": function_response["name"],
|
|
135
|
+
"response": function_response["response"],
|
|
136
|
+
}
|
|
137
|
+
return ExtractorResponse(
|
|
138
|
+
content=safe_json_serialize(tool_output) or "<unknown_tool_output>"
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
TOOL_ATTRIBUTES = {
|
|
143
|
+
"gen_ai.operation.name": tool_gen_ai_operation_name,
|
|
144
|
+
"gen_ai.tool.name": tool_gen_ai_tool_name, # TLS required
|
|
145
|
+
"gen_ai.tool.input": tool_gen_ai_tool_input, # TLS required
|
|
146
|
+
"gen_ai.tool.output": tool_gen_ai_tool_output, # TLS required
|
|
147
|
+
"cozeloop.input": tool_gen_ai_tool_input, # CozeLoop required
|
|
148
|
+
"cozeloop.output": tool_gen_ai_tool_output, # CozeLoop required
|
|
149
|
+
"gen_ai.span.kind": tool_gen_ai_span_kind, # apmplus required
|
|
150
|
+
"gen_ai.input": tool_gen_ai_tool_input, # apmplus required
|
|
151
|
+
"gen_ai.output": tool_gen_ai_tool_output, # apmplus required
|
|
152
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
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, Literal
|
|
16
|
+
|
|
17
|
+
from attr import dataclass
|
|
18
|
+
from google.adk.agents.invocation_context import InvocationContext
|
|
19
|
+
from google.adk.events import Event
|
|
20
|
+
from google.adk.models.llm_request import LlmRequest
|
|
21
|
+
from google.adk.models.llm_response import LlmResponse
|
|
22
|
+
from google.adk.tools import BaseTool
|
|
23
|
+
from opentelemetry.sdk.trace import _Span
|
|
24
|
+
from opentelemetry.trace.span import Span
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@dataclass
|
|
28
|
+
class ExtractorResponse:
|
|
29
|
+
"""Response container for telemetry attribute extractors.
|
|
30
|
+
|
|
31
|
+
ExtractorResponse encapsulates the output from attribute extraction functions
|
|
32
|
+
and provides metadata about how the extracted data should be applied to
|
|
33
|
+
OpenTelemetry spans. It supports different response types for flexible
|
|
34
|
+
span annotation patterns.
|
|
35
|
+
|
|
36
|
+
The response system enables extractors to return various data formats
|
|
37
|
+
including simple attributes, structured events, and event collections,
|
|
38
|
+
allowing for rich telemetry data capture and organization.
|
|
39
|
+
|
|
40
|
+
Attributes:
|
|
41
|
+
content: The extracted data to be applied to the span. Can be any type
|
|
42
|
+
depending on the response type and extractor implementation.
|
|
43
|
+
type: Specification of how the content should be applied to spans.
|
|
44
|
+
Controls the span annotation method used.
|
|
45
|
+
|
|
46
|
+
Response Types:
|
|
47
|
+
- "attribute": Sets span attributes using set_attribute()
|
|
48
|
+
- "event": Adds span events using add_event()
|
|
49
|
+
- "event_list": Adds multiple events from a structured list
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
content: Any
|
|
53
|
+
|
|
54
|
+
type: Literal["attribute", "event", "event_list"] = "attribute"
|
|
55
|
+
"""Type of extractor response.
|
|
56
|
+
|
|
57
|
+
`attribute`: span.add_attribute(attr_name, attr_value)
|
|
58
|
+
`event`: span.add_event(...)
|
|
59
|
+
`event_list`: span.add_event(...) for each event in the list
|
|
60
|
+
"""
|
|
61
|
+
|
|
62
|
+
@staticmethod
|
|
63
|
+
def update_span(
|
|
64
|
+
span: _Span | Span, attr_name: str, response: "ExtractorResponse"
|
|
65
|
+
) -> None:
|
|
66
|
+
"""Apply extractor response content to an OpenTelemetry span.
|
|
67
|
+
|
|
68
|
+
This method interprets the ExtractorResponse and applies its content
|
|
69
|
+
to the given span using the appropriate OpenTelemetry API method
|
|
70
|
+
based on the response type.
|
|
71
|
+
|
|
72
|
+
Processing Logic:
|
|
73
|
+
- attribute: Sets span attributes, supporting both single values and lists
|
|
74
|
+
- event: Adds span events, handling both single events and event lists
|
|
75
|
+
- event_list: Processes structured event lists with key-value pairs
|
|
76
|
+
|
|
77
|
+
Args:
|
|
78
|
+
span: OpenTelemetry span to annotate with extracted data
|
|
79
|
+
attr_name: Attribute name or event name for span annotation
|
|
80
|
+
response: ExtractorResponse containing the data and type information
|
|
81
|
+
|
|
82
|
+
Note:
|
|
83
|
+
- Gracefully handles unsupported response types by discarding them
|
|
84
|
+
- Type checking ensures safe attribute and event operations
|
|
85
|
+
- List processing supports nested dictionary structures
|
|
86
|
+
"""
|
|
87
|
+
if response.type == "attribute":
|
|
88
|
+
res = response.content
|
|
89
|
+
if isinstance(res, list):
|
|
90
|
+
for _res in res:
|
|
91
|
+
if isinstance(_res, dict):
|
|
92
|
+
for k, v in _res.items():
|
|
93
|
+
span.set_attribute(k, v)
|
|
94
|
+
else:
|
|
95
|
+
# set anyway
|
|
96
|
+
span.set_attribute(attr_name, res) # type: ignore
|
|
97
|
+
elif response.type == "event":
|
|
98
|
+
if isinstance(response.content, dict):
|
|
99
|
+
span.add_event(attr_name, response.content)
|
|
100
|
+
elif isinstance(response.content, list):
|
|
101
|
+
for event in response.content:
|
|
102
|
+
span.add_event(attr_name, event) # type: ignore
|
|
103
|
+
elif response.type == "event_list":
|
|
104
|
+
if isinstance(response.content, list):
|
|
105
|
+
for event in response.content:
|
|
106
|
+
if isinstance(event, dict):
|
|
107
|
+
# we ensure this dict only have one key-value pair
|
|
108
|
+
key, value = next(iter(event.items()))
|
|
109
|
+
span.add_event(key, value)
|
|
110
|
+
else:
|
|
111
|
+
# Unsupported response type, discard it.
|
|
112
|
+
pass
|
|
113
|
+
else:
|
|
114
|
+
# Unsupported response type, discard it.
|
|
115
|
+
pass
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
@dataclass
|
|
119
|
+
class LLMAttributesParams:
|
|
120
|
+
"""Parameter container for LLM attribute extractors.
|
|
121
|
+
|
|
122
|
+
LLMAttributesParams packages all the contextual information needed by
|
|
123
|
+
LLM attribute extraction functions. It provides access to the complete
|
|
124
|
+
LLM call context including request parameters, response data, and
|
|
125
|
+
execution environment details.
|
|
126
|
+
|
|
127
|
+
Attributes:
|
|
128
|
+
invocation_context: Complete context of the agent invocation including
|
|
129
|
+
agent instance, session information, user details, and execution state
|
|
130
|
+
event_id: Unique identifier for this specific LLM call event within
|
|
131
|
+
the broader agent execution trace
|
|
132
|
+
llm_request: Request object containing model name, parameters, prompt
|
|
133
|
+
content, and configuration settings sent to the language model
|
|
134
|
+
llm_response: Response object containing generated content, usage metadata,
|
|
135
|
+
token counts, timing information, and any error details
|
|
136
|
+
"""
|
|
137
|
+
|
|
138
|
+
invocation_context: InvocationContext
|
|
139
|
+
event_id: str
|
|
140
|
+
llm_request: LlmRequest
|
|
141
|
+
llm_response: LlmResponse
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
@dataclass
|
|
145
|
+
class ToolAttributesParams:
|
|
146
|
+
"""Parameter container for tool attribute extractors.
|
|
147
|
+
|
|
148
|
+
ToolAttributesParams packages all the contextual information needed by
|
|
149
|
+
tool attribute extraction functions. It provides access to tool execution
|
|
150
|
+
details including tool metadata, input arguments, and execution results
|
|
151
|
+
for comprehensive tool usage telemetry.
|
|
152
|
+
|
|
153
|
+
Attributes:
|
|
154
|
+
tool: Tool instance that was executed, containing metadata such as
|
|
155
|
+
name, description, function signature, and custom metadata
|
|
156
|
+
args: Dictionary of arguments that were passed to the tool function
|
|
157
|
+
during execution, including parameter names and values
|
|
158
|
+
function_response_event: Event object containing the tool's execution
|
|
159
|
+
results, return values, timing information, and any error details
|
|
160
|
+
"""
|
|
161
|
+
|
|
162
|
+
tool: BaseTool
|
|
163
|
+
args: dict[str, Any]
|
|
164
|
+
function_response_event: Event
|
|
@@ -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.
|