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
17 changes: 13 additions & 4 deletions src/google/adk/integrations/firestore/firestore_session_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from __future__ import annotations

import asyncio
import json
from contextlib import asynccontextmanager
from datetime import datetime
from datetime import timezone
Expand Down Expand Up @@ -203,7 +204,7 @@ async def create_session(
"id": session_id,
"appName": app_name,
"userId": user_id,
"state": session_state,
"state": json.dumps(session_state),
"createTime": now,
"updateTime": now,
"revision": 1,
Expand Down Expand Up @@ -314,7 +315,10 @@ async def get_session(
events.append(Event.model_validate(ed))

# Let's continue getting session.
session_state = data.get("state", {})
raw_state = data.get("state", {})
session_state = (
json.loads(raw_state) if isinstance(raw_state, str) else raw_state
)

# Fetch shared state
app_ref = self.client.collection(self.app_state_collection).document(
Expand Down Expand Up @@ -407,7 +411,12 @@ async def list_sessions(
data = doc.to_dict()
if data:
u_id = data["userId"]
s_state = data.get("state", {})
raw_s_state = data.get("state", {})
s_state = (
json.loads(raw_s_state)
if isinstance(raw_s_state, str)
else raw_s_state
)
u_state = user_states_map.get(u_id, {})
merged = self._merge_state(app_state, u_state, s_state)

Expand Down Expand Up @@ -555,7 +564,7 @@ async def _append_txn(transaction: firestore.AsyncTransaction) -> int:
transaction.update(
session_ref,
{
"state": session_only_state,
"state": json.dumps(session_only_state),
"updateTime": firestore.SERVER_TIMESTAMP,
"revision": new_revision,
},
Expand Down
Loading