Skip to content

Conversation

@ashubham
Copy link

@ashubham ashubham commented Jan 15, 2026

Please ensure you have read the contribution guide before creating a pull request.

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

Problem:
ADK does not support display_name and labels in the Session class. Both of these are required for a title for a session and labeling the sessions for filtering when listed.

Solution:
Support display_name and labels natively. A further improvement could be to autogenerate titles based on model when using LLMAgent.

Testing Plan

Ran all the Unit/Integration Tests. Also added basic tests. The changes are done in a backward compatible way by making the the two fields optional. This ensures none of the existing tests needed updating.

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Please include a summary of passed pytest results.

$ pytest tests/unittests/sessions/ --tb=no -q

94 passed, 17 warnings in 3.59s

Manual End-to-End (E2E) Tests:

  • Create a session with a display_name and/or labels using the API.
  • See that the values are available in the session object available in the Context.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

Additional context

The new fields align with what is present in the Session resource on the VertexAI Sessions service defined here

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @ashubham, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves session management by introducing display_name and labels to the Session object. These additions provide a more robust way to identify and organize sessions, enabling users to assign meaningful names and categorize sessions using key-value pairs. Furthermore, the list_sessions functionality has been enhanced to leverage these new labels for efficient filtering, making it easier to retrieve specific sets of sessions based on custom criteria.

Highlights

  • Enhanced Session Model: The Session class now includes optional display_name and labels fields, allowing for more descriptive and categorizable sessions.
  • Label-based Session Filtering: The list_sessions method across all session services (in-memory, database, SQLite, and Vertex AI) has been extended to support filtering sessions by user-defined labels.
  • Persistence and API Integration: The new display_name and labels fields are fully integrated into the persistence layers (SQLAlchemy schemas for database services, SQLite schema) and the Vertex AI Sessions API, ensuring data integrity and consistency.
  • Backward Compatibility and Migration: The changes are implemented in a backward-compatible manner, with new fields being optional. SQLite service includes a mechanism to add new columns to existing databases without requiring a full schema migration.
  • Comprehensive Testing: New unit tests have been added to cover the creation, persistence, and filtering functionality of display_name and labels.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

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

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for display_name and labels to sessions, which is a valuable feature for identifying and filtering them. The changes are consistently applied across all session service implementations (in-memory, database, sqlite, and vertex_ai). The new fields are also added to the data models and database schemas, with backward compatibility in mind for sqlite_session_service through schema alteration. The addition of unit tests is also great.

My main feedback is regarding performance in the database-backed session services. Both DatabaseSessionService and SqliteSessionService perform label-based filtering in Python after fetching all data from the database. This can be inefficient. I've left comments with suggestions to move this filtering logic to the database query itself.

I've also included a couple of suggestions for the in_memory_session_service to improve code conciseness and reduce duplication.

Overall, this is a solid contribution. Addressing the performance concerns in the database services would make it even better.

@ashubham
Copy link
Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for display_name and labels in sessions, which is a valuable feature for organizing and filtering. The changes are comprehensive, consistently applied across all session service implementations (in-memory, database, sqlite, and vertex_ai). The data models, database schemas, and service methods have been updated correctly. Label-based filtering is implemented with backend-specific optimizations, and a non-disruptive schema migration for SQLite is included to maintain backward compatibility. The addition of unit tests for the new functionality is also great. Overall, this is a well-executed feature addition. I have one suggestion to improve the efficiency of the schema check in the SqliteSessionService.

Comment on lines +501 to +511
async def _ensure_new_columns(self, db: aiosqlite.Connection) -> None:
"""Ensures display_name and labels columns exist in the sessions table."""
async with db.execute("PRAGMA table_info(sessions)") as cursor:
columns = [row[1] async for row in cursor]

if "display_name" not in columns:
await db.execute("ALTER TABLE sessions ADD COLUMN display_name TEXT")
if "labels" not in columns:
await db.execute(
"ALTER TABLE sessions ADD COLUMN labels TEXT NOT NULL DEFAULT '{}'"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This method is called on every database connection, which is inefficient as it runs a PRAGMA query each time. To optimize this, the check should run only once per service instance.

You can achieve this with an instance flag and a lock for thread safety. First, add self._columns_ensured = False and self._columns_ensured_lock = asyncio.Lock() to the __init__ method. Then, modify this method to use them as shown in the suggestion.

At the call site in _get_db_connection, you would then wrap the call:

      # Ensure new columns exist for existing databases
      if not self._columns_ensured:
        await self._ensure_new_columns(db)
Suggested change
async def _ensure_new_columns(self, db: aiosqlite.Connection) -> None:
"""Ensures display_name and labels columns exist in the sessions table."""
async with db.execute("PRAGMA table_info(sessions)") as cursor:
columns = [row[1] async for row in cursor]
if "display_name" not in columns:
await db.execute("ALTER TABLE sessions ADD COLUMN display_name TEXT")
if "labels" not in columns:
await db.execute(
"ALTER TABLE sessions ADD COLUMN labels TEXT NOT NULL DEFAULT '{}'"
)
async def _ensure_new_columns(self, db: aiosqlite.Connection) -> None:
"""Ensures display_name and labels columns exist in the sessions table."""
async with self._columns_ensured_lock:
if self._columns_ensured:
return
async with db.execute("PRAGMA table_info(sessions)") as cursor:
columns = [row[1] async for row in cursor]
if "display_name" not in columns:
await db.execute("ALTER TABLE sessions ADD COLUMN display_name TEXT")
if "labels" not in columns:
await db.execute(
"ALTER TABLE sessions ADD COLUMN labels TEXT NOT NULL DEFAULT '{}'"
)
self._columns_ensured = True

@ryanaiagent
Copy link
Collaborator

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for display_name and labels to sessions, which is a great feature for organizing and filtering. The changes are implemented consistently across different session service backends (InMemory, Database, Sqlite, VertexAi). The addition of tests for the new functionality is also good. I have one main suggestion regarding the SqliteSessionService implementation to improve its robustness.

if labels_filter:
for key, value in labels_filter.items():
query_parts.append("AND json_extract(labels, ?)=?")
params.extend([f"$.{key}", value])
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The current construction of the JSONPath f"$.{key}" is not safe if the label key contains special characters like . which are interpreted by json_extract. To handle all valid string keys correctly, the key should be properly quoted within the JSONPath expression. For example, a key "a.b" would be interpreted as nested access, not as a literal key. Using json.dumps(key) will correctly quote and escape the key, ensuring it's treated as a single literal key in the JSONPath.

Suggested change
params.extend([f"$.{key}", value])
params.extend([f"$.{json.dumps(key)}", value])

@ryanaiagent ryanaiagent added the request clarification [Status] The maintainer need clarification or more information from the author label Jan 15, 2026
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.

ADK Session should have display_name and align with AgentEngine Sessions interface

3 participants