fix: Add endpoints to get/list artifact version metadata

This change introduces new FastAPI endpoints in adk_web_server.py and corresponding client methods in adk_web_server_client.py to allow fetching metadata for artifact versions without downloading the artifact content

Close #3710

Co-authored-by: George Weale <gweale@google.com>
PiperOrigin-RevId: 868217569
This commit is contained in:
sarojrout
2026-02-10 10:40:54 -08:00
committed by Copybara-Service
co-authored by George Weale
parent 7c7d25a4a6
commit e0b9712a49
4 changed files with 272 additions and 0 deletions
+43
View File
@@ -1347,6 +1347,24 @@ class AdkWebServer:
raise HTTPException(status_code=404, detail="Artifact not found")
return artifact
@app.get(
"/apps/{app_name}/users/{user_id}/sessions/{session_id}/artifacts/{artifact_name}/versions/metadata",
response_model=list[ArtifactVersion],
response_model_exclude_none=True,
)
async def list_artifact_versions_metadata(
app_name: str,
user_id: str,
session_id: str,
artifact_name: str,
) -> list[ArtifactVersion]:
return await self.artifact_service.list_artifact_versions(
app_name=app_name,
user_id=user_id,
session_id=session_id,
filename=artifact_name,
)
@app.get(
"/apps/{app_name}/users/{user_id}/sessions/{session_id}/artifacts/{artifact_name}/versions/{version_id}",
response_model_exclude_none=True,
@@ -1416,6 +1434,31 @@ class AdkWebServer:
)
return artifact_version
@app.get(
"/apps/{app_name}/users/{user_id}/sessions/{session_id}/artifacts/{artifact_name}/versions/{version_id}/metadata",
response_model=ArtifactVersion,
response_model_exclude_none=True,
)
async def get_artifact_version_metadata(
app_name: str,
user_id: str,
session_id: str,
artifact_name: str,
version_id: int,
) -> ArtifactVersion:
artifact_version = await self.artifact_service.get_artifact_version(
app_name=app_name,
user_id=user_id,
session_id=session_id,
filename=artifact_name,
version=version_id,
)
if not artifact_version:
raise HTTPException(
status_code=404, detail="Artifact version not found"
)
return artifact_version
@app.get(
"/apps/{app_name}/users/{user_id}/sessions/{session_id}/artifacts",
response_model_exclude_none=True,
@@ -27,6 +27,7 @@ from typing import Optional
import httpx
from ...artifacts.base_artifact_service import ArtifactVersion
from ...events.event import Event
from ...sessions.session import Session
from ..adk_web_server import RunAgentRequest
@@ -268,3 +269,38 @@ class AdkWebServerClient:
yield Event.model_validate(event_data)
else:
logger.debug("Non data line received: %s", line)
async def get_artifact_version_metadata(
self,
*,
app_name: str,
user_id: str,
session_id: str,
artifact_name: str,
version: int,
) -> ArtifactVersion:
"""Retrieve metadata for a specific artifact version."""
async with self._get_client() as client:
response = await client.get((
f"/apps/{app_name}/users/{user_id}/sessions/{session_id}"
f"/artifacts/{artifact_name}/versions/{version}/metadata"
))
response.raise_for_status()
return ArtifactVersion.model_validate(response.json())
async def list_artifact_versions_metadata(
self,
*,
app_name: str,
user_id: str,
session_id: str,
artifact_name: str,
) -> list[ArtifactVersion]:
"""List metadata for all versions of an artifact."""
async with self._get_client() as client:
response = await client.get((
f"/apps/{app_name}/users/{user_id}/sessions/{session_id}"
f"/artifacts/{artifact_name}/versions/metadata"
))
response.raise_for_status()
return [ArtifactVersion.model_validate(item) for item in response.json()]