fix: await get_session and create_session (async ADK 1.x API)
This commit is contained in:
parent
4ef0683c7c
commit
ffe4ec1c63
|
|
@ -52,10 +52,10 @@ class RunResponse(BaseModel):
|
||||||
response: str
|
response: str
|
||||||
|
|
||||||
|
|
||||||
def _ensure_session(user_id: str, session_id: str):
|
async def _ensure_session(user_id: str, session_id: str):
|
||||||
"""Get existing session or create a new one. Handles both ADK 1.x and 2.x."""
|
"""Await get_session; create if missing or raises."""
|
||||||
try:
|
try:
|
||||||
session = session_service.get_session(
|
session = await session_service.get_session(
|
||||||
app_name=APP_NAME,
|
app_name=APP_NAME,
|
||||||
user_id=user_id,
|
user_id=user_id,
|
||||||
session_id=session_id,
|
session_id=session_id,
|
||||||
|
|
@ -63,9 +63,9 @@ def _ensure_session(user_id: str, session_id: str):
|
||||||
if session is not None:
|
if session is not None:
|
||||||
return session
|
return session
|
||||||
except Exception:
|
except Exception:
|
||||||
pass # session doesn't exist — fall through to create
|
pass
|
||||||
|
|
||||||
session = session_service.create_session(
|
session = await session_service.create_session(
|
||||||
app_name=APP_NAME,
|
app_name=APP_NAME,
|
||||||
user_id=user_id,
|
user_id=user_id,
|
||||||
session_id=session_id,
|
session_id=session_id,
|
||||||
|
|
@ -82,7 +82,7 @@ async def health():
|
||||||
@app.post("/run", response_model=RunResponse)
|
@app.post("/run", response_model=RunResponse)
|
||||||
async def run(req: RunRequest):
|
async def run(req: RunRequest):
|
||||||
try:
|
try:
|
||||||
_ensure_session(req.user_id, req.session_id)
|
await _ensure_session(req.user_id, req.session_id)
|
||||||
|
|
||||||
runner = Runner(
|
runner = Runner(
|
||||||
agent=root_agent,
|
agent=root_agent,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user