-
Notifications
You must be signed in to change notification settings - Fork 358
Description
What happened?
**Environment**
ADK Version: 1.13.0 (via google-adk)
Python Version: 3.13.5
OS: macOS (darwin 24.5.0, arm64)
Installation: pip/uv
Description
When storing a Pydantic BaseModel subclass in the ADK session state, sqlite_session_service.py raises a TypeError because json.dumps() is called directly on the Pydantic model object instead of its serialized representation.
Steps to Reproduce
- Create a Pydantic model and store it in the session state:
class IntentMandate(BaseModel):
natural_language_description: str i
ntent_expiry: str # ... other fields
# In an agent tool or executor:
ctx.state["mandate"] = IntentMandate( natural_language_description="Buy red shoes",
intent_expiry="2025-12-30T00:00:00Z"
)
- The ADK attempts to persist the session state to SQLite
- Error is raised
Expected Behavior
The session service should handle Pydantic models gracefully, either by:
Calling .model_dump() on Pydantic BaseModel instances before JSON serialization
Using a custom JSON encoder that handles Pydantic models
Documenting that session state values must be JSON-serializable primitives
Actual Behavior
TypeError: Object of type IntentMandate is not JSON serializable (ref screenshot)
Relevant log output
2025-12-29 20:31:45,807 - ERROR - adk_web_server.py:1509 - Error in event_generator: Object of type IntentMandate is not JSON serializable
Traceback (most recent call last):
File ".venv/lib/python3.13/site-packages/google/adk/cli/adk_web_server.py", line 1499, in event_generator
async for event in agen:
...
yield f"data: {sse_event}\n\n"
File ".venv/lib/python3.13/site-packages/google/adk/runners.py", line 505, in run_async
async for event in agen:
yield event
File ".venv/lib/python3.13/site-packages/google/adk/runners.py", line 493, in _run_with_trace
async for event in agen:
yield event
File ".venv/lib/python3.13/site-packages/google/adk/runners.py", line 769, in _exec_with_plugin
await self.session_service.append_event(
session=session, event=event
)
File ".venv/lib/python3.13/site-packages/google/adk/cli/utils/local_storage.py", line 200, in append_event
return await service.append_event(session, event)
File ".venv/lib/python3.13/site-packages/google/adk/sessions/sqlite_session_service.py", line 369, in append_event
await self._update_session_state_in_db(...)
File ".venv/lib/python3.13/site-packages/google/adk/sessions/sqlite_session_service.py", line 504, in _update_session_state_in_db
json.dumps(delta),
File "/opt/homebrew/Cellar/[email protected]/3.13.5/.../json/__init__.py", line 231, in dumps
return _default_encoder.encode(obj)
...
TypeError: Object of type IntentMandate is not JSON serializableCode of Conduct
- I agree to follow this project's Code of Conduct
Metadata
Metadata
Assignees
Labels
No labels