Skip to content

Commit 793d373

Browse files
committed
feat: format
1 parent 32c6fb3 commit 793d373

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

veadk/agent.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ def model_post_init(self, __context: Any) -> None:
140140

141141
if self.long_term_memory is not None:
142142
from google.adk.tools import load_memory
143+
143144
if not load_memory.custom_metadata:
144145
load_memory.custom_metadata = {}
145146
load_memory.custom_metadata["backend"] = self.long_term_memory.backend

veadk/tracing/telemetry/exporters/apmplus_exporter.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import time
1616
from dataclasses import dataclass
17-
import random
1817
from typing import Any
1918

2019
from google.adk.agents.invocation_context import InvocationContext
@@ -133,6 +132,7 @@ class Meters:
133132
# tool token usage
134133
APMPLUS_TOOL_TOKEN_USAGE = "apmplus_tool_token_usage"
135134

135+
136136
class MeterUploader:
137137
def __init__(
138138
self, name: str, endpoint: str, headers: dict, resource_attributes: dict
@@ -217,7 +217,6 @@ def __init__(
217217
explicit_bucket_boundaries_advisory=_GEN_AI_CLIENT_TOKEN_USAGE_BUCKETS,
218218
)
219219

220-
221220
def record_call_llm(
222221
self,
223222
invocation_context: InvocationContext,
@@ -299,16 +298,14 @@ def record_call_llm(
299298
# record span latency
300299
if hasattr(span, "start_time") and self.apmplus_span_latency:
301300
# span 耗时
302-
duration = (time.time_ns() - span.start_time)/1e9 # type: ignore
303-
self.apmplus_span_latency.record(
304-
duration, attributes=attributes
305-
)
301+
duration = (time.time_ns() - span.start_time) / 1e9 # type: ignore
302+
self.apmplus_span_latency.record(duration, attributes=attributes)
306303

307304
def record_tool_call(
308-
self,
309-
tool: BaseTool,
310-
args: dict[str, Any],
311-
function_response_event: Event,
305+
self,
306+
tool: BaseTool,
307+
args: dict[str, Any],
308+
function_response_event: Event,
312309
):
313310
logger.debug(f"Record tool call work in progress. Tool: {tool.name}")
314311
span = trace.get_current_span()
@@ -329,23 +326,25 @@ def record_tool_call(
329326
if hasattr(span, "start_time") and self.apmplus_span_latency:
330327
# span 耗时
331328
duration = (time.time_ns() - span.start_time) / 1e9 # type: ignore
332-
self.apmplus_span_latency.record(
333-
duration, attributes=attributes
334-
)
329+
self.apmplus_span_latency.record(duration, attributes=attributes)
335330

336331
if self.apmplus_tool_token_usage and hasattr(span, "attributes"):
337332
tool_input = span.attributes["gen_ai.tool.input"]
338-
tool_token_usage = len(tool_input) / 4 # tool token 数量,使用文本长度/4 # tool token 数量,使用文本长度/4
333+
tool_token_usage_input = (
334+
len(tool_input) / 4
335+
) # tool token 数量,使用文本长度/4
339336
input_tool_token_attributes = {**attributes, "token_type": "input"}
340337
self.apmplus_tool_token_usage.record(
341-
tool_token_usage, attributes=input_tool_token_attributes
338+
tool_token_usage_input, attributes=input_tool_token_attributes
342339
)
343340

344341
tool_output = span.attributes["gen_ai.tool.output"]
345-
tool_token_usage = len(tool_output) / 4 # tool token 数量,使用文本长度/4 # tool token 数量,使用文本长度/4
342+
tool_token_usage_output = (
343+
len(tool_output) / 4
344+
) # tool token 数量,使用文本长度/4
346345
output_tool_token_attributes = {**attributes, "token_type": "output"}
347346
self.apmplus_tool_token_usage.record(
348-
tool_token_usage, attributes=output_tool_token_attributes
347+
tool_token_usage_output, attributes=output_tool_token_attributes
349348
)
350349

351350

0 commit comments

Comments
 (0)