Skip to content
Open
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
18 changes: 18 additions & 0 deletions python/packages/kagent-adk/src/kagent/adk/_session_service.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import functools
import logging
from typing import Any, Optional

Expand All @@ -14,6 +15,18 @@
logger = logging.getLogger("kagent." + __name__)


def logging_http_exception(func):
@functools.wraps(func)
async def wrapper(*args, **kwargs):
try:
return await func(*args, **kwargs)
except httpx.HTTPError as exc:
logger.error(f"Got HTTP exception when {exc.request.method} {exc.request.url}: {exc}")
raise

return wrapper


class KAgentSessionService(BaseSessionService):
"""A session service implementation that uses the Kagent API.
This service integrates with the Kagent server to manage session state
Expand All @@ -25,6 +38,7 @@ def __init__(self, client: httpx.AsyncClient):
self.client = client

@override
@logging_http_exception
async def create_session(
self,
*,
Expand Down Expand Up @@ -61,6 +75,7 @@ async def create_session(
return Session(id=session_data["id"], user_id=session_data["user_id"], state=state or {}, app_name=app_name)

@override
@logging_http_exception
async def get_session(
self,
*,
Expand Down Expand Up @@ -126,6 +141,7 @@ async def get_session(
raise

@override
@logging_http_exception
async def list_sessions(self, *, app_name: str, user_id: str) -> ListSessionsResponse:
# Make API call to list sessions
response = await self.client.get(f"/api/sessions?user_id={user_id}", headers={"X-User-ID": user_id})
Expand All @@ -146,6 +162,7 @@ def list_sessions_sync(self, *, app_name: str, user_id: str) -> ListSessionsResp
raise NotImplementedError("not supported. use async")

@override
@logging_http_exception
async def delete_session(self, *, app_name: str, user_id: str, session_id: str) -> None:
# Make API call to delete session
response = await self.client.delete(
Expand All @@ -155,6 +172,7 @@ async def delete_session(self, *, app_name: str, user_id: str, session_id: str)
response.raise_for_status()

@override
@logging_http_exception
async def append_event(self, session: Session, event: Event) -> Event:
# Convert ADK Event to JSON format
event_data = {
Expand Down
Loading