Skip to content

Conversation

@zhangp365
Copy link

Link to Issue or Description of Change

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

Problem:
There is no title field in the sessions table, so when the frontend tries to display the chat history to users, there are no readable titles in the history list. In contrast, when users interact with other agents, the history list always contains readable titles.

Solution:
This update introduces the ability to set, update, and clear titles for user sessions across various session services. The following changes were made:

  • Added title attribute to the Session model.
  • Implemented update_session_title method in BaseSessionService and its concrete implementations (e.g., DatabaseSessionService, InMemorySessionService, SqliteSessionService, VertexAiSessionService).
  • Updated the adk_web_server.py to include a new endpoint for updating session titles.
  • Enhanced migration scripts to accommodate the new title field in session records.
  • Added unit tests to verify the functionality of session title management.

Unit Tests

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

Manual End-to-End (E2E) Tests

I have installed the updated code on both my local machine and my server, started adk web, and run the agent. Everything works as expected with no issues.


Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my code.
  • I have added comments where the code may be difficult to understand.
  • I have added tests that prove my fix is effective or that my feature works.
  • All 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.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @zhangp365, 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 introduces a crucial feature for user experience by enabling the management of titles for user sessions. Previously, chat histories lacked readable titles, making it difficult for users to distinguish between different sessions. This change addresses that by integrating a title field into the session model and providing the necessary API and service layer functionality to set, update, and clear these titles, ensuring a consistent and user-friendly experience across all session types.

Highlights

  • Session Model Enhancement: The Session model now includes an optional title attribute, allowing for human-readable names for user sessions.
  • API Endpoint for Title Management: A new PATCH endpoint /apps/{app_name}/users/{user_id}/sessions/{session_id}/title has been added to adk_web_server.py to enable updating session titles.
  • Service Layer Integration: The update_session_title method has been introduced in BaseSessionService and implemented across all concrete session service types (Database, In-Memory, SQLite, and Vertex AI) to support title creation, retrieval, and modification.
  • Database Schema Updates: Database-backed session services (Database and SQLite) have been updated to include a title column in their respective session storage schemas, with migration scripts adjusted to handle this new field.
  • Comprehensive Unit Testing: Extensive unit tests have been added and updated to cover the new session title management functionality across all supported session service implementations, including edge cases like clearing titles and handling non-existent sessions.
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 Nov 25, 2025
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 a valuable feature for managing session titles, which will improve the user experience by providing readable titles in the chat history. The changes are well-implemented across different session services, including in-memory, database, SQLite, and Vertex AI. The implementation is solid and includes corresponding unit tests to ensure correctness. I've provided a few suggestions to improve API consistency, code clarity, and efficiency.

Comment on lines 304 to 313
if (
app_name not in self.sessions
or user_id not in self.sessions[app_name]
or session_id not in self.sessions[app_name][user_id]
):
raise ValueError(
f'Session not found: app_name={app_name}, user_id={user_id},'
f' session_id={session_id}'
)
self.sessions[app_name][user_id][session_id].title = title
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The check for session existence is a bit verbose. It can be written more concisely and safely using .get() with default values. This makes the code more readable and less prone to errors.

    session = self.sessions.get(app_name, {}).get(user_id, {}).get(session_id)
    if session is None:
      raise ValueError(
          f'Session not found: app_name={app_name}, user_id={user_id},'
          f' session_id={session_id}'
      )
    session.title = title

Comment on lines 317 to 339
async def update_session_title(
self,
*,
app_name: str,
user_id: str,
session_id: str,
title: Optional[str],
) -> None:
async with self._get_db_connection() as db:
async with db.execute(
"SELECT 1 FROM sessions WHERE app_name=? AND user_id=? AND id=?",
(app_name, user_id, session_id),
) as cursor:
if not await cursor.fetchone():
raise ValueError(
f"Session not found: app_name={app_name}, user_id={user_id},"
f" session_id={session_id}"
)
await db.execute(
"UPDATE sessions SET title=? WHERE app_name=? AND user_id=? AND id=?",
(title, app_name, user_id, session_id),
)
await db.commit()
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 implementation uses two separate database queries (SELECT then UPDATE) to update the session title. This can be optimized into a single, more efficient, and atomic UPDATE operation. You can check the cursor.rowcount after the UPDATE to see if any rows were affected. If rowcount is 0, it means the session was not found, and you can raise the ValueError.

  async def update_session_title(
      self,
      *,
      app_name: str,
      user_id: str,
      session_id: str,
      title: Optional[str],
  ) -> None:
    async with self._get_db_connection() as db:
      cursor = await db.execute(
          "UPDATE sessions SET title=? WHERE app_name=? AND user_id=? AND id=?",
          (title, app_name, user_id, session_id),
      )
      if cursor.rowcount == 0:
        raise ValueError(
            f"Session not found: app_name={app_name}, user_id={user_id},"
            f" session_id={session_id}"
        )
      await db.commit()

Comment on lines +251 to +253
except Exception as e:
logger.error('Error updating session title %s: %s', session_id, e)
raise
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Catching a broad Exception can hide other unexpected errors. It's better to catch a more specific exception, such as api_core_exceptions.GoogleAPICallError, which is the base class for errors from the Google API client. This makes the error handling more robust.

You'll need to add from google.api_core import exceptions as api_core_exceptions at the top of the file.

Suggested change
except Exception as e:
logger.error('Error updating session title %s: %s', session_id, e)
raise
except api_core_exceptions.GoogleAPICallError as e:
logger.error('Error updating session title %s: %s', session_id, e)
raise

Copy link
Author

Choose a reason for hiding this comment

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

No, this exception should be kept as other methods.

@ryanaiagent ryanaiagent self-assigned this Nov 25, 2025
@ryanaiagent
Copy link
Collaborator

Hi @zhangp365 , Thank you for your work on this pull request. We appreciate the effort you've invested.
Can you please fix the failing unit tests before we proceed with the review.

@ryanaiagent ryanaiagent added the request clarification [Status] The maintainer need clarification or more information from the author label Nov 30, 2025
@zhangp365
Copy link
Author

Hi @zhangp365 , Thank you for your work on this pull request. We appreciate the effort you've invested. Can you please fix the failing unit tests before we proceed with the review.

have fixed it.

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.

3 participants