Skip to content

feat(sessions): add get_events() and filter_events() methods to Session#4960

Open
ecanlar wants to merge 3 commits intogoogle:mainfrom
ecanlar:feature/session-filter-clean
Open

feat(sessions): add get_events() and filter_events() methods to Session#4960
ecanlar wants to merge 3 commits intogoogle:mainfrom
ecanlar:feature/session-filter-clean

Conversation

@ecanlar
Copy link

@ecanlar ecanlar commented Mar 23, 2026

Summary

This PR implements event filtering capabilities for the Session class to support rewind operations.

Changes

  • Added get_events() method: Provides a consistent API for accessing all session events
  • Added filter_events() method: Allows filtering events with options to exclude rewound events
  • Implemented rewind filtering logic: When a session is rewound, events from the rewound invocation onwards are automatically filtered out
  • Comprehensive test coverage: Added extensive unit tests covering all scenarios including edge cases

Key Features

  1. get_events(): Returns all events in the session
  2. filter_events(exclude_rewound=True): Returns filtered events, excluding those invalidated by rewind operations
  3. Backward iteration algorithm: Efficiently filters rewound events by iterating backward through the event list

Testing

The implementation includes comprehensive unit tests in test_session_filter_events.py covering:

  • Normal event retrieval
  • Single and multiple rewind scenarios
  • Edge cases (rewind target not found, chronological order preservation)
  • Multiple events in the same invocation

Files Changed

  • src/google/adk/sessions/session.py - Added get_events() and filter_events() methods with rewind filtering logic
  • tests/unittests/sessions/test_session_filter_events.py - Comprehensive unit tests

Related Issue

Fixes #4959

@google-cla
Copy link

google-cla bot commented Mar 23, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@adk-bot adk-bot added the services [Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc label Mar 23, 2026
@adk-bot
Copy link
Collaborator

adk-bot commented Mar 23, 2026

Response from ADK Triaging Agent

Hello @ecanlar, thank you for your contribution!

Before we can merge this PR, we need you to sign our Contributor License Agreement (CLA). It seems the cla/google check has failed. Please check the details of the failed check and sign the CLA.

Thanks!

@ecanlar ecanlar force-pushed the feature/session-filter-clean branch from 6648a5b to f024441 Compare March 23, 2026 11:44
@rohityan rohityan self-assigned this Mar 23, 2026
@rohityan
Copy link
Collaborator

Hi @ecanlar , Thank you for your contribution! We appreciate you taking the time to submit this pull request. Can you please fix the formatting errrors. You can use autoformat.sh

@rohityan rohityan added the request clarification [Status] The maintainer need clarification or more information from the author label Mar 23, 2026
@ecanlar
Copy link
Author

ecanlar commented Mar 24, 2026

Hi @rohityan, formatting errors are fixed by running autoformat.sh. The code now follows the Google Python Style Guide with proper indentation (2 spaces) and import ordering.

@ecanlar
Copy link
Author

ecanlar commented Mar 24, 2026

I've just pushed a commit that adds full support for nested Pydantic models!
The implementation is based on ADK's existing _resolve_references() function in openapi_spec_parser.py, which already handles similar reference resolution for OpenAPI tools. I adapted it for Pydantic's specific schema structure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

request clarification [Status] The maintainer need clarification or more information from the author services [Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add get_events() and filter_events() methods to Session

3 participants