8000 fix: add ordering to recent events in database session service to preserve the chronological sequence of messages: 400 INVALID_ARGUMENT by JoaoCampista · Pull Request #454 · google/adk-python · GitHub
[go: up one dir, main page]

Skip to content

fix: add ordering to recent events in database session service to preserve the chronological sequence of messages: 400 INVALID_ARGUMENT #454

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

JoaoCampista
Copy link
Contributor
@JoaoCampista JoaoCampista commented Apr 29, 2025

Fixes: #453

Describe the bug
The DatabaseSessionService class (in adk/sessions/database_session_service.py) fetches StorageEvent records without any ORDER BY clause. As a result, events are returned in a non-deterministic order determined by the database’s query planner. When building the context for inference via the Gemini API, messages end up shuffled, leading to hallucinations because the model receives them out of their original sequence.

@JoaoCampista
Copy link
Contributor Author

#453

@JoaoCampista JoaoCampista marked this pull request as draft April 29, 2025 16:29
@JoaoCampista JoaoCampista marked this pull request as ready for review April 29, 2025 16:32
@JoaoCampista JoaoCampista changed the title fix: add ordering to recent events in database session service to preserve the chronological sequence of messages fix: add ordering to recent events in database session service to preserve the chronological sequence of messages: 400 INVALID_ARGUMENT Apr 29, 2025
@JoaoCampista
Copy link
Contributor Author

This resolves the google.genai.errors.ClientError: 400 INVALID_ARGUMENT. {'error': {'code': 400, 'message': 'Please ensure that function call turn comes immediately after a user turn or after a function response turn.', 'status': 'INVALID_ARGUMENT'}}

When retrieve data from db, this get its non cronological, causing inconsistency on order of functions callings e responses.
And reults on 400 Error.

;)

Copy link
Contributor Author
@JoaoCampista JoaoCampista left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add Order By

@hangfei hangfei added the ready to pull for importing back to Google label Apr 30, 2025
copybara-service bot pushed a commit that referenced this pull request Apr 30, 2025
--
709e1dd by joao.campista <joaocampista@proton.me>:

feat: add ordering to recent events in database session service
COPYBARA_INTEGRATE_REVIEW=#454 from lugui-co:main 912503f
PiperOrigin-RevId: 753013663
@JoaoCampista
Copy link
Contributor Author

hello guys
@hangfei @DeanChensj

do I need to do anything here now? I saw the merge has already been done on the main branch—do I need to update anything here? It’s my first PR on the project.

@hangfei
Copy link
Collaborator
hangfei commented May 3, 2025

This is already in acbbdb7.

We have code sync that fetches this. Since we didn't close this promptly, so it's merged from Google by our system again.

But the commit is still associated with your name. Thanks for your contribution!

@hangfei hangfei closed this May 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready to pull for importing back to Google
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DatabaseSessionService returns storage_events without ordering, causing out-of-sequence messages : 400 INVALID_ARGUMENT
3 participants
0