3131from typing import Literal
3232from typing import Optional
3333
34- from fastapi import FastAPI
3534from fastapi import Body
35+ from fastapi import FastAPI
3636from fastapi import HTTPException
3737from fastapi import Path
3838from fastapi import Query
109109
110110TAG_DEBUG = "Debug"
111111TAG_EVALUATION = "Evaluation"
112+ TAG_SESSIONS = "Sessions"
113+ TAG_RUNS = "Agent Runs"
114+ TAG_ARTIFACTS = "Artifacts"
115+ TAG_MEMORY = "Memory"
112116
113117_REGEX_PREFIX = "regex:"
114118
@@ -380,12 +384,10 @@ class RunAgentRequest(common.BaseModel):
380384 "Optional user message to append before the run starts. Either"
381385 " new_message or invocation_id is required for a run."
382386 ),
383- examples = [
384- {
385- "role" : "user" ,
386- "parts" : [{"text" : "Summarize the last response." }],
387- }
388- ],
387+ examples = [{
388+ "role" : "user" ,
389+ "parts" : [{"text" : "Summarize the last response." }],
390+ }],
389391 )
390392 streaming : bool = Field (
391393 default = False ,
@@ -1216,9 +1218,9 @@ async def get_session_trace(session_id: str) -> Any:
12161218 "/apps/{app_name}/users/{user_id}/sessions/{session_id}" ,
12171219 response_model_exclude_none = True ,
12181220 summary = "Get a session" ,
1221+ tags = [TAG_SESSIONS ],
12191222 response_description = (
1220- "The stored session, including its current state and event"
1221- " history."
1223+ "The stored session, including its current state and event history."
12221224 ),
12231225 responses = {
12241226 404 : {"description" : "Session not found." },
@@ -1268,6 +1270,7 @@ async def get_session(
12681270 "/apps/{app_name}/users/{user_id}/sessions" ,
12691271 response_model_exclude_none = True ,
12701272 summary = "List sessions" ,
1273+ tags = [TAG_SESSIONS ],
12711274 response_description = (
12721275 "All non-evaluation sessions for the specified application and"
12731276 " user."
@@ -1320,6 +1323,7 @@ async def list_sessions(
13201323 "/apps/{app_name}/users/{user_id}/sessions/{session_id}" ,
13211324 response_model_exclude_none = True ,
13221325 summary = "Create a session (deprecated)" ,
1326+ tags = [TAG_SESSIONS ],
13231327 response_description = "The newly created session." ,
13241328 responses = {
13251329 409 : {"description" : "Session already exists." },
@@ -1328,9 +1332,7 @@ async def list_sessions(
13281332 )
13291333 async def create_session_with_id (
13301334 app_name : str = Path (
1331- description = (
1332- "Application name under which the session is created."
1333- ),
1335+ description = "Application name under which the session is created." ,
13341336 examples = ["hello_world" ],
13351337 ),
13361338 user_id : str = Path (
@@ -1382,6 +1384,7 @@ async def create_session_with_id(
13821384 "/apps/{app_name}/users/{user_id}/sessions" ,
13831385 response_model_exclude_none = True ,
13841386 summary = "Create a session" ,
1387+ tags = [TAG_SESSIONS ],
13851388 response_description = (
13861389 "The newly created session with its initial state and any seeded"
13871390 " events."
@@ -1393,9 +1396,7 @@ async def create_session_with_id(
13931396 )
13941397 async def create_session (
13951398 app_name : str = Path (
1396- description = (
1397- "Application name under which the session is created."
1398- ),
1399+ description = "Application name under which the session is created." ,
13991400 examples = ["hello_world" ],
14001401 ),
14011402 user_id : str = Path (
@@ -1445,6 +1446,7 @@ async def create_session(
14451446 @app .delete (
14461447 "/apps/{app_name}/users/{user_id}/sessions/{session_id}" ,
14471448 summary = "Delete a session" ,
1449+ tags = [TAG_SESSIONS ],
14481450 response_description = "The session was deleted successfully." ,
14491451 responses = {
14501452 500 : {"description" : "Internal server error." },
@@ -1485,6 +1487,7 @@ async def delete_session(
14851487 "/apps/{app_name}/users/{user_id}/sessions/{session_id}" ,
14861488 response_model_exclude_none = True ,
14871489 summary = "Update session state" ,
1490+ tags = [TAG_SESSIONS ],
14881491 response_description = (
14891492 "The updated session after applying the provided state delta."
14901493 ),
@@ -1958,6 +1961,7 @@ async def list_metrics_info(app_name: str) -> ListMetricsInfoResponse:
19581961 "/apps/{app_name}/users/{user_id}/sessions/{session_id}/artifacts/{artifact_name}" ,
19591962 response_model_exclude_none = True ,
19601963 summary = "Load an artifact" ,
1964+ tags = [TAG_ARTIFACTS ],
19611965 response_description = (
19621966 "The requested artifact payload for the latest or specified"
19631967 " version."
@@ -2027,6 +2031,7 @@ async def load_artifact(
20272031 response_model = list [ArtifactVersion ],
20282032 response_model_exclude_none = True ,
20292033 summary = "List artifact version metadata" ,
2034+ tags = [TAG_ARTIFACTS ],
20302035 response_description = (
20312036 "Metadata for every stored version of the specified artifact."
20322037 ),
@@ -2077,9 +2082,8 @@ async def list_artifact_versions_metadata(
20772082 "/apps/{app_name}/users/{user_id}/sessions/{session_id}/artifacts/{artifact_name}/versions/{version_id}" ,
20782083 response_model_exclude_none = True ,
20792084 summary = "Load a specific artifact version" ,
2080- response_description = (
2081- "The artifact payload for the requested version."
2082- ),
2085+ tags = [TAG_ARTIFACTS ],
2086+ response_description = "The artifact payload for the requested version." ,
20832087 responses = {
20842088 404 : {"description" : "Artifact not found." },
20852089 500 : {"description" : "Internal server error." },
@@ -2139,9 +2143,8 @@ async def load_artifact_version(
21392143 response_model = ArtifactVersion ,
21402144 response_model_exclude_none = True ,
21412145 summary = "Save an artifact" ,
2142- response_description = (
2143- "Metadata for the newly created artifact version."
2144- ),
2146+ tags = [TAG_ARTIFACTS ],
2147+ response_description = "Metadata for the newly created artifact version." ,
21452148 responses = {
21462149 400 : {"description" : "Invalid artifact payload." },
21472150 500 : {"description" : "Internal server error." },
@@ -2223,9 +2226,8 @@ async def save_artifact(
22232226 response_model = ArtifactVersion ,
22242227 response_model_exclude_none = True ,
22252228 summary = "Get artifact version metadata" ,
2226- response_description = (
2227- "Metadata for the requested artifact version."
2228- ),
2229+ tags = [TAG_ARTIFACTS ],
2230+ response_description = "Metadata for the requested artifact version." ,
22292231 responses = {
22302232 404 : {"description" : "Artifact version not found." },
22312233 500 : {"description" : "Internal server error." },
@@ -2286,9 +2288,8 @@ async def get_artifact_version_metadata(
22862288 "/apps/{app_name}/users/{user_id}/sessions/{session_id}/artifacts" ,
22872289 response_model_exclude_none = True ,
22882290 summary = "List artifact names" ,
2289- response_description = (
2290- "All artifact names stored for the session."
2291- ),
2291+ tags = [TAG_ARTIFACTS ],
2292+ response_description = "All artifact names stored for the session." ,
22922293 responses = {
22932294 500 : {"description" : "Internal server error." },
22942295 },
@@ -2328,6 +2329,7 @@ async def list_artifact_names(
23282329 "/apps/{app_name}/users/{user_id}/sessions/{session_id}/artifacts/{artifact_name}/versions" ,
23292330 response_model_exclude_none = True ,
23302331 summary = "List artifact versions" ,
2332+ tags = [TAG_ARTIFACTS ],
23312333 response_description = (
23322334 "Version numbers available for the specified artifact."
23332335 ),
@@ -2377,6 +2379,7 @@ async def list_artifact_versions(
23772379 @app .delete (
23782380 "/apps/{app_name}/users/{user_id}/sessions/{session_id}/artifacts/{artifact_name}" ,
23792381 summary = "Delete an artifact" ,
2382+ tags = [TAG_ARTIFACTS ],
23802383 response_description = "The artifact was deleted successfully." ,
23812384 responses = {
23822385 500 : {"description" : "Internal server error." },
@@ -2424,11 +2427,16 @@ async def delete_artifact(
24242427 @app .patch (
24252428 "/apps/{app_name}/users/{user_id}/memory" ,
24262429 summary = "Add a session to memory" ,
2430+ tags = [TAG_MEMORY ],
24272431 response_description = (
24282432 "The session events were added to the configured memory service."
24292433 ),
24302434 responses = {
2431- 400 : {"description" : "Memory service is not configured or request is invalid." },
2435+ 400 : {
2436+ "description" : (
2437+ "Memory service is not configured or request is invalid."
2438+ )
2439+ },
24322440 404 : {"description" : "Session not found." },
24332441 500 : {"description" : "Internal server error." },
24342442 },
@@ -2488,6 +2496,7 @@ async def patch_memory(
24882496 "/run" ,
24892497 response_model_exclude_none = True ,
24902498 summary = "Run an agent" ,
2499+ tags = [TAG_RUNS ],
24912500 response_description = (
24922501 "Ordered events generated while processing the request."
24932502 ),
@@ -2545,6 +2554,7 @@ async def run_agent(req: RunAgentRequest) -> list[Event]:
25452554 @app .post (
25462555 "/run_sse" ,
25472556 summary = "Run an agent with server-sent events" ,
2557+ tags = [TAG_RUNS ],
25482558 response_description = (
25492559 "A text/event-stream response that emits events as they are"
25502560 " generated."
@@ -2560,8 +2570,8 @@ async def run_agent_sse(req: RunAgentRequest) -> StreamingResponse:
25602570
25612571 This endpoint streams events as they are generated using the
25622572 `text/event-stream` media type. Each SSE message is formatted as:
2563- `data: <json> \n \n `, where `<json>` is an `Event` serialized with camelCase
2564- field names.
2573+ `data: {"key":"value"} `, where the JSON object is an `Event`
2574+ serialized with camelCase field names.
25652575
25662576 **Request body**
25672577 - `req.app_name`: Application name to run.
0 commit comments