Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/content/2.configurations/2.envs.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ navigation:
| 环境变量名称 | 释义 |
| :- | :- |
| `VOLCENGINE_ACCESS_KEY` | 火山引擎 Access Key |
| `VOLCENGINE_SECRET_KEY` | 火山引擎 Access Key |
| `VOLCENGINE_SECRET_KEY` | 火山引擎 Secret Key |

对应 `yaml` 文件格式:

Expand Down
4 changes: 4 additions & 0 deletions veadk/cli/cli_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ def init_for_veadk(
eval_set_results_manager: Any,
agents_dir: str,
extra_plugins: Optional[list[str]] = None,
**kwargs: Any,
):
self.agent_loader = agent_loader
self.artifact_service = artifact_service
Expand All @@ -166,6 +167,9 @@ def init_for_veadk(
self.runner_dict = {}
self.extra_plugins = extra_plugins or []

for key, value in kwargs.items():
setattr(self, key, value)

# parse VeADK memories
short_term_memory, long_term_memory = _get_memory(module_path=agents_dir)
self.session_service = short_term_memory.session_service
Expand Down
2 changes: 1 addition & 1 deletion veadk/memory/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __getattr__(name):
from veadk.memory.short_term_memory import ShortTermMemory

return ShortTermMemory
if name == "LongTeremMemory":
if name == "LongTermMemory":
from veadk.memory.long_term_memory import LongTermMemory

return LongTermMemory
Expand Down
12 changes: 9 additions & 3 deletions veadk/memory/short_term_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
BaseSessionService,
DatabaseSessionService,
InMemorySessionService,
Session,
)
from pydantic import BaseModel, Field, PrivateAttr

Expand Down Expand Up @@ -106,7 +107,7 @@ async def create_session(
app_name: str,
user_id: str,
session_id: str,
) -> None:
) -> Session | None:
if isinstance(self._session_service, DatabaseSessionService):
list_sessions_response = await self._session_service.list_sessions(
app_name=app_name, user_id=user_id
Expand All @@ -122,7 +123,12 @@ async def create_session(
)
is None
):
# create a new session for this running
await self._session_service.create_session(
return await self._session_service.create_session(
app_name=app_name, user_id=user_id, session_id=session_id
)
else:
logger.info(
f"Session {session_id} already exists with app_name={app_name} user_id={user_id}."
)

return None
12 changes: 11 additions & 1 deletion veadk/tracing/telemetry/exporters/apmplus_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
from typing import Any

from google.adk.agents.invocation_context import InvocationContext
from google.adk.events import Event
from google.adk.models.llm_request import LlmRequest
from google.adk.models.llm_response import LlmResponse
from google.adk.tools import BaseTool
from opentelemetry import metrics, trace
from opentelemetry import metrics as metrics_api
from opentelemetry.exporter.otlp.proto.grpc.metric_exporter import OTLPMetricExporter
Expand Down Expand Up @@ -195,7 +197,7 @@ def __init__(
explicit_bucket_boundaries_advisory=_GEN_AI_SERVER_TIME_PER_OUTPUT_TOKEN_BUCKETS,
)

def record(
def record_call_llm(
self,
invocation_context: InvocationContext,
event_id: str,
Expand Down Expand Up @@ -267,6 +269,14 @@ def record(
# time_per_output_token, attributes=attributes
# )

def record_tool_call(
self,
tool: BaseTool,
args: dict[str, Any],
function_response_event: Event,
):
logger.debug(f"Record tool call work in progress. Tool: {tool.name}")


class APMPlusExporterConfig(BaseModel):
endpoint: str = Field(
Expand Down
26 changes: 23 additions & 3 deletions veadk/tracing/telemetry/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@

logger = get_logger(__name__)

meter_uploader = None

def _upload_metrics(

def _upload_call_llm_metrics(
invocation_context: InvocationContext,
event_id: str,
llm_request: LlmRequest,
Expand All @@ -47,11 +49,27 @@ def _upload_metrics(
for tracer in tracers:
for exporter in getattr(tracer, "exporters", []):
if getattr(exporter, "meter_uploader", None):
exporter.meter_uploader.record(
global meter_uploader
meter_uploader = exporter.meter_uploader
exporter.meter_uploader.record_call_llm(
invocation_context, event_id, llm_request, llm_response
)


def _upload_tool_call_metrics(
tool: BaseTool,
args: dict[str, Any],
function_response_event: Event,
):
global meter_uploader
if meter_uploader:
meter_uploader.record_tool_call(tool, args, function_response_event)
else:
logger.warning(
"Meter uploader is not initialized yet. Skip recording tool call metrics."
)


def _set_agent_input_attribute(
span: Span, invocation_context: InvocationContext
) -> None:
Expand Down Expand Up @@ -203,6 +221,8 @@ def trace_tool_call(
response: ExtractorResponse = attr_extractor(params)
ExtractorResponse.update_span(span, attr_name, response)

_upload_tool_call_metrics(tool, args, function_response_event)


def trace_call_llm(
invocation_context: InvocationContext,
Expand Down Expand Up @@ -252,7 +272,7 @@ def trace_call_llm(
response: ExtractorResponse = attr_extractor(params)
ExtractorResponse.update_span(span, attr_name, response)

_upload_metrics(invocation_context, event_id, llm_request, llm_response)
_upload_call_llm_metrics(invocation_context, event_id, llm_request, llm_response)


# Do not modify this function
Expand Down