Skip to content

Commit b06f1f2

Browse files
fix: enhance API documentation for session management endpoints
1 parent 5d17ae4 commit b06f1f2

1 file changed

Lines changed: 93 additions & 42 deletions

File tree

src/google/adk/cli/adk_web_server.py

Lines changed: 93 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
from fastapi import FastAPI
3535
from fastapi import HTTPException
36+
from fastapi import Path
3637
from fastapi import Query
3738
from fastapi import Response
3839
from fastapi.middleware.cors import CORSMiddleware
@@ -392,7 +393,11 @@ class CreateSessionRequest(common.BaseModel):
392393
)
393394
events: Optional[list[Event]] = Field(
394395
default=None,
395-
description="A list of events to initialize the session with.",
396+
description=(
397+
"Optional list of events to seed the session history. Events are"
398+
" appended in order after session creation."
399+
),
400+
examples=[[]],
396401
)
397402

398403

@@ -1089,25 +1094,41 @@ async def get_session_trace(session_id: str) -> Any:
10891094
"/apps/{app_name}/users/{user_id}/sessions/{session_id}",
10901095
response_model_exclude_none=True,
10911096
summary="Get a session",
1097+
responses={
1098+
404: {"description": "Session not found."},
1099+
500: {"description": "Internal server error."},
1100+
},
10921101
)
10931102
async def get_session(
1094-
app_name: str, user_id: str, session_id: str
1103+
app_name: str = Path(
1104+
description="Application name that owns the session.",
1105+
examples=["hello_world"],
1106+
),
1107+
user_id: str = Path(
1108+
description="User ID that owns the session.",
1109+
examples=["user-123"],
1110+
),
1111+
session_id: str = Path(
1112+
description="Session ID to retrieve.",
1113+
examples=["session-abc123"],
1114+
),
10951115
) -> Session:
1096-
"""Retrieves a specific session by its ID.
1116+
"""Retrieve a specific session by ID.
10971117
1098-
Returns the full session object including conversation history and state
1099-
for the given application, user, and session ID combination.
1118+
Returns the full session object, including conversation history and
1119+
state, for the given application, user, and session ID.
11001120
1101-
Args:
1102-
app_name: The name of the application that owns the session.
1103-
user_id: The ID of the user who owns the session.
1104-
session_id: The unique identifier of the session to retrieve.
1121+
**Path parameters**
1122+
- `app_name`: Name of the application that owns the session.
1123+
- `user_id`: ID of the user who owns the session.
1124+
- `session_id`: Unique identifier of the session to retrieve.
11051125
1106-
Returns:
1107-
The session object containing conversation events and state.
1126+
**Returns**
1127+
- `Session`: Session object containing conversation events and state.
11081128
1109-
Raises:
1110-
HTTPException: 404 if no session with the given ID exists.
1129+
**Errors**
1130+
- `404 Not Found`: No session exists with the given ID.
1131+
- `500 Internal Server Error`: Unexpected internal error.
11111132
"""
11121133
session = await self.session_service.get_session(
11131134
app_name=app_name, user_id=user_id, session_id=session_id
@@ -1121,20 +1142,35 @@ async def get_session(
11211142
"/apps/{app_name}/users/{user_id}/sessions",
11221143
response_model_exclude_none=True,
11231144
summary="List sessions",
1145+
responses={
1146+
500: {"description": "Internal server error."},
1147+
},
11241148
)
1125-
async def list_sessions(app_name: str, user_id: str) -> list[Session]:
1126-
"""Lists all active sessions for the specified user and application.
1127-
1128-
Returns all sessions belonging to the user within the given application,
1129-
excluding internal sessions generated during evaluation runs.
1130-
1131-
Args:
1132-
app_name: The name of the application.
1133-
user_id: The ID of the user whose sessions to list.
1134-
1135-
Returns:
1136-
A list of session objects. Returns an empty list if the user has no
1137-
sessions.
1149+
async def list_sessions(
1150+
app_name: str = Path(
1151+
description="Application name to list sessions from.",
1152+
examples=["hello_world"],
1153+
),
1154+
user_id: str = Path(
1155+
description="User ID whose sessions are listed.",
1156+
examples=["user-123"],
1157+
),
1158+
) -> list[Session]:
1159+
"""List sessions for a user in an application.
1160+
1161+
Returns all sessions for the given application and user, excluding
1162+
internal sessions generated during evaluation runs.
1163+
1164+
**Path parameters**
1165+
- `app_name`: Name of the application.
1166+
- `user_id`: ID of the user whose sessions are listed.
1167+
1168+
**Returns**
1169+
- `list[Session]`: List of sessions. Returns an empty list when none
1170+
exist.
1171+
1172+
**Errors**
1173+
- `500 Internal Server Error`: Unexpected internal error.
11381174
"""
11391175
list_sessions_response = await self.session_service.list_sessions(
11401176
app_name=app_name, user_id=user_id
@@ -1171,30 +1207,45 @@ async def create_session_with_id(
11711207
"/apps/{app_name}/users/{user_id}/sessions",
11721208
response_model_exclude_none=True,
11731209
summary="Create a session",
1210+
responses={
1211+
409: {"description": "Session already exists."},
1212+
500: {"description": "Internal server error."},
1213+
},
11741214
)
11751215
async def create_session(
1176-
app_name: str,
1177-
user_id: str,
1216+
app_name: str = Path(
1217+
description=(
1218+
"Application name under which the session is created."
1219+
),
1220+
examples=["hello_world"],
1221+
),
1222+
user_id: str = Path(
1223+
description="User ID for whom the session is created.",
1224+
examples=["user-123"],
1225+
),
11781226
req: Optional[CreateSessionRequest] = None,
11791227
) -> Session:
1180-
"""Creates a new session for the specified user and application.
1228+
"""Create a new session for a user in an application.
11811229
1182-
A session stores conversation history and state across multiple agent
1183-
interactions. If no session ID is provided, a random unique ID is
1184-
generated automatically. An optional initial state and seed events can
1185-
be supplied to pre-populate the session.
1230+
A session stores conversation history and state across agent
1231+
interactions. If `req.session_id` is omitted, a random session ID is
1232+
generated automatically.
11861233
1187-
Args:
1188-
app_name: The name of the application to create the session under.
1189-
user_id: The ID of the user for whom the session is created.
1190-
req: Optional request body with session configuration, including an
1191-
optional session ID, initial state dictionary, and seed events.
1234+
**Path parameters**
1235+
- `app_name`: Name of the application where the session is created.
1236+
- `user_id`: ID of the user for whom the session is created.
11921237
1193-
Returns:
1194-
The newly created session object.
1238+
**Request body**
1239+
- `req.session_id` (optional): Explicit session ID.
1240+
- `req.state` (optional): Initial session state.
1241+
- `req.events` (optional): Seed events appended after creation.
11951242
1196-
Raises:
1197-
HTTPException: 409 if a session with the given ID already exists.
1243+
**Returns**
1244+
- `Session`: Newly created session object.
1245+
1246+
**Errors**
1247+
- `409 Conflict`: Session with the same ID already exists.
1248+
- `500 Internal Server Error`: Unexpected internal error.
11981249
"""
11991250
if not req:
12001251
return await self._create_session(app_name=app_name, user_id=user_id)

0 commit comments

Comments
 (0)